How to combine 2 models

74 views
Skip to first unread message

heartswiki

unread,
Dec 5, 2021, 9:36:40 AM12/5/21
to AMPL Modeling Language
Hello! I hope you could help me with this.

I have this model (cassava_extended.mod) and in this model, I want the data of param Cassava_Amount to rely on the sum of decision variable X in the cassava.mod

Basically it's like combining these two mods. Is it possible? If yes, how?


cassava_extended.mod
cassava.mod

AMPL Google Group

unread,
Dec 6, 2021, 8:17:12 PM12/6/21
to AMPL Modeling Language
It is possible to combine two models; in fact, there is a feature called "named problems" (AMPL book sections 14.4-14.5) that is designed for this purpose. However, in your description of what you want to do, it is not clear how the data of param Cassava_Amount should "rely" on the sum of decision variable X. This is one possibility:
  • Solve cassava.mod for the optimal values of the variables X[i,j].
  • Using the optimal values, set param Cassava_Amount[i] equal to sum {j in J} X[i,j].
  • Solve cassava_extended.mod for the optimal values of the variables Y[j].
Here the first solve has only X[i,j] as the variables, while the second solve has only Y[j] as the variables. If this is what you want, I can suggest a good way to do it. But if you want something else, how would it be different from this?


--
Robert Fourer
am...@googlegroups.com
{#HS:1717437868-107488#}
Message has been deleted

heartswiki

unread,
Dec 7, 2021, 9:43:58 AM12/7/21
to AMPL Modeling Language
Thank you so much! After analyzing the model, I figured out a way to adjust it my way but I have one last problem.

When I run the new code, I get the following error:

ampl: reset;
ampl: model cassava_ext.mod;

cassava_ext.mod, line 41 (offset 2044):
i is undefined
context:  s.t. Store_Demand {j in J, s in S}: sum {i in I} Y[i,j,s] >=  >>> Min_Demand[i,s] <<< ;
ampl: 

I believe it is pertaining to the following constraint:
s.t. Store_Demand {j in J, s in S}: sum {i in I} Y[i,j,s] >= Min_Demand[i,s];


Is there something that I am missing or forgot to code?


cassava_ext.dat
cassava_ext.mod

AMPL Google Group

unread,
Dec 7, 2021, 12:56:16 PM12/7/21
to AMPL Modeling Language
The index i is only defined within the expression "sum {i in I} Y[i,j,s]" on the left side of the >= operator. It is not defined on the right side of the >= operator, which is why you get an "i is undefined" message for >>> Min_Demand[i,s] <<<.

Probably you have the indexing mixed up. Should there be a Store_Demand constraint for each {i in I, s in S}?


--
Robert Fourer
am...@googlegroups.com
{#HS:1717437868-107488#}
On Tue, Dec 7, 2021 at 2:44 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you so much! After analyzing the model, I figured out a way to adjust it my way but I have one last problem.

When I run the new code, I get the following error:

ampl: reset;
ampl: model cassava_ext.mod;

cassava_ext.mod, line 41 (offset 2044):
i is undefined
context: s.t. Store_Demand {j in J, s in S}: sum {i in I} Y[i,j,s] >= >>> Min_Demand[i,s] <<< ;
ampl:

I believe it is pertaining to the following constraint:
s.t. Store_Demand {j in J, s in S}: sum {i in I} Y[i,j,s] >= Min_Demand[i,s];

Is there something that I am missing or forgot to code?

On Tue, Dec 7, 2021 at 2:12 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
The first and second bullets is what I actually want. Thank you so much! But how and where would I set param Cassava_Amount equal to sum {j in J} X[i,j]?

On Mon, Dec 6, 2021 at 8:59 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
It is possible to combine two models; in fact, there is a feature called "named problems" (AMPL book sections 14.4-14.5) that is designed for this purpose. However, in your description of what you want to do, it is not clear how the data of param Cassava_Amount should "rely" on the sum of decision variable X. This is one possibility:
  • Solve cassava.mod for the optimal values of the variables X[i,j].
  • Using the optimal values, set param Cassava_Amount[i] equal to sum {j in J} X[i,j].
  • Solve cassava_extended.mod for the optimal values of the variables Y[j].
Here the first solve has only X[i,j] as the variables, while the second solve has only Y[j] as the variables. If this is what you want, I can suggest a good way to do it. But if you want something else, how would it be different from this?


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages