Decision Optimization

Decision Optimization

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

 View Only
  • 1.  I'm sort of stuck...

    Posted Wed August 20, 2008 07:17 PM

    Originally posted by: SystemAdmin


    [alan_a said:]

    I'm sure this is a really stupid question, but I'm a n00b - both to OR and iLog so please be gentle...

    This is a cost allocation problem.

    I have a 2d constraint array with do not exceed numbers
    [a][c]

    I have a 2d target array that I have to maximize the contents of each cell such that they are as close to the constraint array as possible
    [a][c]

    have a 2d incoming data structure
    [c] {tuple z} where {tuple z} is a varying sized set of index/dollars, arrayed by c.

    I have to allocate each member of z to the target array to maximize each cell subject to the constraints.

    I'm having trouble.

    I'm not sure how to iterate over the set in each [c] to assign it to the [a] in the target. I'm also struggling to understand how I get back from there to see which index went to which cell.

    I realise this is probably obvious to someone who has the first clue, and I'm not looking for someone to do my work for me, but amy pointers would be gratefully received.

    TIA, Alan

    edit: If you are wondering about the odd letter choices, consider the effects of the letters x and b with  [] in bb_code...

    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: I'm sort of stuck...

    Posted Wed August 20, 2008 11:16 PM

    Originally posted by: SystemAdmin


    [prubin said:]

    Several things need clarification, but first and foremost is how you are trying to solve this.  Are you formulating it as a constraint satisfaction problem or an integer program?  That in turn brings us to whether you're using CP Optimizer, Solver or CPLEX to solve it.  Are you using OPL Studio, writing C/C++ or Java code, or what?

    /Paul

    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: I'm sort of stuck...

    Posted Wed August 20, 2008 11:42 PM

    Originally posted by: SystemAdmin


    [alan_a said:]

    Right now I'm trying to formulate the equations in the scripting language in the OPL IDE.

    So far - the way I've structured all my samples - they've used CPLEX to solve the problems, and this is no different.
    Whether that's the correct approach is moot, but it's the one that I've used.



    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: I'm sort of stuck...

    Posted Wed August 27, 2008 06:56 AM

    Originally posted by: SystemAdmin


    [alan_a said:]

    Ok, so I rtfm'd and got all but one of my problems solved by switching to an array instead of a set for the incoming data structure.
    To do the assigns, I needed a seperate array of the form: used[][] in 0..1; to get my assigns - sorta like the knapsack problem.
    It's working pretty well as it stands, it's pretty quick, and the numbers coming out look good.

    Now my only other bugbear is that I have to normalize my arrays to get it to work.

    I have my incoming data as a 2d array. Sadly it has a varying sized second dimension.
    To get my script to work, I am having to blow out all these rows to be the size of the biggest of the second dimensions, so I end up with a lot of padding - which is going to be a real pita to add to the model since for the next test I have 30k values in a [13][varying from 10 - 10000] array before normalizing...

    Is there a fix for that?
    If so can anyone give me a clue as to what it is?
    TIA, Alan

    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: I'm sort of stuck...

    Posted Wed August 27, 2008 08:43 PM

    Originally posted by: SystemAdmin


    [prubin said:]

    I don't use OPL, but CPLEX has no requirement that 2-d variable or parameter arrays be rectangular.  You could for instance define used as IloArray<IloNumVarArray> with 13 rows, then defined used[i] as IloNumVarArray with a different dimension for each i, and similarly for parameters.

    If you have to use rectangular arrays, declare them the largest size you'll need, then declare a 1-d integer array maxc such that maxc[i] is the maximum column index actually used in row i.  Then just index loops across the columns of row i from 0 to maxc[i].

    /Paul

    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: I'm sort of stuck...

    Posted Thu August 28, 2008 05:15 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    Alan,

    In case it helps, here is a small OPL example that illustrates how to use the OPL syntax to do some filtering in a forall statement.



    range a = 1..2;
    range b = 1..3;

    tuple zTuple {
      int b;
      int value;
    };


    int doNotExceed[a][b] = [
                            // inline definition for a = 1
                            [3,5,7],
                            // inline definition for a = 2
                            [2,4,6]];
    {zTuple} z[a] = [
                      // for a = 1
                      {<1, 2>, <3, 6>},
                      // for a = 2
                      {<2, 3>}];

    dvar int targetArray[xa in a][xb in b] in 0..doNotExceed[xa][xb];

    maximize sum(xa in a, xb in b) targetArray[xa][xb];
    constraints {
      forall(xa in a, <xb,c> in z[xa])
          targetArray[xa][xb] == c;
    }



    Didier.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: I'm sort of stuck...

    Posted Thu August 28, 2008 08:13 PM

    Originally posted by: SystemAdmin


    [alan_a said:]

    Didier,

    Thanks for the sample, but I think I'd got the filtering idea.

    My problem is more of this form:

    dexpr float tdm = sum(w in weeks, r in r_units, g in goals, d in a_set)
    units[w][r].dv[d] * caniusethis[g][w][d] * didiusethis[w][r][g];

    Forget everything except "units" in the above statement. Here's the definition for units:

    int n_units = ...;
    range r_units = 1..n_units;

    t_unit units[weeks][r_units] = ...;

    where t_unit is:

    tuple t_unit{
    int index;
    string a_string;
    int some_time;
    float price;
    float dv[a_set...];
    }

    r_units varies from 1 - 20k.
    I don't know enough to figure out how to get it to work without normalizing this dimension to the maximum size of r_units with data that always gives zero sum answers.
    I don't even know if that's possible here!
    I could do it in an HLL, but the script equivalent is eluding me.

    I could cut down the size of this array (and hence the variables and solve time - I hope) significantly if there's a way to do it.
    Either I didn't rtfm enough, or I'm missing something.

    #DecisionOptimization
    #MathematicalProgramming-General


  • 8.  Re: I'm sort of stuck...

    Posted Thu August 28, 2008 10:16 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    Alan,

    If you mean that not all combinations of w,r,g make sense for your didiusethis decision variable ?

    If this is the case, did you consider indexing the didiusethis decision variabe by a tuple set that contains all the valid combinations ?


    Didier.

    #DecisionOptimization
    #MathematicalProgramming-General


  • 9.  Re: I'm sort of stuck...

    Posted Thu August 28, 2008 11:21 PM

    Originally posted by: SystemAdmin


    [alan_a said:]

    No, all combinations of w, r, g make sense.
    The problem is that not all d in g are used. Each g only uses a subset of all the possible d values, all of which are on the units.
    This was an attempt to use a pre-initialized 0/1 array to say which d values were valid for this g.


    #DecisionOptimization
    #MathematicalProgramming-General