Finding the minimum cost of a matrix

8 次查看(过去 30 天)
Suppose i have cost matrix M= [ 100 250 300 400
600 900 400 300
250 300 160 190].
The size of matrix 3x4. Let column represent machines and row represent worker.I want to minimize cost Matrix M. Each column should have only one cost. I didn't want to use matchpair function.
How can i use intlinprog function of Matlab for minimization cost?
  5 个评论
Abolfazl Chaman Motlagh
sure, i add generall method in comment of Accepted answer. give me some time to write it clear and properly.
Danish Nasir
Danish Nasir 2021-9-11
Thanx for the help.
Please remember that output of the code (minimize cost) will be such that "any size matrix can be given as an input to the code".

请先登录,再进行评论。

采纳的回答

Abolfazl Chaman Motlagh
编辑:Abolfazl Chaman Motlagh 2021-9-10
If i get that right, you have an assignment task.
so you want to solve this :
your constraint should be :
which i represent machines, and j represent workers. you have 3 workers and 4 machines. hence the constraints are not symmetric.
you also need boundery conditions.
i am going to linearize 2d index of x_i,j to a vector so we have
finally :
M= [ 100 250 300 400;
600 900 400 300;
250 300 160 190];
f = M(:)' ;
Aeq = [ 1 0 0 1 0 0 1 0 0 1 0 0;
0 1 0 0 1 0 0 1 0 0 1 0;
0 0 1 0 0 1 0 0 1 0 0 1];
beq = ones(3,1);
x = intlinprog(f,1:12,[],[],Aeq,beq,zeros(12,1),inf(12,1));
LP: Optimal objective value is 560.000000. Optimal solution found. Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
find(x)
ans = 3×1
1 9 11
which means X11 = 1, X33=1, X42=1.
and that means : the worker 1 assign to machie 1, worker 2 assign to machine 4, and worker 3 assign to machine 3.
  5 个评论
Abolfazl Chaman Motlagh
编辑:Abolfazl Chaman Motlagh 2021-9-11
yes, i'am sorry. i forgot to include constraints for ensure than workers are not having more than one job, and machines have more than one workers. here is complete solution. i hope it doesn't have any problem:
M= [30187,18877,45543,43822;
31457,19802,46460,45501;
33977,21638,48279,48831;
35815,22274,50330,52160;
36817,23199,54771,52584]; % for example
[m n] = size(M);
f = M(:)';
if m==n
Aeq = [ kron(eye(m),ones(1,m));
kron(ones(1,m),eye(m))];
beq = ones(2*m,1);
x = intlinprog(f,1:m*n,[],[],Aeq,beq,zeros(m*n,1),ones(m*n,1));
elseif m>n
Aeq = kron(eye(n),ones(1,m));
beq = ones(n,1);
A = kron(ones(1,n),eye(m));
b = ones(m,1);
x = intlinprog(f,1:m*n,A,b,Aeq,beq,zeros(m*n,1),ones(m*n,1));
else %(m<n)
Aeq = kron(ones(1,n),eye(m));
beq = ones(m,1);
A = kron(eye(n),ones(1,m));
b = ones(n,1);
x = intlinprog(f,1:m*n,A,b,Aeq,beq,zeros(m*n,1),ones(m*n,1));
end
ind = find(x);
[worker_index machine_index] = ind2sub([m n],ind);
in 2rd and 3rd cases i add an inequality to make sum of machines for each worker be less than 1(m>n), and some of worker on each machine be less than 1(m<n).
Danish Nasir
Danish Nasir 2021-9-11
Thanx for the help. The code is working.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by