Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  objective within while loop

    Posted 07/28/15 06:51 AM

    Originally posted by: Cplex


    Hey guys,

    I have a problem modelling a robust recoverable warehouse location problem. There's a while loop which contains the objective. It has to look more or less like this:

     

    h == 0;

    while(h <= 20){  
            FixC = sum (m in M) c[m]*x[m];
            VarC = sum (m in M,n in N) d[m][n]*y[m][n];
            RC = sum (n in N,k in K) v[n][k]*h*(1+p[k]);      

            costs = FixC + VarC + RC;
            minimize costs;
            h == h+1;}

     

    So the costs should be minimized until h reaches a value of 20. The value of h influences the recoverable costs.

    It would be nice if anyone could try to help me with this issue.

     

    Thanks in advance!

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: objective within while loop

    Posted 07/28/15 09:58 AM

    Hi,

    why do not you adapt what was given at https://www.ibm.com/developerworks/community/forums/html/topic?id=fbea4b7b-6ed7-4fb8-a890-45df63b39222

    ?

    You would add something like

    dexpr RC[scenario in scenarii] = sum (n in N,k in K)
        scenario*(1+p[k]); 

    and then the objective would be rewritten from

    minimize sum(scenario in scenarii)
        (TotalFixedCost[scenario] + TotalSupplyCost[scenario]);

    to

    minimize sum(scenario in scenarii)
        (TotalFixedCost[scenario] + TotalSupplyCost[scenario]+RC[scenario]);

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: objective within while loop

    Posted 12/06/19 07:55 AM

    Originally posted by: Kamran_Sr


    Hi,

    I have a model that I need to solve first, and then do a flow control to improve the solution. However, I got an issue with a while loop in this flow control. What I need to do is after solving the problem if an specific decision variable (SlackCap[i]) got a positive value, I have to change the data regarding to a set, which is the index of different decision variables, and rerun the model again until that decision variable get 0 value for all its elements. I have used a while loop to do this. The issue is, although incorporated a break statement (if (feasblity[i] = 0break;) for the loop, the model still keeps running even all elements of SlackCap[i] equals to 0.

    My script code is as follows:

    main {

     

    var source = new IloOplModelSource("Feasiblity Restoration.mod");

    var cplex = new IloCplex();

    var def = new IloOplModelDefinition(source);

    var model = new IloOplModel(def,cplex);

    var data = new IloOplDataElements();

    var k = 0;

     

    model.addDataSource(data);

    data.DataExcelFile = "InputData3.xlsx";

    data.NbdryportsString="dryports";

    data.fixedcostString = "fixedcost";

    data.allocationcostString = "allocationcost";

    data.coiString = "coim";

    data.ceoiString = "ceoim";

    data.bijString = "bijm";

    data.beijString = "beijm";

    data.li1String = "leaseI1";

    data.li2String = "leaseI2";

    data.viString = "vi";

    data.hiString = "hi";

    data.CapiString = "Capi";

    data.LTString = "LTi";

    data.RString = "Ri";

    data.InversePhiNString = "InversePhiN";

    data.InverseINString = "InverseIN";

    data.InitialIString = "InitialI";

     

    var Data = new IloOplDataSource("Feasiblity Restoration.dat");

    model.addDataSource(Data);

    model.generate();

     

    if(cplex.solve()){

     

    model.postProcess();

    writeln("\t cost :", cplex.getObjValue());

    writeln("\t SlackCap = ",model.SlackCap);

    writeln("\t Location = ",model.X);

    writeln("\t Allocation = ",model.Y);

     

    var Infeasblity = new Array(model.dryports);

    for(var i in model.dryports){

    Infeasblity[i] = model.SlackCap[i].solutionValue;}

     

    var dryports = model.dryports}

     

    while(1){

    for (var i in dryports){

    if (Infeasblity[i]>0){

     

    k++;

    var model2 = new IloOplModel(def,cplex);

    var data3 = new IloOplDataElements();

     

    model2.addDataSource(data3);

    data3.DataExcelFile = "Restoration.xlsx";

    data3.NbdryportsString = "dryports"+k;

    data3.fixedcostString = "fixedcost"+k;

    data3.allocationcostString = "allocationcost"+k;

    data3.coiString = "coim"+k;

    data3.ceoiString = "ceoim"+k;

    data3.bijString = "bijm"+k;

    data3.beijString = "beijm"+k;

    data3.li1String = "leaseI1"+k;

    data3.li2String = "leaseI2"+k;

    data3.viString = "_vi"+k;

    data3.hiString = "_hi"+k;

    data3.CapiString = "Capi"+k;

    data3.LTString = "_LTi"+k;

    data3.RString = "_Ri"+k;

    data3.InversePhiNString = "InversePhiN"+k;

    data3.InverseINString = "InverseIN"+k;

    data3.InitialIString = "InitialI"+k;

     

    var data4 = new IloOplDataSource("Feasiblity Restoration.dat");

    model2.addDataSource(data4);

    model2.generate();

     

    if(cplex.solve()) {

    model2.postProcess();

    writeln("\t New cost"+k+" :", cplex.getObjValue());

    writeln("\t New SlackCap"+k+" = ",model2.SlackCap);

    writeln("\t New Location"+k+" = ",model2.X);

    writeln("\t New Allocation"+k+" = ",model2.Y);

     

    var dryports = model2.dryports;

    for(var i in model2.dryports){

    Infeasblity[i] = model2.SlackCap[i].solutionValue;}

     

    var feasblity = new Array ();

    for(var i in model2.dryports){

    if (model2.SlackCap[i].solutionValue == 0)

    feasblity[i] = model2.SlackCap[i].solutionValue}

     

    }

    }

    else if (feasblity[i] = 0)

    break;

    }

    if (feasblity[i] = 0)

    break;

    }

    writeln("\t Final cost:", cplex.getObjValue());

    writeln("\t Final SlackCap = ",model2.SlackCap);

    writeln("\t Final Location = ",model2.X);

    writeln("\t Final Allocation = ",model2.Y);

    }

    I would be grateful if someone can help me with this issue.

     

    Regards,

    Kamran


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: objective within while loop

    Posted 12/10/19 04:07 PM

    Hi,

    in your model I see

    if (feasblity[i] = 0)

    which is probably wrong and I think you meant

    if (feasblity[i] == 0)

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: objective within while loop

    Posted 12/11/19 03:40 PM

    Originally posted by: Kamran_Sr


    Hi Alex,

    Many Thanks for your reply. I have modified the if statement as you advised. However, this issue is not resolved yet.

    I have attached the model files. I really appreciated any further advice.

     

    Regards.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: objective within while loop

    Posted 12/11/19 04:55 PM

    Hi,

    just to be sure have you fixed the 2 errors:

    else if (feasblity[i] == 0)
               { writeln("break"); break; }        
            }
              if (feasblity[i] == 0)       
               { writeln("break"); break; }
             }      

    instead of

    else if (feasblity[i] = 0)
               { writeln("break"); break; }        
            }
              if (feasblity[i] = 0)       
               { writeln("break"); break; }
             }      

    ?

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: objective within while loop

    Posted 12/11/19 05:28 PM

    Originally posted by: Kamran_Sr


    Hi Alex,

     

    Yes, I did and the loop was ended. However, the while loop stopped in the iteration in which the value of feasblity[I] was [2 0 0]. But what I need is the loop should be aborted when all elements of feasblity[I] be 0.

    Then I tried to use the decision variable directly in the if condition as follows:

    else if (model.SlackCap[i] == 0)
    { writeln("break"); break; }
    }
    if (model.SlackCap[i] == 0)
    { writeln("break"); break; }
    }

     

    But again the loop stops as this variable return the 0 value for one index(element of array). And as I mentioned I need the loop stops when all elements of this variable be zero, i.e. [0 0 0 0] which will be obtained in the next iteration. So I am not sure how to set the condition in the if function for all elements of array. I would appreciate  any advice.

     

    Thanks again for your assistance.

     

    Regards 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer