Parameter subscripted by other parameter

40 views
Skip to first unread message

b.g.van...@gmail.com

unread,
Jul 11, 2017, 2:16:18 PM7/11/17
to AMPL Modeling Language
Hi, 

I would like to add a parameter in my model which is subscripted by another parameter. The algebraic notation is as follows:




where:



and the corresponding constraint is the following:

I tried to define b[E(k),i,j] in AMPL in the following way and some other ways:

param b{i in D, p in P, (i,j) in A} = min(d[i,p: p = E[k]],u[i,j]);

But I keep getting a syntax error. 
Any idea how to define this properly in AMPL?
Thanks in advance. 

Robert Fourer

unread,
Jul 12, 2017, 11:04:56 AM7/12/17
to am...@googlegroups.com

The problem here is that the first line defining the "Upper bound" is not mathematically well-formed.  Thus any attempt to transcribe it into AMPL will not work.  Probably you just want to write

   param b {(i,j) in A, p in P} = min (d[i,p], u[i,j]);
   param E {k in K} symbolic in P;

and then your constraint can be x[i,j,k] <= b[i,j,E[k]] * z[i,j,k].

Bob Fourer
am...@googlegroups.com


b.g.van...@gmail.com

unread,
Jul 12, 2017, 12:12:02 PM7/12/17
to AMPL Modeling Language, 4...@ampl.com
Thanks! AMPL does recognize the paramater, however I can't get the constraint to work.

I tried:

s.t. MaxFlow1{k in K, (i,j) in A}:
x[i,j,k] <= b[i,j,E[k]] * z[i,j,k];

and

s.t. MaxFlow1{k in K: E[k] = p, (i,j) in A}:
x[i,j,k] <= b[i,j,E[k]] * z[i,j,k];

and some other ways, but I keep getting a syntax error.



Op woensdag 12 juli 2017 17:04:56 UTC+2 schreef Robert Fourer:

Robert Fourer

unread,
Jul 13, 2017, 9:00:50 AM7/13/17
to am...@googlegroups.com
Your first formulation (but not the second) is syntactically correct; for example there is no error in

set K; set N; set P;
set A within N cross N;

param b {(i,j) in A, p in P};
param E {k in K} symbolic in P;

var x {(i,j) in A, k in K};
var z {(i,j) in A, k in K};

s.t. MaxFlow1{k in K, (i,j) in A}:
x[i,j,k] <= b[i,j,E[k]] * z[i,j,k];

So the error must be due to something that is not right earlier in your model, which in turn causes MaxFlow1 to be in error. To get more help, post the *complete* syntax error message, and also attach your model file.

Bob Fourer
am...@googlegroups.com

=======

b.g.van...@gmail.com

unread,
Jul 13, 2017, 9:34:15 AM7/13/17
to AMPL Modeling Language, 4...@ampl.com
My bad, it wasn't a syntax error. AMPL's output indicates:

#ampl: Error executing "solve" command:
error processing param b['S1','T1',1]:
invalid subscript demand['S1',1]

Op donderdag 13 juli 2017 15:00:50 UTC+2 schreef Robert Fourer:
CMND2(ProductExtension).mod

Robert Fourer

unread,
Jul 16, 2017, 8:55:19 AM7/16/17
to am...@googlegroups.com
First the message "error processing param b['S1','T1',1]" implies that the error is in the definition of b['S1','T1',1], which is

min(demand['S1',1],u['S1','T1'])

Then the message "invalid subscript demand['S1',1]" implies that your indexing of demand does not include demand['S1',1]. You defined demand by

param demand {i in D, p in P} >=0;

so either 'S1' is not in D or 1 is not in P.

BVG

unread,
Jul 25, 2017, 5:11:58 AM7/25/17
to AMPL Modeling Language, 4...@ampl.com
This is indeed the case. 'S1' is not in D. 

I am not sure how to correctly write this algebraically and/or in AMPL. 
My intention is to provide an upper bound of the flow of product p on arc (i,j).

This upper bound can either be the demand[i,p] (demand by customer i for product p) or the arc capacity u[i,j], whichever is the smallest, i.e.:  

param b {(i,j) in A, p in P} = min (d[i,p], u[i,j]);


The constraint would then be:

s.t. MaxFlow1{k in K, (i,j) in A}:
x[i,j,k] <= b[i,j,E[k]] * z[i,j,k];


Concerning the arc capacity, (i,j) is in all nodes. However, for demand i is only in D (a subset of Nodes). 
I tried to write: 

param b {i in D, (i,j) in A, p in P} = min (d[i,p], u[i,j]);


But this doesn't work either..


Robert Fourer

unread,
Jul 26, 2017, 6:38:33 PM7/26/17
to am...@googlegroups.com
Perhaps you are meaning to write:

param b {(i,j) in A, p in P} =
if i in D then min (d[i,p], u[i,j]) else u[i,j];

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of BVG
Sent: Tuesday, July 25, 2017 4:12 AM
To: AMPL Modeling Language
Cc: 4...@ampl.com
Reply all
Reply to author
Forward
0 new messages