Topic
  • 3 replies
  • Latest Post - ‏2013-12-20T10:28:43Z by AlexFleischer
davidoff
davidoff
55 Posts

Pinned topic OPL Script : how to check that an element is contained in a set ?

‏2013-12-20T09:31:34Z |
{int} truc = {1,2,3};
int a= 4;
int inset = a in truc;

 

How to write such code in scripting ?

  • AlexFleischer
    AlexFleischer
    1271 Posts

    Re: OPL Script : how to check that an element is contained in a set ?

    ‏2013-12-20T09:37:34Z  

    Hi,

    {int} truc = {1,2,3};
    int a= 4;
    int b=3;
    int ainset = a in truc;
    int binset = b in truc;

    execute
    {
     writeln(ainset);
     var ainset2=truc.contains(a);
     writeln(ainset2);
     
     writeln(binset);
     var binset2=truc.contains(b);
     writeln(binset2);
    }

     

    gives

    0
    false
    1
    true

     

    regards

     

  • davidoff
    davidoff
    55 Posts

    Re: OPL Script : how to check that an element is contained in a set ?

    ‏2013-12-20T09:44:41Z  

    Thanks.

    Now, if I work with this example

     tuple Truc{
       int first;
       int second;
     }   
     {Truc} trucs = { <t,t+1> | t in truc};
     Truc atruc = <1,3>;
     execute{
       var inset3 = trucs.contains(atruc);
       writeln("inset3=",inset3);
     }
    

    It works fine too.

    Now, I'm wondering how I could build the tuple atruc within the script

  • AlexFleischer
    AlexFleischer
    1271 Posts

    Re: OPL Script : how to check that an element is contained in a set ?

    ‏2013-12-20T10:28:43Z  
    • davidoff
    • ‏2013-12-20T09:44:41Z

    Thanks.

    Now, if I work with this example

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"> tuple Truc{ int first; int second; } {Truc} trucs = { <t,t+1> | t in truc}; Truc atruc = <1,3>; execute{ var inset3 = trucs.contains(atruc); writeln("inset3=",inset3); } </pre>

    It works fine too.

    Now, I'm wondering how I could build the tuple atruc within the script

    tuple Truc{
       int first;
       int second;
     }   
     
     Truc atruc;
     
     execute
     {
      atruc.first=1;
      atruc.second=2;
      writeln(atruc);
     }