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
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
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
Thanks very much Bob. It works great!
-Shrini
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
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/
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
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