Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

multidimensional array initialization

  • 1.  multidimensional array initialization

    Posted Wed July 02, 2008 11:41 PM

    Originally posted by: SystemAdmin


    [topbull said:]

    Is it possible to initialize a multidimensional array separately? For example, if define an array a[1..2][1..2], can I initialize this array like
    a[1] = [1 2]
    a[2] = [3 4]
    ?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: multidimensional array initialization

    Posted Fri July 04, 2008 02:30 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    You have all the flexibility you want if you do the initialization with javascript statements, as in the following example


    int a[1..2][1..2];

    execute {
      a[1][1] = 1;
      a[1][2] = 2;
      a[2][1] = 3;
      a[2][2] = 4;
    }



    However, the constraint in this case is that the second dimension has the same indexer in all cases (your array must really be a matrix).

    If you want to model structures that are more complex than a matrix, the best way is to use tuplesets.  On the whitepaper page of OPL ([url=http://www.ilog.com/products/oplstudio/whitepapers/index.cfm]http://www.ilog.com/products/oplstudio/whitepapers/index.cfm[/url] ) you have an interesting whitepaper called  "Efficient Modeling in ILOG OPL-CPLEX Development System" that details the use of tuplesets.

    Didier Vidal
    #DecisionOptimization
    #OPLusingCPLEXOptimizer