Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Sum

    Posted Wed December 28, 2011 03:40 AM

    Originally posted by: Larelian


    Hey,

    I would like to sum over a limited part of the indexes of a parameter/decision variable/...
    How can I do this?

    F.e.:
    String P = {"P1", "P2", "P3", "P4"};
    int D = {1 2 3 4 5 6 7};
    int A = {1 2 3 4 5 6 7};

    float LOS[P][D] = [ 1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 29 20 21
    22 23 24 25 26 27 28 ] ;

    dvar int+ x[P][A];

    Maximize sum(p in P) sum(a in A) x[p][a];

    Subject to
    *sum(p in P) x[p][1] * LOS[p][1] + x[p][5] * LOS[p][4] + x[p][4] * LOS[p][5] + x[p][3] * LOS[p][6] + x[p][2] * LOS[p][7] <= 200;*

    Can I use this expression?
    How can I sum over only f.e. p = "P1" and "P2"?

    Kind regards
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Sum

    Posted Wed December 28, 2011 04:02 AM

    Originally posted by: SystemAdmin


    You can write the first constraint as you suggested if you add parenthesis. Below is a .mod file that should answer your questions.
    
    
    {string
    } P = 
    {
    "P1", 
    "P2", 
    "P3", 
    "P4"
    }; 
    {
    
    int
    } D = 
    {1, 2, 3, 4, 5, 6, 7
    }; 
    {
    
    int
    } A = 
    {1, 2, 3, 4, 5, 6, 7
    };   
    
    float LOS[P][D] = [ [ 1.0,   2.0,  3.0,  4.0,  5.0,  6.0,  7.0 ], [ 8.0,   9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ], [ 15.0, 16.0, 17.0, 18.0, 29.0, 20.0, 21.0 ], [ 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0 ] ] ;   dvar int+ x[P][A];   maximize sum(p in P) sum(a in A) x[p][a];   subject to 
    { 
    // Your first constraint. sum(p in P) (x[p][1] * LOS[p][1] + x[p][5] * LOS[p][4] + x[p][4] * LOS[p][5] + x[p][3] * LOS[p][6] + x[p][2] * LOS[p][7]) <= 200; 
    // Sum only over p=P1 or p=P2 sum(p in P : p == 
    "P1" || p == 
    "P2") sum(a in A) x[p][a] <= 1; 
    }
    

    Not that for questions concerning OPL you best refer to the OPL forum here.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Sum

    Posted Wed December 28, 2011 04:40 AM

    Originally posted by: Larelian


    Thank you very much!
    #DecisionOptimization
    #MathematicalProgramming-General