Finding the minimum cost of a matrix

조회 수: 4 (최근 30일)
Danish Nasir
Danish Nasir 2021년 9월 10일
댓글: Danish Nasir 2021년 9월 11일
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
Abolfazl Chaman Motlagh 2021년 9월 11일
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일
편집: 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일
편집: 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에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by