Hi,
How come I still get negative value even though I have set the variable to be positive variable?
It still give me negative answer even if I have set a demand constraint, meaning that each plant can not receive a negative demand for any circumstances.
Is there any other methods to avoid negative value in answer?
Regards,
Jun Keat
Have you checked the model and solve status? Perhaps, the solver did not give you a feasible solution:
S O L V E S U M M A R Y
MODEL transport OBJECTIVE z
TYPE LP DIRECTION MINIMIZE
SOLVER CPLEX FROM LINE 65
**** SOLVER STATUS 1 Normal Completion
**** MODEL STATUS 4 Infeasible
**** OBJECTIVE VALUE 245.8800
It helps if you send reproducible code to the forum.
-Michael
Hi Michael,
Thanks for the reply. The model is really infeasible. However, I don’t know how to make it feasible. Can you help me to check on my code? Thanks so much!
Sets
i ‘waste type’ / waste-1 * waste-5 /
j ‘power plant’ / plant-1 * plant-7 / ;
Parameters
w(i) ‘waste amount(mil)’
/ waste-1 40
waste-2 39
waste-3 29
waste-4 57
waste-5 46 /
c(j) ‘capacity of plant’
/ plant-1 20
plant-2 19
plant-3 19
plant-4 17
plant-5 16
plant-6 17
plant-7 16 /;
Table o(i,j) ‘operating cost of waste’
plant-1 plant-2 plant-3 plant-4 plant-5 plant-6 plant-7
waste-1 4 2 4 5 7 6 7
waste-2 4 2 4 4 6 4 5
waste-3 3 1 3 3 5 4 5
waste-4 5 3 5 3 3 5 2
waste-5 4 2 4 5 2 4 8 ;
Variables
x(i,j) ‘waste to be operated in each plant’
opex ‘operating cost’ ;
Positive variables x;
Equations
opcost ‘definition of operation cost’
mascon1(i) ‘constraint - mass balance of waste to plant’
capcon(j) ‘constraint - waste amount cannot exceed the capacity of plant’;
opcost … opex =e= sum((i,j), o(i,j)*x(i,j));
mascon1(i) … sum(j, x(i,j)) =g= w(i) ;
capcon(j) … sum(i, x(i,j)) =l= c(j) ;
Model msw /all/ ;
Solve msw using lp minimizing opex ;
Display x.l, opex.l;
There are many ways how to deal with infeasibility. Bruce McCarl Newsletter vol. 40 gives good recommendations on how to deal with infeasible models (see section 3 of https://www.gams.com/fileadmin/community/mccarlarchive/news40.pdf).
-Michael