Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Working with tuples

    Posted 06/18/12 04:29 PM

    Originally posted by: Besko


    Dear all,

    I have difficulties to make everything working right.

    Here is the problem introduction:
    I have a set of origin/destination paths, i.e S = (1,2,5,10), (1,2,8), (1,4,6,3,9), (2,8), (3,5,7). It can be noticed that they have different lengths.

    Based on that, I have created a set of tuples with the number of elements as of the longest path (5 in this case):

    tuple Path {
    int a;
    int b;
    int c;
    int d;
    int e;
    }

    {Path} Paths = ...;
    And the .dat contains the data:

    Paths = {<1,2,5,10,0>, <1,2,8,0,0>, <1,4,6,3,9>, <2,8,0,0,0>, <3,5,7,0,0>};
    Furthermore, I have a 0/1 decision variable X.
    Now, I have a problem to define a specific constraint.
    What I want to do is:
    1. to make the subset of nonzero elements for each tuple. i.e for the first tuple: subset = <1,2,5,10>
    2. to do some computation with that subset. i.e X[1] + X[2] + X[5] + X10
    I believe that the code could go something like:

    forall(i in Paths)
    sum(j in Path: "something" ) X[j] >= 1;
    It can be noticed that the "something" is the major issue. :) Please correct me if I am wrong even on this point. The question is how to correctly formulate this constraint?

    Thank you in advance.

    Sincerely,
    Nikola Besinovic
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Working with tuples

    Posted 06/18/12 05:06 PM

    Originally posted by: SystemAdmin


    Hi,

    Would the following approach suit your needs?
    tuple Path {
       {int} p;
     }    
    {Path} Paths = {<{1,2,5,10}>, <{1,2,8}>, <{1,4,6,3,9}>, <{2,8}>, <{3,5,7}>};
    dvar boolean X[Paths][1..10];
    constraints {
      forall (path in Paths) 
        sum (j in path.p) X[path][j] >=1; 
    }
    


    Depending on the rest of your model, you may not need to create the set of tuples.
    What kind of filtering do you want to do ("something" part in your message)?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer