Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
4 replies Latest Post - ‏2012-12-31T15:03:50Z by GGR
qtbgo
qtbgo
116 Posts
ACCEPTED ANSWER

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
    ACCEPTED ANSWER

    Re: array element as set?

    ‏2012-12-20T09:58:46Z  in response to qtbgo
    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
      ACCEPTED ANSWER

      Re: array element as set?

      ‏2012-12-20T10:28:22Z  in response to SystemAdmin
      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
        ACCEPTED ANSWER

        Re: array element as set?

        ‏2012-12-20T10:40:52Z  in response to qtbgo
        
        A = [ 
        { 1 
        } 
        {1 2 
        } ];
        
  • GGR
    GGR
    68 Posts
    ACCEPTED ANSWER

    Re: array element as set?

    ‏2012-12-31T15:03:50Z  in response to qtbgo
    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