Can anyone help me to express this condition in Gams? - gams-math

I have this condition and want to express it in Gams! But Really dont Know How to do it!
If (t'+L(d)*(1-alfa)=t) ---> Y=1
Otherwise ---> Y=0
Y is a Binary variable, alfa is a continuous variable
L(d) is a parameter, t and t' are time sets.
Thanks for your help!

Related

How to solve systems with TI-nspire automatically

is there any solution to solve a large system of equations in a program with the TI-nspire without typing all the variable names by hand?
For example, the function solve([1 2; 3 4]* [x; y] = 2,{x,y}) requires typing x,y manually. How is this done if the dimensions of the matrix can change?
I tried to use the function constructMat(x[i], i, j, 5, 1) which partly works but solve doesn't accept this function as variable as second argument.
Thanks for the help!!
I had this problem a while ago, i couldnt find any solution but to manually type the list of variables. Ive found the way to construct the list of unkowns (B_n):
i:=3:j:=4:B_n:=newlist(j+1) For i1,i,i+j:B_n[i1-i+1]:=expr("b"&string(i1)):endfor
with result: {b3,b4,b5,b6,b7}.
I dont remember exactly why this didnt work, i guess its the same reason (solve or zeros function will not accept this list as an argument)

How to express a condition in GAMS?

I am a new user in GAMS and I want to write a condition but I cannot figure out the right way to express it.
I want b(l) to be equals Pcost(pl) when Loc(l,pl) is not zero.
Is there any way to express this?
b(l) = sum(pl$Loc(l,pl), Pcost(pl));
The $ is the condition sign. pl needs to be controlled on the right. Therefore, the sum is used. Assuming, that there is just one pl for each l with Loc(l,pl)>0, the assignment above will do, what you asked for.
Note: $Loc(l,pl) can be read as "if Loc(l,pl) is unequal to zero. If you want to be more explicit, you could also write the following (which is really the same as the first version for GAMS):
b(l) = sum(pl$(Loc(l,pl)<>0), Pcost(pl));

Octave: quadprog index issue?

I am trying to run several files of code for an assignment. I am trying to solve an optimization problem using the "quadprog" function from the "optim" package.
quadprog is supposed to solve the optimization problem in a certain format and takes inputs H,f, A,b, Aeq, Beq, lb, ub.
The issue I am having involves my f which is a column vector of constants. To clarify, f looks like c*[1,1,1,1,1,1] where c is a constant. Quadprog seems to run my code just fine for certain values of c, but gives me the error:
error: index (_,49): but object has size 2x2
error: called from
quadprog at line 351 column 32
for other values of c. So, for example, 1/3 works, but 1/2 doesn't. Does anyone have any experience with this?
Sorry for not providing a working example. My code runs over several files and I seem to only be having problems with a specific value set that is very big. Thanks!
You should try the qp native Octave function.
You mention f is: c*[1,1,1,1,1,1] but, if c is a scalar, that is not a column vector. It seems very odd that a scalar value might produce a dimensions error...

sum+sum equation issue in GAMS

I defined the following equation to calculate the sum of total power consumed by the system:
TotalPower.. systemPower =e= sum(J,P(J)) + sum(I,CP(I));
However, the variable systemPower gets only the result of the second sum and not both!. The declaration of P(J) is as following:
P.LO(I)=0;
P.up(I)=100;
P.l('i1')=2;
P.l('i2')=3;
Please, Can any one explain why I get the result of a single sum? How I can do to get both?. I tried also to separate them in different values but yet I get the same result.
Thank you in advance.
I though it is a good idea to share this it might help someone else. I used a variable directly instead of an equation and I put it in the following form and it worked.
systemPower.l = sum(I,P.l(I))+sum(I,CP(I));

Mathematica: Commands return no output, but itself. Bug?

I am working with Wolfram Mathematica 8 and have the following problem. I have an optimization problem under certain constraints and want to have an analytical (symbolical solution). I am maximizing function piA. My input is:
piA[a_, WA1_, WA0_] =
a/(1 + a)*(X - (y*WA1 + 1)^(1/y)) - 1/(1 + a) ((y*WA0 + 1)^(1/y));
Maximize[{piA[a, WA1, WA0], WA0 >= -1/y, WA1 >= -1/y}, WA0]
What I get most of the times is:
Maximize[{-((1 + WA0 y)^((1/y))/(1 + a)) + (
a (X - (1 + WA1 y)^(1/y)))/(1 + a), WA0 >= -(1/y), WA1 >= -(1/y)},a]
Basically, the command does nothing, but outputs itself. Only once I have managed to get the proper output (too long to paste here). I have tested it with simpler functions and it works. Unfortunately, I cannot understand what causes the problem. It is not a syntax problem, since it has worked like that several times. Any help would be very much appreciated.
P.S. Just checked again and my input ALWAYS generates the wrong output. The time it generated the solution was when I accidentally set parameters X and y to certain numbers.
The most likely reason is that given the function and constraints, Mathematica doesn't know how to maximize your function with respect to WA0. Note you also have a free variables X and a in there, and it might not have enough information about the domain of X and a to be able to properly form a solution to your equation.
I've had instances where I tried feeding in some equations and constraints and Mathematica simply couldn't do anything with them because they were too general. This may be the case here as well. Is there a specific problem you're trying to solve, and is there any way you could give Mathematica more context?
I don't think this is a bug at all, but it's unfortunate that sometimes Mathematica will just spit back your input when it doesn't have any rules for solving what you gave it.
The usual reason these things happens seems to be when the expressions given are too general for Mathematica to handle, or when it it's faced with a set of expressions that are ill formed.
Just as an example, I tried passing in fractions into a function I wrote that specifically looked for rational expressions, thinking it would work. It turned out that it needed to handle both Rational[a, b] and Times[a, Power[b, -1]]. It could be the case that Mathematica is not expecting a constraint to be of the form GreaterEqual[a, b].
Mathematica returns an answer if you assign the variable a some value. Maybe you could build your strategy on that? In fact it does provide an answer if you assign a value to any of the variables.
( I would need more background of the problem to go from there... )