Re: dynamic optimization: wagner whitin problem as shortest path problem

822 views
Skip to first unread message

Paul

unread,
Dec 5, 2012, 6:36:15 PM12/5/12
to am...@googlegroups.com
Regarding c, the question to ask yourself is whether the value of c[u,v] depends in any way on other decision variable (x), in which case it should be a variable, or whether c[u,v] is independent of decisions made in the solution, in which case it should be a parameter.

If you decide that c should be a computed parameter, the syntax you want is

let {(u, v) in E : u < v} c[u,v] := ...;

substituting an appropriate formula for the ellipsis (...).

Paul

Paul

unread,
Dec 6, 2012, 6:11:20 PM12/6/12
to am...@googlegroups.com

On Thursday, December 6, 2012 5:39:06 AM UTC-5, Anke wrote:
But as shown in the data set for d is 1 dimensional. How can i tell ampl, that is should calculate d[u,v] as sum of d[v]
For example d[1,5] = d[1] +d[2]+ d[3]+d[4]

You cannot use the same name (d) for both a one-dimensional parameter and a two-dimensional parameter. You could give the cumulative sum a different name. For instance:

param d {V} > 0;
param dsum {u in V, v in V : u < v} := sum {w in V : w >= u and w <= v} d[w];

Paul

Robert Fourer

unread,
Dec 12, 2012, 9:44:06 AM12/12/12
to am...@googlegroups.com

Have you looked at the example of a shortest path model in the AMPL book (www.ampl.com/BOOK/download.html)?  It's in chapter 15, beginning on page 329.

 

If you write

 

   subject to Flusserhaltung {(u,v) in E}: ...

 

then you are defining a separate constraint for each pair (u,v) in the set E.  Thus the indexes u and v are already fixed inside the constraint expression, and it doesn't make sense to write

 

   sum {(u,v) in E} x[u,v]

 

inside the constraint -- that is what gives rise to a "zero-dimensional slice" message.  The example in the book shows how to properly constrain the path to start at a specific node.

 

Bob Fourer

4...@ampl.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of Anke
Sent: Wednesday, December 12, 2012 3:35 AM
To: am...@googlegroups.com
Subject: [AMPL 6382] Re: dynamic optimization: wagner whitin problem as shortest path problem

 

Hey Paul,

 

thanks again. Another question:

How can i tell ampl, that it should minimize the costs: sum{(u,v) in E} c[u,v] * x[u,v]; 

subject to that xuv discribes a way from 1 to T+1

 

Furthermore i have to tell ampl, that a best path (u=1,v) has to be used to cover the demand in the first period!

Could you help me again, and tell me what is wrong in the model:

 

I always get the information, that the subject is a conditional 0 slice!

 

 

Here is my latest try:

 

param T integer;                   
set V:= 1..T;                 
set E:= {u in V, v in V:u<v};

 

param d{v in V}; 

param dsum{u in V, v in V:u<v}:=sum{w in V:w>=u and w<=v} d[w];    

param s;                        
param h;
param c{(u,v) in E}:=  h* dsum[u,v]+ s;  

                

var x{(u,v) in E} binary;    

 

minimize Kosten: sum{(u,v) in E} c[u,v] * x[u,v];  

 

subject to Flusserhaltung{(u,v) in E}: sum{(u,v) in E} x[u,v] - (sum{(v,w) in E} x[v,w]=dsum[u,v]

.

Reply all
Reply to author
Forward
0 new messages