[AMPL 16131] Excluding indices from a .run file.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 16131] Excluding indices from a .run file.

Alex Nguyen
Hello,

I am having some trouble with excluding indices when running from a .run file. I am trying to solve a multiperiod optimization by solving each period individually, but there is an issue with indexing.

PROBLEM: Syntax error
GOAL: Solving a set of problems but excluding one constraint from one problem.

I have an inventory constraint that references the inventory from the previous period, seen below:


I have written a separate constraint, MASSIN1, to account for the first period, and a constraint MASSIN2_MASTER for all other periods. These are in a .mod file.

Now, IN A SEPARATE .RUN FILE, I have the problem set up as so:


Where the problem is separated into 5 separate problems (5 periods). The problem is the MASSIN2_MASTER constraint - I receive a syntax error that reads:
syntax error
context:      {t   >>> in <<< TIMEPERIODS: t != 1} MASSIN2_MASTER[t]

I am not sure how to exclude the MASSIN2_MASTER constraint from the first period whilst using the .run file. I've tried {2..5} instead of {t in TIMEPERIODS: t != 1} but that doesn't work as well.

Keep in mind that I want to solve each period individually. In other words:

I want to solve the 1st period ONLY with all constraints ONLY using the 1st period.
Solve the 2nd period ONLY with all constraints ONLY using the 2nd period.
And so on.

Any help is appreciated!

Thanks!

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 16137] Excluding indices from a .run file.

AMPL mailing list
You can use if-then-else and combine MASSIN1 and MASSIN2_MASTER constraint. Below is an example of if-then-else

set TIMEPERIODS := {1,2,3};
var M_A{TIMEPERIODS};

subject to c {t in TIMEPERIODS}: M_A[t] <= if t>1 then 5 else 10;


The example is just to explain you the idea of if-then-else. You need to replace number 5 and 10 by your expression. Moreover, I have replace your equality constraint by <=. We recommend you to replace the equality constraint by either <= or >=.

--
Paras Tiwari
[hidden email]
{#HS:558500267-4898#}
On Tue, Apr 10, 2018 at 5:46 PM UTC, Zeyad Kassem' Via Ampl Modeling Language <[hidden email]> wrote:
Hello,

I am having some trouble with excluding indices when running from a .run file. I am trying to solve a multiperiod optimization by solving each period individually, but there is an issue with indexing.

PROBLEM: Syntax error
GOAL: Solving a set of problems but excluding one constraint from one problem.

I have an inventory constraint that references the inventory from the previous period, seen below:

Figure1.PNG


I have written a separate constraint, MASSIN1, to account for the first period, and a constraint MASSIN2_MASTER for all other periods. These are in a .mod file.

Now, IN A SEPARATE .RUN FILE, I have the problem set up as so:

Figure2.PNG


Where the problem is separated into 5 separate problems (5 periods). The problem is the MASSIN2_MASTER constraint - I receive a syntax error that reads:
syntax error
context: {t >>> in <<< TIMEPERIODS: t != 1} MASSIN2_MASTER[t]

I am not sure how to exclude the MASSIN2_MASTER constraint from the first period whilst using the .run file. I've tried {2..5} instead of {t in TIMEPERIODS: t != 1} but that doesn't work as well.

Keep in mind that I want to solve each period individually. In other words:

I want to solve the 1st period ONLY with all constraints ONLY using the 1st period.
Solve the 2nd period ONLY with all constraints ONLY using the 2nd period.
And so on.

Any help is appreciated!

Thanks!
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 16144] Excluding indices from a .run file.

Alex Nguyen
Works perfectly, thanks! I have a more complex model that I originally used the if-then-else statements but then converted them to the != form. I will have to go back and change them all back to if-then-else (this particular example that I posted was a simplified model, just to test some decomposition methods).

Thanks again for your help!


On Tuesday, 10 April 2018 17:26:09 UTC-4, AMPL Google Group wrote:
You can use if-then-else and combine MASSIN1 and MASSIN2_MASTER constraint. Below is an example of if-then-else

set TIMEPERIODS := {1,2,3};
var M_A{TIMEPERIODS};

subject to c {t in TIMEPERIODS}: M_A[t] <= if t>1 then 5 else 10;


The example is just to explain you the idea of if-then-else. You need to replace number 5 and 10 by your expression. Moreover, I have replace your equality constraint by <=. We recommend you to replace the equality constraint by either <= or >=.

--
Paras Tiwari
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="euBruAbJBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...
{#HS:558500267-4898#}
On Tue, Apr 10, 2018 at 5:46 PM UTC, Zeyad Kassem' Via Ampl Modeling Language <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="euBruAbJBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...> wrote:
Hello,

I am having some trouble with excluding indices when running from a .run file. I am trying to solve a multiperiod optimization by solving each period individually, but there is an issue with indexing.

PROBLEM: Syntax error
GOAL: Solving a set of problems but excluding one constraint from one problem.

I have an inventory constraint that references the inventory from the previous period, seen below:

<a href="https://lh3.googleusercontent.com/-Fcx4fAy0eic/WszpscBEBeI/AAAAAAAAKRQ/b9iChjTnuVIS671w8fBa21PNFHeC7XU7ACLcBGAs/s1600/Figure1.PNG" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-Fcx4fAy0eic/WszpscBEBeI/AAAAAAAAKRQ/b9iChjTnuVIS671w8fBa21PNFHeC7XU7ACLcBGAs/s1600/Figure1.PNG&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-Fcx4fAy0eic/WszpscBEBeI/AAAAAAAAKRQ/b9iChjTnuVIS671w8fBa21PNFHeC7XU7ACLcBGAs/s1600/Figure1.PNG&#39;;return true;">Figure1.PNG


I have written a separate constraint, MASSIN1, to account for the first period, and a constraint MASSIN2_MASTER for all other periods. These are in a .mod file.

Now, IN A SEPARATE .RUN FILE, I have the problem set up as so:

<a href="https://lh3.googleusercontent.com/-6NiYZ-pLl4g/WszpwNtug5I/AAAAAAAAKRU/NgUAXQocVqgH1IdskJENse9CJQ5706CfQCLcBGAs/s1600/Figure2.PNG" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-6NiYZ-pLl4g/WszpwNtug5I/AAAAAAAAKRU/NgUAXQocVqgH1IdskJENse9CJQ5706CfQCLcBGAs/s1600/Figure2.PNG&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-6NiYZ-pLl4g/WszpwNtug5I/AAAAAAAAKRU/NgUAXQocVqgH1IdskJENse9CJQ5706CfQCLcBGAs/s1600/Figure2.PNG&#39;;return true;">Figure2.PNG


Where the problem is separated into 5 separate problems (5 periods). The problem is the MASSIN2_MASTER constraint - I receive a syntax error that reads:
syntax error
context: {t >>> in <<< TIMEPERIODS: t != 1} MASSIN2_MASTER[t]

I am not sure how to exclude the MASSIN2_MASTER constraint from the first period whilst using the .run file. I've tried {2..5} instead of {t in TIMEPERIODS: t != 1} but that doesn't work as well.

Keep in mind that I want to solve each period individually. In other words:

I want to solve the 1st period ONLY with all constraints ONLY using the 1st period.
Solve the 2nd period ONLY with all constraints ONLY using the 2nd period.
And so on.

Any help is appreciated!

Thanks!
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="euBruAbJBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ampl+uns...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="euBruAbJBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@....
Visit this group at <a href="https://groups.google.com/group/ampl" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/ampl&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/ampl&#39;;return true;">https://groups.google.com/group/ampl.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.