Topic
  • 2 replies
  • Latest Post - ‏2013-01-04T09:12:42Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic Writing constraints for subsets of a set.

‏2013-01-03T10:27:33Z |
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?
Updated on 2013-01-04T09:12:42Z at 2013-01-04T09:12:42Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Writing constraints for subsets of a set.

    ‏2013-01-03T16:50:51Z  
    Have you considered using an array of decision variables like
    dvar 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 2014-03-26T05:51:30Z at 2014-03-26T05:51:30Z by iron-man
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Writing constraints for subsets of a set.

    ‏2013-01-04T09:12:42Z  
    Have you considered using an array of decision variables like <pre class="java dw" data-editor-lang="java" data-pbcklang="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" data-editor-lang="java" data-pbcklang="java" dir="ltr">forall (i in 1..4, j in i+1..5) x[i]+x[j]==2; </pre>
    i think i made a mistake while making easy to explain my problem. i think your suggestion might work what i ask :) here is actually what i want:
    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 "1-3-4-2". and also i wanna construct these constraints for each ucitycity variable.

    any idea how can i do this?