Questions Tagged With if-elsehttp://www.or-exchange.com/tags/if-else/?type=rssquestions tagged <span class="tag">if-else</span>enFri, 02 Sep 2016 04:53:56 -0400If Function in GAMShttp://www.or-exchange.com/questions/14158/if-function-in-gams<p>I've been busy with a model, but I'm uncomfortable about the result because I think GAMS violates a constraint. What I want to tell to GAMS is:
"check demand first -> then check current stocks -> <strong>IF</strong> there is enough stocks sell from current stocks -> <strong>IF</strong> there is <strong>not</strong> enough stocks first buy (produce) then sell."</p>
<p>I think in the model GAMS does not obey any demand (sell), any minimum values and sells everything without buying any.</p>
<p>The model is hereinbelow:</p>
<pre><code>Sets
i items /s,p,b/
t time in quarters /1,2,3/
Parameters
price(i) selling price per unit i per quarter in euros /s 6.34, p 6.46, b 5.93/
inistock(i) initial stock in units /s 320000, p 296199, b 104208/
cap(i) capacity limit for each unit /s 400000, p 350000, b 150000/
c cost of holding 1 unit of i /s 10, p 15, b 12/
Scalars
tcap total capacity of warehouse /650000/
Variables
stock(i,t) stock stored at time t
sell(i,t) stock sold at time t
buy(i,t) stock bought at time t
cost total cost
Positive Variables stock,sell,buy
Equations
cst total cost occurs
stck(i,t) stock balance of unit i at time t;
cst.. cost=e=sum((i,t),price(i)*(buy(i,t)-sell(i,t))+c(i)*stock(i,t));
stck(i,t).. stock(i,t)=e=inistock(i)+stock(i,t-1)+buy(i,t)-sell(i,t);
stck.up(i,t)=tcap;
Option LP=Cplex ;
Option optcr=0;
Model TWH The Warehouse Problem / all /;
Solve TWH minimizing cost using lp;
</code></pre>
<p>Thank you in advance for your support!</p>dregazzFri, 02 Sep 2016 04:53:56 -0400http://www.or-exchange.com/questions/14158/if-function-in-gamsgams-cplexif-elseifmodeling an if statement without an else clausehttp://www.or-exchange.com/questions/11901/modeling-an-if-statement-without-an-else-clause<p>I am trying to use linear programming to model an if statement that does not include an else clause. I need to model this:</p>
<p>if Ci <= 6, Xi = 1; however Xi can equal either 1 or 0 if Ci > 6</p>neddstarkTue, 07 Apr 2015 18:22:02 -0400http://www.or-exchange.com/questions/11901/modeling-an-if-statement-without-an-else-clausenoif-elseifif-else in linear programminghttp://www.or-exchange.com/questions/9530/if-else-in-linear-programming<p>Hello,</p>
<p>I am trying to model a system with following constraints using linear programming in MATLAB:</p>
<pre><code>if P(i) > 0
limit1 <= K(1)*P(1) + K(2)*P(2) + K(3)*P(3) + ... + K(i)*P(i) <= limit2
# K(1),K(2)... are constants, P is power to a battery
else if P(i) <= 0
limit1 <= C(1)*P(1) + C(2)*P(2)+ C(3)*P(3) + ... + C(i)*P(i) <= limit2
# C(1),C(2)... are constants different from K(1)...
</code></pre>
<p>I modified it in following form: (e.g. for i=1)<br>
</p>
<pre><code>P(1)<=b*U # b is binary & U is a big number;
limit1<= (1-b)*P(1)*C(1) + b*P(1)*K(1)<=limit2
</code></pre>
<p>Is this formulation correct? My doubt is that at b=0, I get P(1)<=0 and the second condition, which is perfect. But when b=1, I get P(1)<=U, and first condition. But then the program can also return P(1) less than zero for b=1. Is there something wrong here or I did not understand correctly? Thank you so much for any help :)</p>
<p>PS: I know it is not linear right now. But I want to confirm if what I did so far is right or not. <br>
</p>
<p>cheers,<br><br>
Aastha</p>aasthaWed, 30 Apr 2014 12:03:24 -0400http://www.or-exchange.com/questions/9530/if-else-in-linear-programminglinear-programmingif-elseGAMS - if and else problemhttp://www.or-exchange.com/questions/9523/gams-if-and-else-problem<p>Hello, </p>
<p>I have just started to work with GAMS. I have already programmed a storage optimization tool, which is working fine. It optimizes the revenue at the spot market minus costs of storage and volume.</p>
<p>But now I want to extend my model (I want to include self discharge). The self discharge depends on State of Charge (SOC - variable in my model) and of course the storage type (sto1, sto2, sto3 - set u_S). </p>
<p>I have the following parameters: </p>
<pre><code> sel_Dis1(u_S) self discharge rate per day SOC > 80%
/ sto1 0.999928762
sto2 0.999943304
sto3 0.999957696 /
sel_Dis2(u_S) self discharge rate per day SOC < 80%
/ sto1 0.999971941
sto2 0.999986041
sto3 0.999986041 /
</code></pre>
<p>Depending on the level of my variable SOC - the self discharge differs. But I need just one SelDis variable(?), thats why I build the following if else term: </p>
<pre><code> Variables
x
y etc.
SOC(t,u_S)
SelDis(t,u_S)
LOOP(u_S,LOOP(t,
if((SOC(t,U_S)gt 0.8),
SelDis(t,u_S)=Sel_Dis1(u_S)
else
SelDis(t,u_S)=Sel_Dis2(u_S)););
</code></pre>
<p>But unfortunately it is not working. Is my "if else" term wrong? Where do I have to put it? Under equations? Do you need more information?</p>
<p>Thank you very much in advance!</p>banolliTue, 29 Apr 2014 04:23:12 -0400http://www.or-exchange.com/questions/9523/gams-if-and-else-problemgamsif-else