Problem adding constraints

Problems with modeling
Post Reply
Saheb
User
User
Posts: 4
Joined: 2 years ago

Problem adding constraints

Post by Saheb »

I have the 443 farms(f) , 16 RBPDs (r) and 5 Biorefineries (b). The constraints I have for distance between each of these have been used in the table , they are as goes :

Dfr<=85
21=<Drb<=255
Dfb<=85


However the farms sends biomass to RBPDs and biorefineries beyond their distance limit because I have not been able to add those constraints. How to do that?
Thank You.
ResDes(Saheb).gms
(177.67 KiB) Downloaded 234 times
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Problem adding constraints

Post by abhosekar »

You define distances in tables, also used them in calculating transportation cost(i guess) but you do not explicitly bound your variables with the help of these distances.

It is slightly confusing to me whether the distances are maximum distances to which a farm can deliver or they are just distances. In either case what does a 0 value of this parameter/table indicate? if Dfr is 0, does it mean that a farm cannot deliver to that particular rbpd? If yes, you can set Bfr 0.

here are few hints:
if they are maximum distances (which I don't think they are) you can set upper bound:

Code: Select all

Bfr.up(f,r,t) = Dfr(f,r);
Bfb.up(f,b,t) = Dfb(f, b);
..

If you want to set 0, use fix.

Code: Select all

Bfr.fx(f,r,t)$(not Dfr(f,r)) = 0;
You can also set the upper bound manually

Code: Select all

Bfr.up(f,r,t) = 85;
HTH
-Atharv
Saheb
User
User
Posts: 4
Joined: 2 years ago

Re: Problem adding constraints

Post by Saheb »

The 0s represent that the farms cannot deliver to those locations because they are far (out of 85km in case of Dfr) . I have written it 0 so that transport cost gets calculated for the farms in that bound.

Bfr represents the amount of biomass sent from farms to RBPD that gets calculated by GAMS itself and I want to ensure biomass is sent to RBPDs that are within the 85km range (the ones in the table).
So basically I want help with how to allocate or add that constraint.

Thank You.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Problem adding constraints

Post by abhosekar »

.lo, .up, and .fx are better ways to write such constraints than writing them as equations =l=, =g= etc..

In your case, first you want to make sure Bfr is 0 when Dfr is 0.

Bfr.fx(f, r, t)$(Dfr(f,r) = 0) = 0

You also want to make sure that Bfr is 0 if Dfr is greater than 85
Bfr.fx(f,r,t)$(Dfr(f,r) > 85) = 0

The above two statements are equivalent in meaning to adding an equation Bfr(f,r,t) =e= 0 but it is better computationally.

You can do the same for Bfb etc..

Hope this helps.

- Atharv
Saheb
User
User
Posts: 4
Joined: 2 years ago

Re: Problem adding constraints

Post by Saheb »

Thanks Atharv , that code worked. But I am facing another issue.
I have defined two binary variables yR(r,z) and yB(b,u) to select one of the capacities out of 3 for RBPDs and bio-refineries respectively. (The values are mentioned in the parameter as well)

parameters

r_ub(z) /1 20000, 2 60000, 3 90000/,
r_lb(z) /1 0 , 2 20000, 3 60000/,

parameters

b_ub(u) /1 21600, 2 57600, 3 90000/,
b_lb(u) /1 0 , 2 21600, 3 57600/,


But instead gams returns me all the 3 capacities. I hope you understand my query.
Can you help me here?

Added the gdx file as well.



Thank You again Atharv .
out.gdx
(111.84 KiB) Downloaded 154 times
Untitled_17.gms
(177.78 KiB) Downloaded 164 times
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Problem adding constraints

Post by abhosekar »

The model you attach is "proven infeasible" if you check the process log. Therefore, the solution reported is not feasible and is not supposed to make any sense. You have to first make it feasible, get a feasible solution and then check the solution.

The constraints you have for selecting only one of the capacities look good to me but your problem is infeasibility of the overall problem. To debug this, you can start from a known feasible solution (a solution that you know should be feasible) and checking which constraints are violated. Another way is to remove/relax certain constraints and bounds to see if the solution makes sense. An automated way is to use CPLEX option iis https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXiis that gives you a minimal set of contradicting constraints. You will have to use solver options file for this as mentioned here https://www.gams.com/latest/docs/UG_Sol ... PTION_FILE

I used iis on your problem and got the following:

Code: Select all

Number of equations in conflict: 1
fixed: eq2(40) = 375.593

Number of variables in conflict: 252
fixed: Bfr(40,1,1) = 0
fixed: Bfr(40,1,2) = 0
fixed: Bfr(40,1,3) = 0
fixed: Bfr(40,1,4) = 0
fixed: Bfr(40,1,5) = 0
fixed: Bfr(40,1,6) = 0
fixed: Bfr(40,1,7) = 0
fixed: Bfr(40,1,8) = 0
fixed: Bfr(40,1,9) = 0
fixed: Bfr(40,1,10) = 0
fixed: Bfr(40,1,11) = 0
fixed: Bfr(40,1,12) = 0
fixed: Bfr(40,2,1) = 0
fixed: Bfr(40,2,2) = 0
fixed: Bfr(40,2,3) = 0
fixed: Bfr(40,2,4) = 0
fixed: Bfr(40,2,5) = 0
fixed: Bfr(40,2,6) = 0
fixed: Bfr(40,2,7) = 0
fixed: Bfr(40,2,8) = 0
fixed: Bfr(40,2,9) = 0
fixed: Bfr(40,2,10) = 0
fixed: Bfr(40,2,11) = 0
fixed: Bfr(40,2,12) = 0
fixed: Bfr(40,3,1) = 0
fixed: Bfr(40,3,2) = 0
fixed: Bfr(40,3,3) = 0
fixed: Bfr(40,3,4) = 0
fixed: Bfr(40,3,5) = 0
fixed: Bfr(40,3,6) = 0
fixed: Bfr(40,3,7) = 0
fixed: Bfr(40,3,8) = 0
fixed: Bfr(40,3,9) = 0
fixed: Bfr(40,3,10) = 0
fixed: Bfr(40,3,11) = 0
fixed: Bfr(40,3,12) = 0
fixed: Bfr(40,4,1) = 0
fixed: Bfr(40,4,2) = 0
fixed: Bfr(40,4,3) = 0
fixed: Bfr(40,4,4) = 0
fixed: Bfr(40,4,5) = 0
fixed: Bfr(40,4,6) = 0
fixed: Bfr(40,4,7) = 0
fixed: Bfr(40,4,8) = 0
fixed: Bfr(40,4,9) = 0
fixed: Bfr(40,4,10) = 0
fixed: Bfr(40,4,11) = 0
fixed: Bfr(40,4,12) = 0
fixed: Bfr(40,5,1) = 0
fixed: Bfr(40,5,2) = 0
fixed: Bfr(40,5,3) = 0
fixed: Bfr(40,5,4) = 0
fixed: Bfr(40,5,5) = 0
fixed: Bfr(40,5,6) = 0
fixed: Bfr(40,5,7) = 0
fixed: Bfr(40,5,8) = 0
fixed: Bfr(40,5,9) = 0
fixed: Bfr(40,5,10) = 0
fixed: Bfr(40,5,11) = 0
fixed: Bfr(40,5,12) = 0
fixed: Bfr(40,6,1) = 0
fixed: Bfr(40,6,2) = 0
fixed: Bfr(40,6,3) = 0
fixed: Bfr(40,6,4) = 0
fixed: Bfr(40,6,5) = 0
fixed: Bfr(40,6,6) = 0
fixed: Bfr(40,6,7) = 0
fixed: Bfr(40,6,8) = 0
fixed: Bfr(40,6,9) = 0
fixed: Bfr(40,6,10) = 0
fixed: Bfr(40,6,11) = 0
fixed: Bfr(40,6,12) = 0
fixed: Bfr(40,7,1) = 0
fixed: Bfr(40,7,2) = 0
fixed: Bfr(40,7,3) = 0
fixed: Bfr(40,7,4) = 0
fixed: Bfr(40,7,5) = 0
fixed: Bfr(40,7,6) = 0
fixed: Bfr(40,7,7) = 0
fixed: Bfr(40,7,8) = 0
fixed: Bfr(40,7,9) = 0
fixed: Bfr(40,7,10) = 0
fixed: Bfr(40,7,11) = 0
fixed: Bfr(40,7,12) = 0
fixed: Bfr(40,8,1) = 0
fixed: Bfr(40,8,2) = 0
fixed: Bfr(40,8,3) = 0
fixed: Bfr(40,8,4) = 0
fixed: Bfr(40,8,5) = 0
fixed: Bfr(40,8,6) = 0
fixed: Bfr(40,8,7) = 0
fixed: Bfr(40,8,8) = 0
fixed: Bfr(40,8,9) = 0
fixed: Bfr(40,8,10) = 0
fixed: Bfr(40,8,11) = 0
fixed: Bfr(40,8,12) = 0
fixed: Bfr(40,9,1) = 0
fixed: Bfr(40,9,2) = 0
fixed: Bfr(40,9,3) = 0
fixed: Bfr(40,9,4) = 0
fixed: Bfr(40,9,5) = 0
fixed: Bfr(40,9,6) = 0
fixed: Bfr(40,9,7) = 0
fixed: Bfr(40,9,8) = 0
fixed: Bfr(40,9,9) = 0
fixed: Bfr(40,9,10) = 0
fixed: Bfr(40,9,11) = 0
fixed: Bfr(40,9,12) = 0
fixed: Bfr(40,10,1) = 0
fixed: Bfr(40,10,2) = 0
fixed: Bfr(40,10,3) = 0
fixed: Bfr(40,10,4) = 0
fixed: Bfr(40,10,5) = 0
fixed: Bfr(40,10,6) = 0
fixed: Bfr(40,10,7) = 0
fixed: Bfr(40,10,8) = 0
fixed: Bfr(40,10,9) = 0
fixed: Bfr(40,10,10) = 0
fixed: Bfr(40,10,11) = 0
fixed: Bfr(40,10,12) = 0
fixed: Bfr(40,11,1) = 0
fixed: Bfr(40,11,2) = 0
fixed: Bfr(40,11,3) = 0
fixed: Bfr(40,11,4) = 0
fixed: Bfr(40,11,5) = 0
fixed: Bfr(40,11,6) = 0
fixed: Bfr(40,11,7) = 0
fixed: Bfr(40,11,8) = 0
fixed: Bfr(40,11,9) = 0
fixed: Bfr(40,11,10) = 0
fixed: Bfr(40,11,11) = 0
fixed: Bfr(40,11,12) = 0
fixed: Bfr(40,12,1) = 0
fixed: Bfr(40,12,2) = 0
fixed: Bfr(40,12,3) = 0
fixed: Bfr(40,12,4) = 0
fixed: Bfr(40,12,5) = 0
fixed: Bfr(40,12,6) = 0
fixed: Bfr(40,12,7) = 0
fixed: Bfr(40,12,8) = 0
fixed: Bfr(40,12,9) = 0
fixed: Bfr(40,12,10) = 0
fixed: Bfr(40,12,11) = 0
fixed: Bfr(40,12,12) = 0
fixed: Bfr(40,13,1) = 0
fixed: Bfr(40,13,2) = 0
fixed: Bfr(40,13,3) = 0
fixed: Bfr(40,13,4) = 0
fixed: Bfr(40,13,5) = 0
fixed: Bfr(40,13,6) = 0
fixed: Bfr(40,13,7) = 0
fixed: Bfr(40,13,8) = 0
fixed: Bfr(40,13,9) = 0
fixed: Bfr(40,13,10) = 0
fixed: Bfr(40,13,11) = 0
fixed: Bfr(40,13,12) = 0
fixed: Bfr(40,14,1) = 0
fixed: Bfr(40,14,2) = 0
fixed: Bfr(40,14,3) = 0
fixed: Bfr(40,14,4) = 0
fixed: Bfr(40,14,5) = 0
fixed: Bfr(40,14,6) = 0
fixed: Bfr(40,14,7) = 0
fixed: Bfr(40,14,8) = 0
fixed: Bfr(40,14,9) = 0
fixed: Bfr(40,14,10) = 0
fixed: Bfr(40,14,11) = 0
fixed: Bfr(40,14,12) = 0
fixed: Bfr(40,15,1) = 0
fixed: Bfr(40,15,2) = 0
fixed: Bfr(40,15,3) = 0
fixed: Bfr(40,15,4) = 0
fixed: Bfr(40,15,5) = 0
fixed: Bfr(40,15,6) = 0
fixed: Bfr(40,15,7) = 0
fixed: Bfr(40,15,8) = 0
fixed: Bfr(40,15,9) = 0
fixed: Bfr(40,15,10) = 0
fixed: Bfr(40,15,11) = 0
fixed: Bfr(40,15,12) = 0
fixed: Bfr(40,16,1) = 0
fixed: Bfr(40,16,2) = 0
fixed: Bfr(40,16,3) = 0
fixed: Bfr(40,16,4) = 0
fixed: Bfr(40,16,5) = 0
fixed: Bfr(40,16,6) = 0
fixed: Bfr(40,16,7) = 0
fixed: Bfr(40,16,8) = 0
fixed: Bfr(40,16,9) = 0
fixed: Bfr(40,16,10) = 0
fixed: Bfr(40,16,11) = 0
fixed: Bfr(40,16,12) = 0
fixed: Bfb(40,1,1) = 0
fixed: Bfb(40,1,2) = 0
fixed: Bfb(40,1,3) = 0
fixed: Bfb(40,1,4) = 0
fixed: Bfb(40,1,5) = 0
fixed: Bfb(40,1,6) = 0
fixed: Bfb(40,1,7) = 0
fixed: Bfb(40,1,8) = 0
fixed: Bfb(40,1,9) = 0
fixed: Bfb(40,1,10) = 0
fixed: Bfb(40,1,11) = 0
fixed: Bfb(40,1,12) = 0
fixed: Bfb(40,2,1) = 0
fixed: Bfb(40,2,2) = 0
fixed: Bfb(40,2,3) = 0
fixed: Bfb(40,2,4) = 0
fixed: Bfb(40,2,5) = 0
fixed: Bfb(40,2,6) = 0
fixed: Bfb(40,2,7) = 0
fixed: Bfb(40,2,8) = 0
fixed: Bfb(40,2,9) = 0
fixed: Bfb(40,2,10) = 0
fixed: Bfb(40,2,11) = 0
fixed: Bfb(40,2,12) = 0
fixed: Bfb(40,3,1) = 0
fixed: Bfb(40,3,2) = 0
fixed: Bfb(40,3,3) = 0
fixed: Bfb(40,3,4) = 0
fixed: Bfb(40,3,5) = 0
fixed: Bfb(40,3,6) = 0
fixed: Bfb(40,3,7) = 0
fixed: Bfb(40,3,8) = 0
fixed: Bfb(40,3,9) = 0
fixed: Bfb(40,3,10) = 0
fixed: Bfb(40,3,11) = 0
fixed: Bfb(40,3,12) = 0
fixed: Bfb(40,4,1) = 0
fixed: Bfb(40,4,2) = 0
fixed: Bfb(40,4,3) = 0
fixed: Bfb(40,4,4) = 0
fixed: Bfb(40,4,5) = 0
fixed: Bfb(40,4,6) = 0
fixed: Bfb(40,4,7) = 0
fixed: Bfb(40,4,8) = 0
fixed: Bfb(40,4,9) = 0
fixed: Bfb(40,4,10) = 0
fixed: Bfb(40,4,11) = 0
fixed: Bfb(40,4,12) = 0
fixed: Bfb(40,5,1) = 0
fixed: Bfb(40,5,2) = 0
fixed: Bfb(40,5,3) = 0
fixed: Bfb(40,5,4) = 0
fixed: Bfb(40,5,5) = 0
fixed: Bfb(40,5,6) = 0
fixed: Bfb(40,5,7) = 0
fixed: Bfb(40,5,8) = 0
fixed: Bfb(40,5,9) = 0
fixed: Bfb(40,5,10) = 0
fixed: Bfb(40,5,11) = 0
fixed: Bfb(40,5,12) = 0
This shows that eq2(40) is fixed to 375.... some nonzero value but Bfr(40, ..) and Bfb(40, ...) are fixed to zero. You cannot have a nonzero value by adding multiple zeros. This could be a good starting point for your debugging. You can check whether you really want all those Bfb and Bfr to be 0 and/or if the parameter farm_yield(40) should be nonzero. It is very likely that you will again get an infeasible solution but you can repeat this procedure with iis and resolve your issue.

- Atharv
Saheb
User
User
Posts: 4
Joined: 2 years ago

Re: Problem adding constraints

Post by Saheb »

Thanks Atharv .

I managed to run it down to 10 infeasible but I want to know how to use the iis . Can you help me with the code?
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Problem adding constraints

Post by abhosekar »

Please read the documentation using the link about options file that I provided in my previous reply. There are several examples on how to use options, even CPLEX options. You can use any of those code snippets and replace option name with iis and set its value to 1. Let me know precisely what you are trying/struggling with.
- Atharv
Post Reply