Topic
  • 3 replies
  • Latest Post - ‏2013-09-24T12:29:58Z by heidizh
heidizh
heidizh
16 Posts

Pinned topic For Help! Thanks a Lot!!

‏2013-09-15T13:01:55Z |

I have a difficulty in expressing the subtour elimination constraint of the selective traveling salesman problem or the orienteering problem. Please help me, thanks very much !!

In the attachment is the constraint that I need to express using CPLEX. Looking forward to a prompt reply! Thanks !!

Best regards,

Heidi

Updated on 2013-09-15T13:03:18Z at 2013-09-15T13:03:18Z by heidizh
  • AlexFleischer
    AlexFleischer
    1268 Posts
    ACCEPTED ANSWER

    Re: For Help! Thanks a Lot!!

    ‏2013-09-24T12:01:53Z  

    Hi,

     

    suppose you want all the subsets of the set s in the array of sets s2

     

    {string} s={"A","B","C","D"};

     

     

     {string} s2[i in 0..ftoi(pow(2,card(s)))-1]={};

     

    int nb=ftoi(pow(2,card(s)));

     

    execute

    {

     for(var i in s)

     {

      

       for(var j=0;j<=nb-1;j++)

       {

         if ((j >> Opl.ord(s,i)) % 2==1) s2[j].add(i);

       }   

     }

     

     writeln(s2);  

    }  

     

    and then you can iterate in a constraint with

     

    forall(k in 0..ftoi(pow(2,card(s)))-1)

     

    and then use s2[k]

     

    regards

  • AlexFleischer
    AlexFleischer
    1268 Posts

    Re: For Help! Thanks a Lot!!

    ‏2013-09-24T12:01:53Z  

    Hi,

     

    suppose you want all the subsets of the set s in the array of sets s2

     

    {string} s={"A","B","C","D"};

     

     

     {string} s2[i in 0..ftoi(pow(2,card(s)))-1]={};

     

    int nb=ftoi(pow(2,card(s)));

     

    execute

    {

     for(var i in s)

     {

      

       for(var j=0;j<=nb-1;j++)

       {

         if ((j >> Opl.ord(s,i)) % 2==1) s2[j].add(i);

       }   

     }

     

     writeln(s2);  

    }  

     

    and then you can iterate in a constraint with

     

    forall(k in 0..ftoi(pow(2,card(s)))-1)

     

    and then use s2[k]

     

    regards

  • AlexFleischer
    AlexFleischer
    1268 Posts

    Re: For Help! Thanks a Lot!!

    ‏2013-09-24T12:07:55Z  

    Hi,

     

    suppose you want all the subsets of the set s in the array of sets s2

     

    {string} s={"A","B","C","D"};

     

     

     {string} s2[i in 0..ftoi(pow(2,card(s)))-1]={};

     

    int nb=ftoi(pow(2,card(s)));

     

    execute

    {

     for(var i in s)

     {

      

       for(var j=0;j<=nb-1;j++)

       {

         if ((j >> Opl.ord(s,i)) % 2==1) s2[j].add(i);

       }   

     }

     

     writeln(s2);  

    }  

     

    and then you can iterate in a constraint with

     

    forall(k in 0..ftoi(pow(2,card(s)))-1)

     

    and then use s2[k]

     

    regards

    This answered

    https://www.ibm.com/developerworks/community/forums/html/topic?id=4f9f3a1e-2933-47d1-9acb-5c632598f805&ps=25

  • heidizh
    heidizh
    16 Posts

    Re: For Help! Thanks a Lot!!

    ‏2013-09-24T12:29:58Z  

    Hi,

     

    suppose you want all the subsets of the set s in the array of sets s2

     

    {string} s={"A","B","C","D"};

     

     

     {string} s2[i in 0..ftoi(pow(2,card(s)))-1]={};

     

    int nb=ftoi(pow(2,card(s)));

     

    execute

    {

     for(var i in s)

     {

      

       for(var j=0;j<=nb-1;j++)

       {

         if ((j >> Opl.ord(s,i)) % 2==1) s2[j].add(i);

       }   

     }

     

     writeln(s2);  

    }  

     

    and then you can iterate in a constraint with

     

    forall(k in 0..ftoi(pow(2,card(s)))-1)

     

    and then use s2[k]

     

    regards

    Hi, Alex

    Thank you very much. You are always there when I need help. 

    Best regards,

    Heidi