how do i code optimum problem using two matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
sharifah shuthairah syed abdullah
2018 年 5 月 2 日
コメント済み: sharifah shuthairah syed abdullah
2018 年 5 月 5 日
when i run this coding and i got wrong answer when i compare to manual calculation.
Facilitieslist = {'i1','i2','i3' , 'i4', 'i5'};
Locationlist = {'j1','j2', 'j3', 'j4', 'j5'};
%Create binary variables indexed by office number and name.
FL = optimvar('FL',Locationlist,Facilitieslist,...
'Type','integer','LowerBound',0,'Upperbound',1);
% Flow mwtrix: flow assigning facility i (colum) to facility k (row)
F = [0 27 85 2 1;
27 0 80 58 21;
85 80 0 3 48;
2 58 3 0 74;
1 21 48 74 0];
%distance flow: distance assigning location j (colum) to location q (row)
D = [0 21 95 82 56;
21 0 44 40 75;
95 44 0 84 12;
82 40 84 0 69;
56 75 12 69 0] ;
The objective is to minimize the cost of the assignment... Create an optimization problem and include the objective function....
sum sum sum sum (fik*djq*xij*xkq)
FLprob = optimproblem('ObjectiveSense','maximize','Objective',sum(sum(sum(sum(FL.*F*D)))));
are the error is at optimvar or optimproblem?..how can i write it correctly ?
0 件のコメント
回答 (1 件)
Mary Fenelon
2018 年 5 月 3 日
Your problem has a quadratic objective function. optimproblem in 18a only supports linear objectives.
You can use the ga function in Global Optimization Toolbox. It can solve problems with quadratic objectives and integer variables. It requires the matrix form of the constraints.
The ga with integer variables does not permit equality constraints so if you have those, try a >= constraint instead. The objective might force equality.
3 件のコメント
Mary Fenelon
2018 年 5 月 4 日
Quadprog doesn't allow integer constraints so you may get fractional values for the variables. You might be able to round the variable values to get a solution respecting the constraints but that would not give you a proven optimum, either.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!