there is a set "1,2,3,4,5". i wanna write constraints for subsets of this set. for example
x1=1,
x2=1,
x3=1,
x4=1,
x5=1,
x1+x2=2,
x1+x3=2,
x1+x4=2,
x1+x5=2,
x2+x3=2,
x2+x4=2,
x2+x5=2,
x3+x4=2,
x3+x5=2,
x4+x5=2,
x1+x2+x3=3,
x1+x2+x4=3,
x1+x2+x5=3,
x1+x3+x4=3,
x1+x3+x5=3,
x1+x4+x5=3,
x2+x3+x4=3,
x2+x3+x5=3,
x2+x4+x5=3,
.
.
.go on
how can i write these constraints (in closed format) by using subsets of this set?
Topic

Re: Writing constraints for subsets of a set.
20130103T16:50:51ZThis is the accepted answer. This is the accepted answer.Have you considered using an array of decision variables likedvar int X[your_range];
and then when you post your constraints you filter the indices as show below?
forall (i in 1..4, j in i+1..5) x[i]+x[j]==2;
Updated on 20140326T05:51:30Z at 20140326T05:51:30Z by ironman 
Re: Writing constraints for subsets of a set.
20130104T09:12:42ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20130103T16:50:51Z
Have you considered using an array of decision variables like <pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">dvar int X[your_range]; </pre> and then when you post your constraints you filter the indices as show below?
<pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">forall (i in 1..4, j in i+1..5) x[i]+x[j]==2; </pre>
this problem is a type of a vehicle routing problem. city 1 is depot.
range city=(1..5);
dvar int xcitycity in 0..1; // if vehicle traverse from city i to city j equal to 1 otherwise 0
dvar int+ ucitycity; // total demanded product from city i to city j
these are the subset constraints which i couldn't write in closed format.
(u[1][2]!=0) => x[1][2]==1
x[1][3]+x[3][2]==2
x[1][4]+x[4][2]==2
x[1][5]+x[5][2]==2
x[1][3]+x[3][4]+x[4][2]==3
x[1][3]+x[3][5]+x[5][2]==3
x[1][4]+x[4][3]+x[3][2]==3
x[1][4]+x[4][5]+x[5][2]==3
x[1][5]+x[5][3]+x[3][2]==3
x[1][5]+x[5][4]+x[4][2]==3
x[1][3]+x[3][4]+x[4][5]+x[5][2]==4
x[1][3]+x[3][5]+x[5][4]+x[4][2]==4
x[1][4]+x[4][3]+x[3][5]+x[5][2]==4
x[1][4]+x[4][5]+x[5][3]+x[3][2]==4
x[1][5]+x[5][3]+x[3][4]+x[4][2]==4
x[1][5]+x[5][4]+x[4][3]+x[3][2]==4;
these constraints ensures that if there some product from city 1 to city 2 then a vehicle deliver this product directly by traversing 1 to 2; or traversing some intermediate cities between 1 and 2 like "1342". and also i wanna construct these constraints for each ucitycity variable.
any idea how can i do this?