The document provides instructions to solve a linear programming problem using GAMS. It defines the objective function and constraints of the problem. It then performs some modifications to the constraint coefficients based on if-else statements. It conducts a sensitivity analysis by changing the right hand side of one constraint and resolves the problem. It writes the results to a text file before and after the sensitivity analysis.
1 of 3
Download to read offline
More Related Content
Lab 5
1. Cairo University, Software Packages,
Faculty of Computers and Information, Lab # 1
Decision Support Department,
Solve the below problems using GAMS IDE:
Max z = 5x1 + 4x2
Subject to
c1 6x1 + 4x2 24 ,
c2 x1 + 2x2 6 ,
c3 -x1 1 ,
c4 x2 2 ,
x1 , x2 0
Display the optimal solution .
If- elseif
Check if coefficient of x2 in c3 less than 1, then make it 1
else if coefficient of x2 in c2 more than 1 and coefficient of x1 in c1 more than 2 ; then put
coefficient of x1 in c3 equal -1
else let coefficient of x1 in c4 equal 0
Sensitivity analysis
Change the value of r.h.s of c2 from 6 to 10.
See the impact on the solution.
Writing to file
Write the results on a text file before and after sensitivity analysis.
2. $eolcom ->
Sets
i / i1,i2 /
j / j1 * j4 / ;
parameters objcoeff(i) / i1 5, i2 4/
rhs(j)/j1 24, j2 6, j3 1, j4 2 /;
Table d(j,i)
i1 i2
j1 6 4
j2 1 2
j3 -1 0
j4 0 1 ;
if (d("j3","i2")<1, d("j3","i2")=1 ;
elseif (d("j2","i2")>1) and (d("j1","i1")>2),d("j3","i1")=-1;
else d("j4","i1")=0;);
Variables
x(i)
z ;
Positive Variable x ;
Equations
profit
constraint(j) ;
profit .. z =e= sum(i, objcoeff(i)*x(i)) ;
constraint(j) .. sum(i,d(j,i)* x(i)) =l= rhs(j) ;
Model examp /all/ ;
Solve examp using lp max z;
display x.l,z.l;
file results /exampresults.txt/ -> write to afile
put results;
put 'First example results'// ;
3. loop (i,put i.tl, x.l(i)/);
put 'objective value' z.l//;
rhs("j2") = 10; -> senstivity analysis
Solve examp using lp max z;
display x.l,z.l;
put results; -> write to afile
put 'Senstivity Example results'// ; -> write text to a file
loop (i,put i.tl, x.l(i)/); -> t1 means value of i
put 'objective value' z.l//; -> / is endl