AMPL Wagner Within Problem, modell is not running. Can some someone help me?

112 views
Skip to first unread message

Bruce Wayne

unread,
Apr 29, 2019, 6:59:18 AM4/29/19
to AMPL Modeling Language
Hello everyone,

im tried to implement the Wagner Within Problem und i was able to learn a lot. I already saw solutions to the problem, way easier than my idea of the implementation. But i want to get it running.

param T;
set V ordered := 1..T+1;
set E within {u in V, v in V: u < v}; #:subset von V #wichtig u < v nicht u < V

param d{t in 1..T}; #param d {t in 1..T}; Nachfragen

param I0;
param s; #Rüstkostensatz
param h; #Lagerkostensatz
param M; #hinreichend große Zahl

#param entry symbolic in V; #Startknoten
#param exit symbolic in V, <> entry;


param EinszuZwei {u in V, v in V: u = 1 and v = 2} := sum {t in 1..T} d[t] - sum {t in 2..T} d[t];
param EinszuDrei {u in V, v in V: u = 1 and v = 3} := sum {t in 1..T} d[t] - sum {t in 3..T} d[t];
param EinszuVier {u in V, v in V: u = 1 and v = 4} := sum {t in 1..T} d[t] - sum {t in 4..T} d[t];
param EinszuFunf {u in V, v in V: u = 1 and v = 5} := sum {t in 1..T} d[t];

param ZweizuDrei {u in V, v in V: u = 2 and v = 3} := sum {t in 2..T} d[t] - sum {t in 3..T} d[t];
param ZweizuVier {u in V, v in V: u = 2 and v = 4} := sum {t in 2..T} d[t] - sum {t in 4..T} d[t];
param ZweizuFunf {u in V, v in V: u = 2 and v = 5} := sum {t in 2..T} d[t];

param DreizuVier {u in V, v in V: u = 3 and v = 4} := sum {t in 3..T} d[t] - sum {t in 4..T} d[t];
param DreizuFunf {u in V, v in V: u = 3 and v = 5} := sum {t in 3..T} d[t];

param VierzuFunf {u in V, v in V: u = 4 and v = 5} := sum {t in 4..T} d[t];


var x{u in V, v in V: u < v} binary;


minimize Kosten: sum{u in V, v in V: u < v} s+ h * (EinszuZwei[1,2] * x[1,2] + EinszuDrei[1,3] * x[1,3] + EinszuVier[1,4] * x[1,4] + EinszuFunf[1,5] * x[1,5] + ZweizuDrei[2,3] * x[2,3] + ZweizuVier[2,4] * x[2,4] + ZweizuFunf[2,5] * x[2,5] + DreizuVier[3,4] * x[3,4] + DreizuFunf[3,5] * x[3,5] + VierzuFunf[4,5] * x[4,5]);


subject to Flusserhaltung {u in V, v in V: u < v}: sum {u in V, v in V: u < v} x[u,v] = sum {v in V, w in V: v < w} x[v,w];

subject to Start: sum{u in V, v in V: u= 1} x[1,v]=1;

subject to Ende: sum{u in V, v in V: v = T+1} x[u,T+1]=1;


It was working, not perfect but i got no error message. Now i tried to impelement the 3 subjects and they are giving me a hard time.
Right now i getting a error message for the subject Flusserhaltung: syntax error.

I tried different ways to approach the problem, maybe someone sees my mistake and can help. Thank you!

AMPL Google Group

unread,
Apr 29, 2019, 11:15:52 PM4/29/19
to Ampl Modeling Language
When you write subject to Flusserhaltung {u in V, v in V: u < v}, then you cannot also use u and v as indexes for your summations in the constraint expression. In particular you are getting a syntax error when you try to sum over {u in V, v in V: u < v}. It seems you may be trying to write

subject to Flusserhaltung {v in V}: sum {u in V: u < v} x[u,v] = sum {w in V: v < w} x[v,w];

Also it greatly complicates the model formulation to name params after different numbers, when you could write a single param definition like this:

param EZDVF {u in V, v in V: u < v} = sum {t in u..T} d[t] - sum {t in v..T} d[t];

(When v equals T+1, the second sum will be over an empty set and hence will be 0.) It appears to me that the sum on the right should further simplify to sum {t in u..v-1} d[t].

--
Robert Fourer
am...@googlegroups.com
{#HS:840103374-42409#}

Bruce Wayne

unread,
May 1, 2019, 9:39:03 AM5/1/19
to AMPL Modeling Language
Thank you, your advice helped me a lot.

Im try to simplfy my model and i get an error i dont understand yet.

i took:

param EinszuZwei {u in V, v in V: u = 1 and v = 2} := sum {t in 1..T} d[t] - sum {t in 2..T} d[t];

and wanted to write it like this:

param EinszuZwei {(u,v) in E: u = 1 and v = 2} := sum {t in 1..T} d[t] - sum {t in 2..T} d[t];

The first one is working, but the second gives me the message: set E is empty.

AMPL Google Group

unread,
May 1, 2019, 9:01:17 PM5/1/19
to Ampl Modeling Language
From the information provided, it is not possible to tell why you are seeing the message "set E is empty". To get more help, reply with your model and data files included as attachments. But in any case, it does not make much sense to write


param EinszuZwei {(u,v) in E: u = 1 and v = 2}
:= sum {t in 1..T} d[t] - sum {t in 2..T} d[t];

because the indexing set can only have one member, and also the indexes u and v defined in the indexing set are not used in the expression after the := sign. You could just as well write

param EinszuZwei := sum {t in 1..T} d[t] - sum {t in 2..T} d[t];

--
Robert Fourer
am...@googlegroups.com
{#HS:840103374-42409#}
On Wed, May 1, 2019 at 1:39 PM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Thank you, your advice helped me a lot.

Im try to simplfy my model and i get an error i dont understand yet.
i took:

param EinszuZwei {u in V, v in V: u = 1 and v = 2} := sum {t in 1..T} d[t]
- sum {t in 2..T} d[t];

and wanted to write it like this:

param EinszuZwei {(u,v) in E: u = 1 and v = 2} := sum {t in 1..T} d[t] -
sum {t in 2..T} d[t];

The first one is working, but the second gives me the message: set E is empty.

Am Dienstag, 30. April 2019 05:15:52 UTC+2 schrieb AMPL Google Group:


On Tue, Apr 30, 2019 at 3:15 AM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
When you write subject to Flusserhaltung {u in V, v in V: u < v}, then you cannot also use u and v as indexes for your summations in the constraint expression. In particular you are getting a syntax error when you try to sum over {u in V, v in V: u < v}. It seems you may be trying to write

subject to Flusserhaltung {v in V}: sum {u in V: u < v} x[u,v] = sum {w in V: v < w} x[v,w];

Also it greatly complicates the model formulation to name params after different numbers, when you could write a single param definition like this:

param EZDVF {u in V, v in V: u < v} = sum {t in u..T} d[t] - sum {t in v..T} d[t];

(When v equals T+1, the second sum will be over an empty set and hence will be 0.) It appears to me that the sum on the right should further simplify to sum {t in u..v-1} d[t].

--
Robert Fourer
am...@googlegroups.com

On Mon, Apr 29, 2019 at 10:59 AM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Hello everyone,

im tried to implement the Wagner Within Problem und i was able to learn a lot. I already saw solutions to the problem, way easier than my idea of the implementation. But i want to get it running.

param T;
 set V ordered := 1..T+1;
set E within {u in V, v in V: u < v}; #:subset von V #wichtig u < v nicht u < V

param d{t in 1..T}; #param d {t in 1..T}; Nachfragen

param I0;
param s; #Rüstkostensatz
param h; #Lagerkostensatz
param M; #hinreichend große Zahl

#param entry symbolic in V; #Startknoten
#param exit symbolic in V, <> entry;


 param EinszuZwei {u in V, v in V: u = 1 and v = 2} := sum {t in 1..T} d[t] - sum {t in 2..T} d[t];

Bruce Wayne

unread,
May 2, 2019, 12:43:26 PM5/2/19
to AMPL Modeling Language
Ah okay, thanks!
Reply all
Reply to author
Forward
0 new messages