Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Issue in constraints

    Posted 10/30/20 05:16 AM
    Hi

    I have a model in which profit should come 692.83 but I am getting 0. I am facing following issues in this model:

    1) If I am initialising S[1,1] == 310 in the model as constraint then only model is working and it is able to find the optimal solutions and decision variables are also working fine but without providing any initial solution as constraint, I am getting profit = 0 

    2) If Constraint 3 is formulated as Constraint 4 then also model is not working otherwise it is giving wrong solutions. However, Constraint 3 and Constraint 4 are conceptually same. I am curious to know which is correct approach for formulation.

    3) If I have defined my decision variables as dvar+ still if I am not giving profit >= 0 as a constraint in the model then I am getting profit as negative. Ideally, profit >= 0 should not  come in constraint because it is an objective function.

    I am attaching my .opl and .dat file. Please help me to resolve these issues

    ////.opl file

    // Declaration of Data 

    int np = ...;

    float B = ...;

    int rawmaterial = ...;

    range raw = 1..rawmaterial;

    int R[raw] = ...;

    range process = 1 .. np;

    float l[process] = ...;

    float m[process] = ...;

    float h[process] = ...;

    float il[process] = ...;

    float im[process] = ...;

    float ih[process] = ...;

    float cl[process] = ...;

    float cm[process] = ...;

    float ch[process] = ...;

    float raw_material [process][raw] = ...;
    int productnumber = ...;

    range PRODUCT = 1..productnumber;

    {int} PRO[PRODUCT] = ...;

    range ORDER = 1..4;

    float saleprice[PRODUCT]= ...;

    float Demand[PRODUCT][ORDER]=...;

    int nbNNZdemand[o in ORDER]=sum(r in PRODUCT) (Demand[r,o]!=0);

    float EP[t in PRODUCT]=max(p in PRO[t]) (h[p]);

    // Declaration of Decision Variables

    dvar float+ S[t in PRODUCT,o in ORDER];

    dvar float+ Sale[o in ORDER];

    dvar boolean Y[t in PRODUCT,o in ORDER];

    dvar boolean Y1[t in PRODUCT,o in ORDER];

    dvar boolean V[process];

    dvar boolean Z[process];

    dvar float+ X[p in process] in 0..h[p];

    dvar float+ L[j in process] in 0..1;

    dvar float+ M[j in process] in 0..1;

    dvar float+ H[j in process] in 0..1;

    dexpr float each_product[i in PRODUCT] = sum(j in PRO[i])X[j];

    dexpr float raw_Constrant[t in raw] = sum(j in process)raw_material[j][t]*X[j];

    dexpr float invst_Constrant = sum(j in process)(il[j]*L[j]+im[j]*M[j]+ih[j]*H[j]);

    dexpr float PC =  sum(j in process)(cl[j]*L[j]+cm[j]*M[j]+ch[j]*H[j]);

    dexpr float profit = sum(o in ORDER) (Sale[o])- sum(j in process)(cl[j]*L[j]+cm[j]*M[j]+ch[j]*H[j]);

    maximize profit;

    subject to {

    forall (j in process){  

    X[j] == l[j]*L[j] + m[j]*M[j] + h[j]*H[j];    

    L[j]<= V[j];

    H[j]<=1-V[j];

    L[j] + M[j] + H[j] == Z[j];

    X[j] <= 100000*Z[j];

    }

         

    forall (t in raw){

    raw_Constrant[t] <= R[t];

    } 

    invst_Constrant <= B;

    // Unique process constraint                                          

    forall(I in PRODUCT){

    sum(j in PRO[I]) Z[j] <= 1;

    } 

    forall(t in PRODUCT){

    sum(s in PRO[t])X[s] >= sum(o in ORDER)S[t,o];

    }

    //S[1,1]==310;

    //Demand Constraints                        

    forall(o in ORDER,t in PRODUCT:Demand[t][o]>0){

    S[t][o]>= Demand[t][o]=> Y[t][o]==1;

    S[t][o]<= Demand[t][o]-0.0001 => Y[t][o]==0 ;

    }


    // Constraint 3

    forall(o in ORDER,t in PRODUCT:Demand[t][o]==0){

    Y[t][o]==0;

    }


    // Constraint 4

    // forall(o in ORDER,t in PRODUCT:){

    // Demand[t][o]==0 => Y[t][o]==0;

    // }


                         

    forall(o in ORDER){

     sum(t in PRODUCT)Y[t,o] == nbNNZdemand[o] => Sale[o]==sum(t in PRODUCT) (saleprice[t]*S[t,o]);

    }

    profit >= 0;

              

    }

    // Display 

    execute{

    for(var p in process)

    if(X[p]>0)

    writeln(p,'-',X[p]);

    }



    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    .dat
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    np = 54;

    productnumber = 24;

    rawmaterial = 2;

    B = 1000;

    R = [500,500]; 

       

    SheetConnection CAPACITY("capacity.xlsx");

    l from SheetRead(CAPACITY,"sheet1!A1:A54"); 

    m from SheetRead(CAPACITY,"sheet1!B1:B54");

    h from SheetRead(CAPACITY,"sheet1!C1:C54"); 

    SheetConnection RAW("consumeraw.xlsx");

     raw_material from SheetRead(RAW,"sheet1!A1:B54");  
           

    SheetConnection INVST("investment.xlsx");

    il from SheetRead(INVST,"sheet1!A1:A54");

    im from SheetRead(INVST,"sheet1!B1:B54");

    ih from SheetRead(INVST,"sheet1!C1:C54"); 

    SheetConnection PROD("production.xlsx");

    cl from SheetRead(PROD,"sheet1!A1:A54");

    cm from SheetRead(PROD,"sheet1!B1:B54");

    ch from SheetRead(PROD,"sheet1!C1:C54");

    PRO = [{ 1  2 3 } { 4 5 } { 6 7 } { 8 } { 9 } { 10 11 12 13 14 15} { 16 17 } { 18 } { 19 20 } { 21 22} { 23 24 25} { 26} { 27} { 28 29 30} { 31 32 33} { 34} { 35 36 37} { 38 39 40} { 41 42} { 43 44 45} { 46 47 48 49} { 50 51} { 52 } { 53 54}];


    SheetConnection oF("DemandFile.xlsx");

    Demand from SheetRead(oF,"sheet1!B2:E25");

    saleprice from SheetRead(oF,"sheet1!F2:F25");

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    I am attaching all the files

    ------------------------------
    sandeep singh chauhan
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Issue in constraints

    Posted 10/30/20 12:39 PM
    Hi,

    can you add

    execute
    {
    cplex.preind=0;
    }

    in the beginning of your model and tell me whether you still have the same issue ?

    regards

    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 3.  RE: Issue in constraints

    Posted 10/31/20 03:01 AM
    Hi

    Thanks for the reply. After incorporating the suggested command, I am not getting the global solution it is giving 691.4 but it should get 692.8 (optimal solution). Alex, I have  attached all the required files related to this model please have a look in it and let me know if anything else is required. It would be a great help if you help me to resolve all three mentioned questions related to this model.

    Thank you
    Sandeep

    ------------------------------
    sandeep singh chauhan
    ------------------------------



  • 4.  RE: Issue in constraints

    Posted 10/31/20 05:14 AM
    Edited by System Admin 01/20/23 04:15 PM
    Hi,

    if I add

    profit<=10000;

    then I get profit 10000

    Are you sure your model is not unbounded ?

    If you add

    Sale[1]==0;

    which seems to be a major cause for concern then you ll get

    profit 692,834

    regards

    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 5.  RE: Issue in constraints

    Posted 11/01/20 02:35 AM
    Edited by System Admin 01/20/23 04:30 PM
    Hi

    Thanks for your reply. If I am using cplex.preind = 0 and commenting constraint 3 and using constraint 4 then I am getting optimal solution 692.83 but the optimal solutions are not correct because I am giving demand for product 1 and order 1 as 310 (you can see it from data) but in optimal solution S for product 1 and order 1 is 0 but it should come as 310. In addition, if I change R = [1000,1000] in data then my profit should come 759.7366 but using the above suggested approach I am getting 705.73. Please suggest your valuable suggestions for correct these bugs.

    One more thing I want to add, if demand is zero then Y is zero and if S>=Demand then only Y=1.

    Thank you

    ------------------------------
    sandeep singh chauhan
    ------------------------------



  • 6.  RE: Issue in constraints

    Posted 11/02/20 01:34 AM
    Hi

    commenting constraint 3 and with constraint 4

    // Constraint 3

    //forall(o in ORDER,t in PRODUCT:Demand[t][o]==0){
    //
    //Y[t][o]==0;
    //
    //}


    // Constraint 4

    forall(o in ORDER,t in PRODUCT){

    Demand[t][o]==0 => Y[t][o]==0;

    }

    I get objective 692.834

    for the demand constraint you can change

    //Demand Constraints

    forall(o in ORDER,t in PRODUCT:Demand[t][o]>0){

    S[t][o]>= Demand[t][o]=> Y[t][o]==1;

    (S[t][o]<= Demand[t][o]-0.0001) => (Y[t][o]==0) ;

    }

    into

    //Demand Constraints

    forall(o in ORDER,t in PRODUCT:Demand[t][o]>0){

    S[t][o]>= Demand[t][o]=> Y[t][o]==1;

    (S[t][o]<= Demand[t][o]-0.0001) => (Y[t][o]==0) ;
    (S[t][o]>= Demand[t][o]) => (Y[t][o]==1) ;

    }


    ------------------------------
    ALEX FLEISCHER
    ------------------------------