My smax function is not working properly even though execution of nload is right - gams-math

I can not find the answer by myself and therefore I'm asking you. I'm trying to modify the input load subject to two different price range. It goes well I receive answers on nload, however when it comes to find the maximum value it doesn't work. I have even replaced smax with an number, but the output answer is being strange...
Con3(d,hpd).. ndload(d,hpd) =E= odload(d,hpd)*(1+sum(hpd1,PRICE_EL(hpd,hpd1)*(P_H(hpd1)-PH_OLD)/PH_OLD));
Con4(hpd)$((ord(hpd)>15)and(ord(hpd)<23)).. P_H(hpd) =E= PHP;
Con5(hpd)$((ord(hpd)<16)or(ord(hpd)>22)).. P_H(hpd) =E= PLP;
Con6.. E_NEW =E= sum((d,hpd),ndload(d,hpd)) ;;
Con7.. LF_NEW =E= sum(d,NDLF(d))/1;
Con8(d).. NDLF(d) =E= sum(hpd,ndload(d,hpd))/(smax(hpd,ndload(d,hpd))*24);

Related

Solving GAMS optimization for a specific range within a set

I'm trying to solve an optimization problem on GAMS, but only for a subset. Right now, i have a code that optimizes for all the elements of set t:
t time in hours / 1 * 8760 /
How do I run the optimization only for t from 1 to 3500, AND from 6500 to 8760 (for example)? FYI, all of my parameters data (from .csv) that i imported to GAMS have 8760 values. Here's a simple objective function to use:
eObjFunc.. vZ =e= sum(t, v1(t));
The simplest way I could think of is to edit all my .csv data so they only have the t values that I care for. In this case, define set t = 1 to 3500, 6500 to 8760. Then, just run the optimization.
However, I'm sure there's a smarter way to do this without having to modify my .csv data...
Really appreciate your help!
You can define subsets like this (assuming t is defined already as 1*8760):
Set tt(t) /1*3500, 6500*8760/;
And then use tt instead of t in your equation:
eObjFunc.. vZ =e= sum(tt, v1(tt));

Splitting GAMS equation using if else statements

I have a working GAMS optimization model using LP. I want to modify one of my equations so that it excludes one of the terms when t = 1. Here's the simplification of this problem:
Set t "time in hours" / 1 * 8760/ ;
If t = 1:
vDemand(t) =e= p1*(vInternal(t) - pAmbient(t))
else:
vDemand(t) =e= p1*(vInternal(t) - pAmbient(t)) + p2*(vInternal(t) - vInternal(t-1))
How do I modify this vDemand equation while keeping my optimization linear?
I looked up and tried the different ways to incorporate conditional statements on GAMS, but not successful so far.
vDemand(t) =e= p1*(vInternal(t) - pAmbient(t)) + (p2*(vInternal(t) - vInternal(t-1)))$(ord(t)>1);
The $ condition at the end of the second term makes sure, that that part is only used, if it is not the first element of the set t.

How do I sum up over an uncontrolled set?

I have to develelop a mcp model using GAMS. I am not quite experienced with this program but the error compilation website was not quite helpful either.
I have tried varying the indices but this would only change the error from uncontrolled set to controlled set. I did also try using the Alias function but either I did it wrong or it did not work at all.
Variables
lambda(p) shadow price
;
POSITIVE VARIABLES
R(t,p) production
S(t,p) Stock at time t
;
RES_resource_lambda(p)..
-(SUM(t, R(t,p)) - S(t,p)) =g= 0
;
The problem is about the last t in the equation:
RES_resource_lambda(p)..
-(SUM(t, R(t,p)) - S(t,p)) =g= 0
;
The t in R(t,p) is controlled by the SUM, but nothing controls the t in S(t,p). You need to specify, what you want to do with this one, e.g. add it to the SUM as well.

Conditional Equations with Variable in GAMS

I need your help to solve this "Little" problem I'm having programming with GAMS.
In my objective function I have this member that is z = [...]-TWC(j)*HS(j).
Where HS(j)is a variable.
Now, TWC(j) should be a parameter that works like this:
TWC(j) = 0 when HS(j) < 1000
and
TWC(j) = 3.21 when HS(j) >=1000.
Any idea how to implement this in GAMS? my attempts all failed.
EDIT: this is what I tried I defined an equation called TWCup(j) that was:
TWCup(j)$(HS.l(j) >= 1000).. TWC(j) =e= 3.21;
Thanks ;)
Probably not relevant for the OP anymore (since the question is more than 3 years old), but maybe useful for someone else that looks at this question.
If TWC(j) is a function of your variable HS(j), it is not a parameter. It is another variable. So you should define TWC(j) as a variable and not as a parameter. This is probably the reason you were getting errors.
There are some ways to fix your problem: One is to actually turn TWC(j) into a variable. But this would turn your problem into non-linear which could be (or not) an issue. Also, this could need the use of binary variables, which could also become a problem (again, or not).
But I think this issue could be resolved with a different specification of the LP. The cost function f(HS(j)) = TWC(j)*HS(j) is linear by parts and convex, which you can represent in a standard LP using auxiliary variables (assuming you are minimizing).
* declare auxiliary variable
Variable
w(j);
* declare equations for linear by part cost function
Equation
costfun1(j)
costfun2(j);
;
* define costfun1 and costfun2
costfun1(j).. w(j) =g= 0;
costfun2(j).. w(j) =g= -3210 + 3.21*HS(j);
*redefine objective function (note that I changed to plus because I assumed this is a cost function that you are minimizing)
z = [...]+w(j)
This solution is very problem dependent. I assumed you were minimizing and I changed the sign in the objective function to '+'. If this was not the case, this would not work (would not be convex). Then we would need to check other approaches.
But the takeaway here is to stress that something that is a function of a variable is also a variable. But you may have options to reformulate your problem to address the problem.

Maxima doesn't find a solution for diff eq with desolve

During my exercise with wxmaxima 11.08.0 (ubuntu 12.04, Maxima version: 5.24.0)
I followed an example from P.Lutus and his second example didn't work for me.
eq: y(t) = -r*c*'diff(y(t),t)+m*sin(%omega*t);
sol:desolve( eq, y(t) );
Is %omega zero or nonzero? nonzero
then Maxima isn't reacting anymore until I restart it.
Is there something changed in maxima that I need to activate or define first to get the result ?
The expected output should be:
There is a second part of my question in case I define the equation by hand:
sol: y(t) = (m * sin(%omega*t)) / (%omega^2*c^2*r^2 + 1) -
(%omega*c*m*r*cos(%omega*t)) / (%omega^2*c^2*r^2 + 1) +
(%omega*c*m*r*%e^-((1*t)/(c*r))) / (%omega^2*c^2*r^2 + 1);
Initial conditions for a continuous process:
init_val:-(c*m*r*(%e^-(t/r*c))*%omega)/(c^2*r^2*%omega^2+1);
atvalue(y(t),t=0, init_val);
try2 : desolve(sol,y(t));
"Is "%omega" zero or nonzero?" nonzero;
Here the last term is still there. Are these problems based on the use of trigonometric functions ?
Best regards,
Marcus
I updated via PPA to wxMaxima 13.04.0 & Maxima 5.29.1. Now desolve fnished, but the last term seems very complicated.
Doing the init_val with the negativ last term and desolve command still leaves the %e^(..)*... in the equation.
You might get more interest in this question on the Maxima mailing list. See: http://maxima.sourceforge.net/maximalist.html
For the first version of Lutus example 2, I get:
y(t) = m*sin(%omega*t)/(%omega^2*c^2*r^2+1)
-%omega*c*m*r*cos(%omega*t)/(%omega^2*c^2*r^2+1)
+(y(0)*%omega^2*c^3*r^3+%omega*c^2*m*r^2+y(0)*c*r)*%e^-(t/(c*r))
/(c*r*(%omega^2*c^2*r^2+1))$
which is the same as the expected result, if y(0) = 0. However, I don't see where that is assumed.
After atvalue(y(t),t=0,init_val), I get the same result as Lutus, namely:
y(t) = m*sin(%omega*t)/(%omega^2*c^2*r^2+1)
-%omega*c*m*r*cos(%omega*t)/(%omega^2*c^2*r^2+1)$
I am working with Maxima 5.31.1, built with Clisp, on Linux.