defining a set with multiple constraints

686 views
Skip to first unread message

Song Yang

unread,
Mar 7, 2007, 3:36:21 AM3/7/07
to am...@googlegroups.com
Hi, I am trying to define a set with multiple constraints, for example:
 
set FSTATEACTIONS:= {ss in STATES, as in FACTIONS}
 
and I want to impose constraints a_As[i, as] <= min(1, d_Ss[i, ss])*l_Ss[i, ss] } for each i in PRODUCT.
 
The way I wrote is

set FSTATEACTIONS:= {ss in STATES, as in FACTIONS: {i in PROJECT}: a_As[i, as] <= min(1, d_Ss[i, ss])*l_Ss[i, ss]};

But AMPL gives me a syntax error for it. I wonder whether there is a way to do this.

Besides, in AMPL, is there a function that can take the intersection of N (a parameter) sets? Thanks.

 

Best,
Alex

 

 

Shrinivas Sale

unread,
Mar 8, 2007, 4:04:32 PM3/8/07
to am...@googlegroups.com

Hello,

 

I am trying to declare a set based on an if condition as shown below.

 

set LOOPS =

if (numberoflegs >= 4 then (LOOPS1 union LOOPS2 union LOOPS3 union LOOPS4))

else

(LOOPS1 union LOOPS2 union LOOPS3);

 

Where numberoflegs is a parameter. AMPL gives me following error

 

“   line 47 (offset 1959):        syntax error  “

 

How can I make such conditional set declarations. I did not see any specific references to this in the AMPL book. Your input would be extremely helpful.

 

Thanks in advance, Shrini

Robert Fourer

unread,
Mar 8, 2007, 6:10:39 PM3/8/07
to am...@googlegroups.com, Shrinivas Sale

Shrini,

 

The placement of the parentheses is not right.  It should be

 

  set LOOPS = if (numberoflegs >= 4)

     then (LOOPS1 union LOOPS2 union LOOPS3 union LOOPS4)

     else (LOOPS1 union LOOPS2 union LOOPS3);

 

In fact all of the parentheses are unnecessary in this case, though they may help to make the statement more readable.

 

Bob Fourer

4...@ampl.com

 

 


Shrinivas Sale

unread,
Mar 8, 2007, 6:39:13 PM3/8/07
to 4...@ampl.com, am...@googlegroups.com

Thanks very much Bob. It works great!

 

-Shrini

 


Robert Fourer

unread,
Mar 9, 2007, 6:30:18 PM3/9/07
to am...@googlegroups.com, Song Yang

Alex,

 

To impose a condition for all i in PRODUCT, use the forall operator:

 

   set FSTATEACTIONS := {ss in STATES, as in FACTIONS:

     forall {i in PROJECT} a_As[i, as] <= min(1, d_Ss[i, ss])*l_Ss[i, ss]};

 

The inter operator can be indexed to take the intersection of N sets, as long as N is determined from the data and not the variables.  For example,

 

       param N;

       set S {1..N};

       set IS = inter {j in 1..N} S[j];

 

Bob Fourer

4...@ampl.com

 

 


Adela Pagès Bernaus

unread,
Mar 16, 2007, 10:25:42 AM3/16/07
to am...@googlegroups.com
Hi all,

I define a problem using several constraints (which have different names).
For example:

problem hello: var1, var2,
cnt1, cnt2, cnt3,
obj;

I wish to be able to recover the coefficients of the constraints in an
auxiliar matrix/parameter, such as:
param mat{1.._ncons,{var1,var2}};

I need the coefficient matrix because I transform the problem and then it
has vertices with its corresponding convex coefficients and at each
iteration of my algorithm I need to multiply the matrix of coefficients of
the original problem by some selected vertices.

What I'm doing now is:
- for each vertex I give the values to the variables.
- then I assign the full multiplication as _con[k].body.

I did this trick as an emergency but I wish to do a bit better. Any idea?
Thanks a lot!
Adela

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

antti.ruot...@destia.fi

unread,
Mar 16, 2007, 3:53:36 PM3/16/07
to AMPL Modeling Language
Hello,

I think I have a related problem: In a network of i nodes I need to
set a balancing constraint for each node, so that the number of
incoming and outgoing arcs at each node are equal. X and Y are binary
variables for two different actions from node i to node j (or from
node j to node i). In my network, all nodes are not directly connected
(as usual), so I defined a set of (i,j) in ROUTES for those pairs that
a direct connection exists. Thus I need to set a constraint for
optimisation calculated at each node (i), but only for the existing
connections (i,j). Thus I write:

subject to NodeBalance :
forall {i in NODES}
sum {(i,j) in ROUTES} (X[i,j] + Y[i,j]) = sum {(j,i) in ROUTES}
(X[j,i] + Y[j,i]);

but get the following error message:

CPLEX 10.1.0: logical constraint _slogcon[1] is not an indicator
constraint.

Set ROUTES within {NODES, NODES} works fine for other statements /
constraints. Can anyone help me further?

Antti

Robert Fourer

unread,
Mar 18, 2007, 1:38:21 AM3/18/07
to am...@googlegroups.com, Antti Ruotoistenmaki

The current AMPL/CPLEX interface (based on the CPLEX callable library) can't
deal with constraints that apply "forall" to expressions involving
variables. Instead you should write this constraint as

subject to NodeBalance {i in NODES}:


sum {(i,j) in ROUTES} (X[i,j] + Y[i,j]) =
sum {(j,i) in ROUTES} (X[j,i] + Y[j,i]);

Bob Fourer
4...@ampl.com


> -----Original Message-----
> From: am...@googlegroups.com [mailto:am...@googlegroups.com]

antti.ruot...@destia.fi

unread,
Mar 18, 2007, 9:31:00 AM3/18/07
to AMPL Modeling Language
Thank you so much! I thought we had tried this syntax, but obviously
not in exactly in this form. Now the code is working properly.

Antti

Reply all
Reply to author
Forward
0 new messages