Topic
  • 4 replies
  • Latest Post - ‏2012-12-31T15:03:50Z by GGR
qtbgo
qtbgo
116 Posts

Pinned topic array element as set?

‏2012-12-20T09:32:33Z |
Hi, I want to define an array a i, the element of the array is set type. So that I can implement a constraint like:

x ik != 1 forall i,k: k in a i

It seems that OPL doesn't support this. Can you help me achieve my purpose?
Updated on 2012-12-31T15:03:50Z at 2012-12-31T15:03:50Z by GGR
  • SystemAdmin
    SystemAdmin
    623 Posts

    Re: array element as set?

    ‏2012-12-20T09:58:46Z  
    Hello,
    I think it works in OPL:

    
    
    
    int n=10; 
    {
    
    int
    } A[i in 1..n] = 
    { k | k in 1..i 
    };   dvar 
    
    int x[i in 1..n][j in 1..n] in 0..1;   constraints 
    { forall(i in 1..n, k in A[i]) 
    { x[i][k] != 0; 
    } 
    }
    


    Is it something like that you want to do ?
    Philippe
  • qtbgo
    qtbgo
    116 Posts

    Re: array element as set?

    ‏2012-12-20T10:28:22Z  
    Hello,
    I think it works in OPL:

    <pre class="jive-pre"> int n=10; { int } A[i in 1..n] = { k | k in 1..i }; dvar int x[i in 1..n][j in 1..n] in 0..1; constraints { forall(i in 1..n, k in A[i]) { x[i][k] != 0; } } </pre>

    Is it something like that you want to do ?
    Philippe
    thank you very much. it works.

    I want to initialize A in .dat file, and the values doesn't depend on i, Could you give correct format to initialize A in dat file? thanks.

    in mod:
    
    
    {
    
    int
    } A[i in 1..2] = ...;
    


    in dat:

    A = ?;
  • SystemAdmin
    SystemAdmin
    623 Posts

    Re: array element as set?

    ‏2012-12-20T10:40:52Z  
    • qtbgo
    • ‏2012-12-20T10:28:22Z
    thank you very much. it works.

    I want to initialize A in .dat file, and the values doesn't depend on i, Could you give correct format to initialize A in dat file? thanks.

    in mod:
    <pre class="jive-pre"> { int } A[i in 1..2] = ...; </pre>

    in dat:

    A = ?;
    
    A = [ 
    { 1 
    } 
    {1 2 
    } ];
    
  • GGR
    GGR
    70 Posts

    Re: array element as set?

    ‏2012-12-31T15:03:50Z  
    Hi gtbgo

    You must declare a tuple class <i, k> and then defines a tuple set of <i, k> that gives the valid k associated with an i.

    Hope that helps