Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Optimization Problem: Problem with the second decision variable

  • 1.  Optimization Problem: Problem with the second decision variable

    Posted Fri February 19, 2016 05:26 PM

    Originally posted by: Thomas_321


    Hello,

    I do have a problem with the second decision variable of my model. I also asked the question in the "CPLEX Optimizers" Forum but they suggested to ask here. I hope you guys can help. (https://www.ibm.com/developerworks/community/forums/html/topic?id=e5026e71-abf5-42ce-86d9-f56946dc58ea&ps=25#repliesPg=0)

     

    The optimization problem:

    I have Product Categories (lets start with 2) containing Products. Each Product can be bought from One of the Two Suppliers therefore I have Two Prices for each product. I want to minimize my total costs taking into account the two constraints:

    1.  60% of the total cost has to be purchased from supplier 1.
    2.  60% of the total cost of one product category has to be purchased from supplier 1. 

    My Code:

     // Sets
    {string} A = ...;     // Product categories
    {string} B = ...;     // Products
     
    // Parameters
    float c1[B] = ...;    // Product price supplier 1
    float c2[B] = ...;    // Product price supplier 2
    float rate = ...;     // Percentage rate purchased from supplier 1
    float m = 10000;      // Big number

    // Decision variables 
    dvar boolean x[B];    
    dvar boolean y[A];
     
    // decision expression 
    dexpr float test = sum (b in B)(c1[b]*x[b]+(1-x[b])*c2[b]);    // Minimizing total cost
     
    // objective funtion  
    minimize test;
     
    // Constraints
    subject to{

      sum (b in B)c1[b]*x[b] >= rate * sum(b in B)(c1[b]*x[b]+(1-x[b])*c2[b]);   // Percentage of total cost purchased from S1

          forall (a in A)
             sum (b in B) sum (b in B)c1[b]*x[b] >= rate * sum(b in B)(c1[b]*x[b]+(1-x[b])*c2[b])-(1-y[a])*m; // Percentage of total cost of a product category purchased from S1
     
          sum (a in A) y[a] >=1; // Number of product categories which need to reach the percentage rate 
     }
     

    The Problem is the following:

    The decision variable y[a] should turn 1 if the 60% of the total cost of a product category is purchased from S1 (supplier1) but it doesn´t

    As seen below the buying rate for product category A is 38% but y[a] ==1 although the buying rate for product category B is 96% and y[a]==0.

     

    I attached my model and the data.

     

    Thank you, I appreciate the help! 

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Optimization Problem: Problem with the second decision variable

    Posted Sat February 20, 2016 04:02 PM

    Originally posted by: Thomas_321


    Hello,

    Is it possible that the problem might be a missing connection between the product categories and the products? 

    Is there a possibility to assign the products to a certain product category? 

    I tried to solve this problem with tuples but I´m stuck at the same point.

    Code.

    // Sets
    {string} Category = ...;     // Categories
    {string} Product = ...;     // Products
     
    // Parameters
    tuple ProductCost{     //Cost of products
    string pc;            // Product Category
    float p1;            // Price 1
    float p2;             // Price 2
    }
    ProductCost c[Product] = ...; 
    float rate = ...;   // Buying rate of supplier 1
    float m = 10000;    // Big number
    // Decision variables 
    dvar boolean x[Product];
    dvar boolean y[Category];
     
    // objective funtion  
    minimize sum (b in Product)(x[b]*c[b].p1+(1-x[b])*c[b].p2);
     
    // Constraints
    subject to{   
         sum (b in Product)(x[b]*c[b].p1)>= rate * sum(b in Product)(x[b]*c[b].p1+(1-x[b])*c[b].p2);
     
     forall (a in Category)
         sum (b in Product)(x[b]*c[b].p1)>= rate * sum(b in Product)(x[b]*c[b].p1+(1-x[b])*c[b].p2)-(1-y[a])*m;
     }
    

    Thanks for your help


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Optimization Problem: Problem with the second decision variable

    Posted Mon February 22, 2016 08:24 AM

    Originally posted by: Thomas_321


    Hey,

    so I hope this goes in the right direction, for "productCost c" I get  [<"A", 10 11>]... witch is a good start but how can I calculate the buying rate for each product category?

    In other words that for "A" and "B" the buying rate is calculated and if so, y = 1?

    Does anyone have an idea?

     

    Thank you for your help, best regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Optimization Problem: Problem with the second decision variable

    Posted Tue February 23, 2016 03:10 AM

    Hi,

    do you know that you are allowed to write logical constraints like:

    (x[1]<=6) => (y[1]==1) // imply

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Optimization Problem: Problem with the second decision variable

    Posted Tue February 23, 2016 02:15 PM

    Originally posted by: Thomas_321


    Hey Alex, 

    thanks for your answer, but sorry I don´t understand where it would be implemented in my model?

    I adjusted my model now and I´m also able to get the data from excel but the main problem still remains the same. y[a] still turns 1 when it shouldn´t. 

    Yet I still think that the problem is rooted in the missing link between product categories and the rest of the constraint, so y still doesn´t  turn 1 because the buying rate within a product category has reached the given rate.

    I really have no clue what else to do or where the problem is. 

     

    I´d really appreciate your help

    Thank you and best regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Optimization Problem: Problem with the second decision variable

    Posted Thu February 25, 2016 05:41 AM

    Hi

    in order to get rid of errors you should replace

    forall (a in Category)
        Ct2[a]:
        sum (f in P) (c[f.pc].Ppc1*x[f.pc]) >= rate * sum(f in P)(c[f.pc].Ppc1*x[f.pc] + (1-x[f.pc])*c[f.pc].Ppc2)-m*(1-y[a]);

    by

     

    forall (a in Category)
        Ct2[a]:
        sum (f in P) (c[f.product].Ppc1*x[f.product]) >= rate * sum(f in P)(c[f.product].Ppc1*x[f.product] + (1-x[f.product])*c[f.product].Ppc2)-m*(1-y[a]);

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Optimization Problem: Problem with the second decision variable

    Posted Thu February 25, 2016 01:33 PM

    Originally posted by: Thomas_321


    Hey Alex,

     

    Thank you for your answer, I actually did that before and it helped with the error messages yet the main problem remains the same. The second decision variable still is not related to the rest and therefore doesn´t switch from 0 to 1 when the Product Category reaches the BR. 

    I changed c[f.product].Ppc1 to c[f.pc].Ppc1 because pc is the product category and I thought that would create the connection, obviously it doesn´t work.

    Do you have an idea how to achieve that y(a) turns 1 when the BR within one product category is reached?

    I attached the model 

     

    Thanks a lot and best regards! 

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Optimization Problem: Problem with the second decision variable

    Posted Thu February 25, 2016 08:51 AM

    Originally posted by: K3P9_SAURABH_PRATAP


    I have doubt

    please clarify it

    dvar boolean x[B];   

    is it binary decision variable?

    I would like to ask, how can I define binary decision variables.

    x[B]= 1 If its is positive

          = 0 otherwise

     

     

    ?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Optimization Problem: Problem with the second decision variable

    Posted Thu February 25, 2016 08:57 AM

    Hi

    dvar int x[1..2];

    subject to
    {
    forall(i in 1..2) (x[i]>=1) => (x[i]==1);
    forall(i in 1..2) (x[i]<=-0) => (x[i]==0);
    x[1]!=x[2];
    }

    gives

    [0 1]

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Optimization Problem: Problem with the second decision variable

    Posted Thu March 03, 2016 08:11 AM

    Originally posted by: Stanko_86


    Hi Thomas,

    I modified your Ct2[a] constraint as follows:

    forall (a in Category)
    {
        Ct2[a]:
        
        (sum (<pr, a, price1, price2> in P) (price1*x[pr]) >= rate*(sum (<pr, a, price1, price2> in P)(price1*x[pr] + price2*(1-x[pr])))) => (y[a] == 1);
        (sum (<pr, a, price1, price2> in P) (price1*x[pr]) <= rate*(sum (<pr, a, price1, price2> in P)(price1*x[pr] + price2*(1-x[pr])))) => (y[a] == 0);  
    }

     

    Now, the constraint :  sum (a in Category)  y[a] >=1;    is unnecessarily.

    I got results given in the table below:

     

    Actual BR

     

    Rate achieved?

    A

    38%

    0

    B

    60%

    1

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Optimization Problem: Problem with the second decision variable

    Posted Thu March 03, 2016 01:21 PM

    Originally posted by: Thomas_321


    Thanks a lot for the help guys!!!

    I managed to solve the problem.

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer