How can I multiply 4D array? Optimization assignment problem

3 次查看(过去 30 天)
Hi guys, I am currently working on an optimization problem:-
I have to assign my workers (i) to perform different tasks (j) under different sections (k) of different projects(L).
So I created a simple model : Maximize P = X(ijkl)*Y(ijkl) and Y(ijkl) is binary variable
here is my code
.
l = {'P1','P2',};
k = {'S1','S2','S3','S4'};
j = {'T1','T2','T3','T4','T5','T6','T7', 'T8'};
i = {'W1','W2','W3','W4','W5','W6','W7','W8'};
Y = optimvar('Y',i,j,k,l,'LowerBound',0,'UpperBound',1,'Type','integer');
X = rand(8,8,4,2)
Optimprob = optimproblem('ObjectiveSense','maximize','Objective',sum(sum(Y.*X)));
[soln,fval,exitflag,output] = solve(Optimprob);
and turns out error is occur:-
Error using optimproblem (line 52) Objective must be a scalar OptimizationExpression or a struct containing a scalar OptimizationExpression.
The assignment method are based on the performance data X(ijlk), e.g. workers (i) have 20 marks in task (j) under section (k) in project (L).
Am I need to reshape the 4D-array to solve the problem? Can anyone give me some advise?
Thank you. Jim

采纳的回答

Torsten
Torsten 2018-8-30
Use "reshape" to turn your 4d-matrices into an 1d-vector, multiply the vectors componentenwise and sum.
  3 个评论
Torsten
Torsten 2018-8-30
Did you impose sum constraints on the Y ? Otherwise, all of them will be 1, I guess.
Ngai Nang Wong
Ngai Nang Wong 2018-8-30
I made 2 constraints but not sure if it is work since I cannot see the value of Y(ijkl).
This is my constraints
Optimprob.Constraints.constr1 = sum(Y,2) == 1;
Optimprob.Constraints.constr2 = sum(Y,1) <= 1;
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by