How can I multiply 4D array? Optimization assignment problem

2 ビュー (過去 30 日間)
Ngai Nang Wong
Ngai Nang Wong 2018 年 8 月 30 日
コメント済み: Ngai Nang Wong 2018 年 8 月 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 Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by