intlinprog summation MILP optimization problem: ALREADY SOLVED IN GAMS [PROVIDED CODE] BUT CONFUSED IN MATLAB

3 views (last 30 days)
CONFUSION: HOW TO MAKE Aeq,A vector for this also confused how to use values in FUN in solve.m
Please Help, I solved this on CPLEX, GAMS but stuck in MATLAB
GAMS WORKING CODE:
SP,PCL,PCM,PCH,ICL,ICM,ICH,CL,CM,CH,RM1,RM2 = 1x54 double
R=[500,500]
Budget=1000
I want to optimize F(below defined) and find values of X,Y [int] , Z[int] ,L,M,H using intlinprog
PROD.m
function [F,A,B,Aeq,Beq,intcon,lb,ub]= Prod(SP,PCL,PCM,PCH,ICL,ICM,ICH,CL,CM,CH,RM1,RM2,R,Budget,X,Y,Z,L,M,H)
D=length(X);
F=0;
for d=1:D
F=F-SP(d)*X(d)+PCL(d)*L(d)+PCM(d)*M(d)+PCH(d)*H(d);
end
A(1,:)=[1;0;-10000;0;0;0];
A(2,:)=[ 0 ;-1 ;0 ;1 ;0 ;0];
A(3,:)=[0;1;0;0;0;1];
for d=1:D
A(4,1)=A(4,1)+X(d)*RM1(d);
A(5,1)=A(5,1)+X(d)*RM2(d);
A(6,4)=A(6,4)+ICL(d)*L(d);
A(6,5)=A(6,5)+ICM(d)*M(d);
A(6,6)=A(6,6)+ICH(d)*H(d);
end
B=[0;0;1;R(1);R(2);Budget]';
intcon=[2,3];
Aeq=zeros(55,6);
for d=1:D
Aeq(d,1)=X(d);
Aeq(d,4)=-CL(d)*L(d);
Aeq(d,5)=-CM(d)*M(d);
Aeq(d,6)=-CH(d)*H(d);
end
Aeq(55,:)=[0;0;-1;1;1;1;];
Beq=zeros(55,1);
lb=[0 0 0 0 0 0];
ub=[inf inf inf inf inf inf];
end
SOLVE.M [confused]
clc;clear;
FUN=@Prod;
[F,A,B,Aeq,Beq,intcon,lb,ub]=FUN(SP,PCL,PCM,PCH,ICL,ICM,ICH,CL,CM,CH,RM1,RM2,R,Budget,X,Y,Z,L,M,H);
%X,Y,Z,L,M,H
[x,fval]=intlinprog(F,intcon,A,B,Aeq,Beq,lb,ub);

Accepted Answer

Alan Weiss
Alan Weiss on 4 Nov 2020
Edited: Alan Weiss on 4 Nov 2020
I suspect that you would be best served by the problem-based approach. You would have a bit of overhead to learn this approach, but I believe that it would overall be faster for you to do so.
For problem-based MILP examples, see Problem-Based Mixed-Integer Linear Programming.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
shubham kumar gupta
shubham kumar gupta on 4 Nov 2020
Edited: shubham kumar gupta on 4 Nov 2020
Thank You,
Sir, I have seen those but I was confused how to create a A vector as A contains only "coefficients" but I need A something like this AS I HAVE CONTRAINT OF USING INTLINPROG
A(4,1)=A(4,1)+X(d)*RM1(d);
How I can only use coefficient
A(4,1)=A(4,1)+...*RM1(d);
shubham kumar gupta
shubham kumar gupta on 4 Nov 2020
Edited: shubham kumar gupta on 4 Nov 2020
What I though is transfrom X(d)*RM1(d) into this X1,X2,X3...X54 with each coefficients as RM1, RM2,RM3...RM54
And it did the job
F(1,:)=[-SP';zeros(54,1);zeros(54,1);PCL';PCM';PCH'];
A(1,:)=[ones(54,1);zeros(54,1);-1000000*ones(54,1);zeros(54,1);zeros(54,1);zeros(54,1)];
A(2,:)=[zeros(54,1);-1*ones(54,1);zeros(54,1);ones(54,1);zeros(54,1);zeros(54,1)];
A(3,:)=[zeros(54,1);ones(54,1);zeros(54,1);zeros(54,1);zeros(54,1);ones(54,1)];
A(4,:)=[RM1';zeros(54,1);zeros(54,1);zeros(54,1);zeros(54,1);zeros(54,1)];
A(5,:)=[RM2';zeros(54,1);zeros(54,1);zeros(54,1);zeros(54,1);zeros(54,1)];
A(6,:)=[zeros(54,1);zeros(54,1);zeros(54,1);IL';IM';IH'];
B=[0;0;1;R(1);R(2);Budget];
intcon=(55:162);
lb=zeros(1,324);
ub=inf(1,324);
Aeq(1,:)=[ones(54,1);zeros(54,1);zeros(54,1);-1*CL';-1*CM';-1*CH'];
Aeq(2,:)=[zeros(54,1);zeros(54,1);-1*ones(54,1);ones(54,1);ones(54,1);ones(54,1)];
Beq=[0;0];
[x,FVAL,EXITFLAG,OUTPUT]=intlinprog(F,intcon,A,B,Aeq,Beq,lb,ub);
FVAL=-1*FVAL;
Is it possible to make it in loops and easy or better instead of taking X(d) into X1....X54
BUT I'M AFRAID AS SOLUTION FROM MATLAB AND GAMS "DIDNOT" MATCHED!! with huge difference in GAMS i was getting around 27669.4327 and in matlab I am getting 2891.949960. difference of 10 factor

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!