Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to average sum?

    Posted 03/19/09 11:25 PM

    Originally posted by: SystemAdmin


    [Kaji said:]

    I've tried to do a
    maximize
        sum (i in Items) Weight[i] * Item[i] / (sum (i in Items) Item[i])

    and it seems won't stop at all.

    how should I do to correct it?

    Thank you for reading this.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: How to average sum?

    Posted 03/20/09 06:06 PM

    Originally posted by: SystemAdmin


    [jfk said:]

    Hello there,
    I suppose you use OPL looking at the syntax you posted your example in...

    it would be nice to share the knowledge what Weight and Item is... it makes it or breaks it as you will see if your read on further:

    if you believe that your model can be solved by math prog engine (CPLEX) then I have to assume that Item is scalar and Weight is dvar

    int n=5;
    range Items = 1..n;
    dvar int Weight in 1..100;
    float Item = 1.1;
    maximize
        sum (i in Items) Weight * Item / (sum (i in Items) Item);  //<-- original case<br />    //Weight * Item /Item;                                                //<simplified case<br />    //Weight;                                                                  //< further simplified case<br />
    gives the solution:
    // solution (optimal) with objective 100
    Weight = 100;

    well, 1 observations: there is no indexing in Weight*Item and Item
    1. therefore the sum's basically can be omitted and you end up with a Weight*Item/Item (see in the code simplified case).
    2. actually it is just a virtual goal with dvar because Item cancels out "up&down" so you end up with the further simplified case where Weight is just a scalar (see in the code the further simplified case)

    to correct the situation you could write the code:

    int n=5;
    range Items = 1..n;
    dvar int Weight[Items] in 1..10;
    float Item[Items] = [1.1,
                          2.2,
                          2.1,
                          3.1,
                          2.3];
                         
    maximize
        sum (i in Items) Weight[i] * Item[i] / (sum (i in Items) Item[i]);



    However, if my assumption is wrong and Item is dvar (array) and Weight is scalar (array), then you have to realize that the model you composed is not linear! So if you are using the default engine (CPLEX) in OPL then CPLEX can't handle your model (you will get some error saying that the model can't be extracted to CPLEX or something like that). On the other hand if you use CPO then the code may look like this and you can solve it:


    using CP;
    int n=5;
    range Items = 1..n;
    dvar int Item[Items] in 1..10;
    float Weight[Items] = [1.1,
                          2.2,
                          2.1,
                          3.1,
                          2.3];
                         
    maximize
        sum (i in Items) Weight[i] * Item[i] / (sum (i in Items) Item[i]);

    and the solution is:
    // solution with objective 2.76428571428571
    Item = [1 1 1 10 1];


    I hope it helps
    cheers
    #DecisionOptimization
    #MathematicalProgramming-General