필터 지우기
필터 지우기

How can I multiply 4D array? Optimization assignment problem

조회 수: 3 (최근 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 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