Formulating Equation of type x_(n-1) Domain Topic is solved

Problems with modeling
Post Reply
zar
User
User
Posts: 17
Joined: 4 years ago

Formulating Equation of type x_(n-1) Domain

Post by zar »

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
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Formulating Equation of type x_(n-1) Domain

Post by Renger »

Hi

Assuming your variable is x(n), you can use

Code: Select all

x(n) =E=  x_(n-1) * t_(n) + 5;
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

Code: Select all

myeq(n)$(ord(n) > 1)..
x(n) =E=  x_(n-1) * t_(n) + 5;
and fix x(n) wiht X.FX("1") = x0.

I hope this helps
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
zar
User
User
Posts: 17
Joined: 4 years ago

Re: Formulating Equation of type x_(n-1) Domain

Post by zar »

Hi Ranger,
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;
The equation that I want to model is the RHS of following equation:
Image
image.png
image.png (2.9 KiB) Viewed 8975 times
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?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Formulating Equation of type x_(n-1) Domain

Post by Renger »

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:

Code: Select all

Eq2(n,t)$(ord(t) > 1).. x(t) =G= x.LO(t) + (x(t-1) - x.LO(t))*lambda(n));
I would define a parameter xlow(t) = X.LO(t) and write the equation as follows:

Code: Select all

Eq2(n,t)$(ord(t) > 1).. x(t) =G= xlow(t) + (x(t-1) - xlow(t))*lambda(n));
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.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
zar
User
User
Posts: 17
Joined: 4 years ago

Re: Formulating Equation of type x_(n-1) Domain

Post by zar »

Hi,

Thank you for the answer. Another question, how will you model following attached equation?Image
Attachments
image.png
image.png (7.05 KiB) Viewed 8891 times
Post Reply