Hello Everyone,
I am formulating a global optimization MILP. In the formulation, I am struggling in defining indices. I need to model equation of following type:
x = x_(n-1) * t_(n) + 5;
- where n-1 and n are subscripts.
Please guide me how to model above equation.
Regards,
ZAR
Formulating Equation of type x_(n-1) Domain Topic is solved
Re: Formulating Equation of type x_(n-1) Domain
Hi
Assuming your variable is x(n), you can use
Although sets are not numbers the expression set_element - 1 can be used to indicat the previous set element.
Furthermore, as for n=1, you have a problem as n(-1) is not part of the model. Therefore, you define the equation as
and fix x(n) wiht X.FX("1") = x0.
I hope this helps
Renger
Assuming your variable is x(n), you can use
Code: Select all
x(n) =E= x_(n-1) * t_(n) + 5;
Furthermore, as for n=1, you have a problem as n(-1) is not part of the model. Therefore, you define the equation as
Code: Select all
myeq(n)$(ord(n) > 1)..
x(n) =E= x_(n-1) * t_(n) + 5;
I hope this helps
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: Formulating Equation of type x_(n-1) Domain
Hi Ranger,
I think, I didn't define the problem elaborately. Let me redefine it here:
The equation that I want to model is the RHS of following equation:
Please note that this not the complete code. So you will not be able to get anything by running it.
I am struggling with the formulating Eq2. The RHS of this equation has 't-1' as domain of x, which is a constant, as defined in the Parameters. However, modelling this way, generates error because the equation definition 'Eq2(n)' does not includes 't' in its domain. Now, how can I model this?
I think, I didn't define the problem elaborately. Let me redefine it here:
Code: Select all
$TITLE Piece-wise Affine Test1
SET n /1, 2, 3/
t /a, b, c, d/
;
FREE VARIABLES z0;
POSITIVE VARIABLES x, y, z1;
BINARY VARIABLES lambda(n);
Parameter P(t) 'Number of Partitions'
/a 0, b 2, c 3, d 4/;
x.LO=0;
x.UP=6;
EQUATIONS
obj, con, Eq1, Eq2(n);
obj.. z0 =E= -x - y;
con.. z1 =L= 4;
Eq1.. sum(n, lambda(n)) =E= 1;
Eq2(n).. x =G= x.LO + (x(t-1) - x.LO)*lambda(n));
MODEL PARTest1 /ALL/;
SOLVE PARTest1 USING MIP MINIMIZING z0;
Please note that this not the complete code. So you will not be able to get anything by running it.
I am struggling with the formulating Eq2. The RHS of this equation has 't-1' as domain of x, which is a constant, as defined in the Parameters. However, modelling this way, generates error because the equation definition 'Eq2(n)' does not includes 't' in its domain. Now, how can I model this?
Re: Formulating Equation of type x_(n-1) Domain
Hi
Why don't you define the equation additonally over t? Furthermore, you use x, x(t-1) and x.lo which surely will cause errors. This should be something like:
I would define a parameter xlow(t) = X.LO(t) and write the equation as follows:
Cheers
Renger
PS. I prefer to write my variables in upper case and parameters in lowercase, so I can read my code without having to check what a variable or parameter is in my equation.
Why don't you define the equation additonally over t? Furthermore, you use x, x(t-1) and x.lo which surely will cause errors. This should be something like:
Code: Select all
Eq2(n,t)$(ord(t) > 1).. x(t) =G= x.LO(t) + (x(t-1) - x.LO(t))*lambda(n));
Code: Select all
Eq2(n,t)$(ord(t) > 1).. x(t) =G= xlow(t) + (x(t-1) - xlow(t))*lambda(n));
Renger
PS. I prefer to write my variables in upper case and parameters in lowercase, so I can read my code without having to check what a variable or parameter is in my equation.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: Formulating Equation of type x_(n-1) Domain
Hi,
Thank you for the answer. Another question, how will you model following attached equation?
Thank you for the answer. Another question, how will you model following attached equation?
- Attachments
-
- image.png (7.05 KiB) Viewed 8913 times