Filter löschen
Filter löschen

How can I multiply 4D array? Optimization assignment problem

3 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Torsten
Torsten am 30 Aug. 2018
Use "reshape" to turn your 4d-matrices into an 1d-vector, multiply the vectors componentenwise and sum.
  3 Kommentare
Torsten
Torsten am 30 Aug. 2018
Did you impose sum constraints on the Y ? Otherwise, all of them will be 1, I guess.
Ngai Nang Wong
Ngai Nang Wong am 30 Aug. 2018
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by