for a variable x[i,j] setting i not equal j

1,201 views
Skip to first unread message

Nathan Wang

unread,
Nov 24, 2014, 5:17:17 AM11/24/14
to am...@googlegroups.com
Hi, I am currently running into some problems with my model. I have two variables indexed over sets I and J that I need to solve for, however due to the nature of the problem and the model, within a given variable, i cannot equal j, for example, x[1,1] or x[4,4] it not possible. The problem is I really have no idea how to write a constraint like that in AMPL and when I try to run the model without the constraint there are logical errors. Any help at all would be greatly appreciated. Thanks!

Robert Fourer

unread,
Nov 24, 2014, 9:51:59 PM11/24/14
to am...@googlegroups.com
You can write, for example,

var x {i in I, j in J: i <> j} >= 0;

to specify that only x[i,j] with i <> j should be defined. Then in your model you must not refer to variables like x[1,1] or x[4,4]. If you have a linear model, then alternatively you can index x over {i in I, j in J} and then add a constraint to zero out the variables that should not be used:

subj to Noii {i in I}: x[i,i] = 0;

Then AMPL's presolve phase will remove these variables from the problem before it is sent to the solver.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages