Decision Optimization

Decision Optimization

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

 View Only
  • 1.  from infeasible to feasible

    Posted Mon July 21, 2008 08:50 PM

    Originally posted by: SystemAdmin


    [NDHU said:]

    Hello~everybody~
    I have a question about the modify the parameter iteratively until the feasible solution appeares.
    Actually, I read the mulprod_change_main.mod, but the difference between us is the first solution is feasible.
    My model increases a value of parameter from infeasible till feasible.

    can you give me a hint~?

    Thanks a lot~
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: from infeasible to feasible

    Posted Tue July 22, 2008 02:58 AM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    what in mulprod_change_main make you think this approach would not work in your case (from infeasible to feasible) ?

    I think this approach should work.

    Alain

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: from infeasible to feasible

    Posted Tue July 22, 2008 12:40 PM

    Originally posted by: SystemAdmin


    [NDHU said:]

    main {
      thisOplModel.generate();

      var produce = thisOplModel;
      var capFlour = produce.Capacity["flour"];

      var best;
      var curr = Infinity;
      var ofile = new IloOplOutputFile("mulprod_main.txt");
      while ( 1 ) {
        best = curr;// the value of curr equal to infinity assigned to best

        writeln("Solve with capFlour = ",capFlour);
        if ( cplex.solve() ) {
          curr = cplex.getObjValue();
          writeln();
          writeln("OBJECTIVE: ",curr);//this solution is a real number 457
       
          ofile.writeln("Objective with capFlour = ", capFlour, " is ", curr);       
        }
        else {
          writeln("No solution!");
          break;
        }
        if ( best==curr ) break;

        capFlour++;
        for(var t in thisOplModel.Periods)
          thisOplModel.ctCapacity["flour"][t].UB = capFlour;
      }
      writeln("plan = ",produce.Plan);

      ofile.close();

      0;
    }
    In the code, i make two comments, What i want to explain is the fisrt rum in while loop in this example is feasible. But in my case, the first run is infeasible. when the OPL solve, due to the first comment assign the value to best, so it will break because best ==curr,(infinity==infinity)
    if there is something wrong, please notify me. Thanks a lot!!^^
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: from infeasible to feasible

    Posted Tue July 22, 2008 01:15 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    of course, the exact same code will not work in your case, but the general idea should.

    You have to change the stopping criteria, may be you want to use a boolean "isfeasible" and stop when it becomes true...

    You may need some other small changes in the script, but the general idea of modifying the model and re-generate and reun should work.

    Alain
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: from infeasible to feasible

    Posted Tue July 22, 2008 01:52 PM

    Originally posted by: SystemAdmin


    [NDHU said:]

    Hi~Alain~
    can you give me a small example shows how to use boolean "infeasible" ?
    i cannot understand you saidYou have to change the stopping criteria, may be you want to use a boolean "isfeasible" and stop when it becomes true...


    Thanks a lot~^^

    Ting-Yun
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: from infeasible to feasible

    Posted Tue July 22, 2008 08:05 PM

    Originally posted by: SystemAdmin


    [NDHU said:]

    Hi~Alain~

    I think the primary problem is not the stopping criteria. it looks like the value of parameter that I increse cannot transfer to the model.
    Can you please help me to check it where something wrong?
    Thanks a lot!!

    int n= ...;
    int nv =...;
    float Dis[1..n][1..n]=...;

    float demand[1..n]=...;
    int cap=...;
    float t[1..n]=...;
    float trat[1..n][1..n]=...;
    float time=...;

    dvar boolean x[1..nv][1..n][1..n];
    dvar float y[2..n];
    dvar boolean x2[2..n][2..n];

    minimize
    sum(v in 1..nv, i in 1..n, j in 1..n) Dis[i][j]*x[v][i][j];

    subject to{
    A:
    forall(j in 2..n)
    sum(i in 1..n, v in 1..nv)x[v][i][j]==1;

    B:
    forall(i in 2..n)
    sum(j in 1..n,v in 1..nv)x[v][i][j]==1;

    C:
    forall(p in 1..n, v in 1..nv)
    sum(i in 1..n)x[v][i][p]-sum(j in 1..n)x[v][p][j]==0;

    D:
    forall(v in 1..nv)
    sum(i in 1..n)(demand[i]*sum(j in 1..n)x[v][i][j])<=cap;<br />E:
    forall(v in 1..nv)
    sum(i in 1..n)(t[i]*sum(j in 1..n)x[v][i][j])+sum(i, j in 1..n)trat[i][j]*x[v][i][j]<=time;<br />
    F:
    forall(v in 1..nv)
    sum(j in 2..n)x[v][1][j]<=1;<br />
    G:
    forall(v in 1..nv)
    sum(i in 2..n)x[v][i][1]<=1;<br />
    H://subtour
    forall(i, j in 2..n:i!=j)
      sum(v in 1..nv)x[v][i][j] == x2[i][j];
    I://subtour
    forall(i, j in 2..n:i!=j)
    y[i]-y[j]+n*x2[i][j]<=n-1; <br />
    }
    main{

      thisOplModel.generate();
    var masterDef = thisOplModel.modelDefinition;
    var masterCplex = cplex;
    var masterOpl0 = thisOplModel;
    var masterData0 = masterOpl0.dataElements;
    masterOpl0.addDataSource(masterData0);
    var numofvehicle = masterData0.nv;

    var best = 999999.0;
    var curr =Infinity;

    while(numofvehicle <= 6){<br /> thisOplModel.generate();
    // best = curr;

    //masterOpl0.addDataSource(masterData0);

    writeln("Solve with number of vehicles = ",numofvehicle);

    if(cplex.solve()){
    curr = cplex.getObjValue();
    writeln();
    writeln("Obj = ", curr);
    }
    else{
    writeln("No Solution");
    }
    // if(curr == best )break;
    if (curr != Infinity) {
    best = curr;
    }
    writeln("curr = ",curr);
    writeln("best = ",best);
    writeln("masterData0.nv = ",masterData0.nv);
    //if(curr = Infinity)writeln("Infeasible");
    numofvehicle++;
    masterOpl0.dataElements.nv = numofvehicle;
    masterData0.nv = numofvehicle;
    writeln("masterData0.nv = ",masterData0.nv);

    }
    0;
    }
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: from infeasible to feasible

    Posted Wed July 23, 2008 01:52 AM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    do you have a .dat file that makes the model infeasible at the beginning but which should be feasible with more vehicles ?

    Here is how I would at least change the model :

    int n= ...;
    int nv =...;
    float Dis[1..n][1..n]=...;

    float demand[1..n]=...;
    int cap=...;
    float t[1..n]=...;
    float trat[1..n][1..n]=...;
    float time=...;

    dvar boolean x[1..nv][1..n][1..n];
    dvar float y[2..n];
    dvar boolean x2[2..n][2..n];

    execute {
      writeln("preprocess with nv = "+nv);
    }
    minimize
    sum(v in 1..nv, i in 1..n, j in 1..n) Dis[i][j]*x[v][i][j];

    subject to{
    A:
    forall(j in 2..n)
    sum(i in 1..n, v in 1..nv)x[v][i][j]==1;

    B:
    forall(i in 2..n)
    sum(j in 1..n,v in 1..nv)x[v][i][j]==1;

    C:
    forall(p in 1..n, v in 1..nv)
    sum(i in 1..n)x[v][i][p]-sum(j in 1..n)x[v][p][j]==0;

    D:
    forall(v in 1..nv)
    sum(i in 1..n)(demand[i]*sum(j in 1..n)x[v][i][j])<=cap;<br />E:
    forall(v in 1..nv)
    sum(i in 1..n)(t[i]*sum(j in 1..n)x[v][i][j])+sum(i, j in 1..n)trat[i][j]*x[v][i][j]<=time;<br />
    F:
    forall(v in 1..nv)
    sum(j in 2..n)x[v][1][j]<=1;<br />
    G:
    forall(v in 1..nv)
    sum(i in 2..n)x[v][i][1]<=1;<br />
    H://subtour
    forall(i, j in 2..n:i!=j)
      sum(v in 1..nv)x[v][i][j] == x2[i][j];
    I://subtour
    forall(i, j in 2..n:i!=j)
    y[i]-y[j]+n*x2[i][j]<=n-1; <br />
    }
    main{

      thisOplModel.generate();
    var masterDef = thisOplModel.modelDefinition;
    var masterCplex = cplex;
    var masterOpl0 = thisOplModel;
    var masterData0 = masterOpl0.dataElements;
    //masterOpl0.addDataSource(masterData0);
    var numofvehicle = masterData0.nv;

    var best = 999999.0;
    var curr =Infinity;

    while(numofvehicle <= 10){<br /> // best = curr;

    //masterOpl0.addDataSource(masterData0);
    var opl =new IloOplModel(masterDef, masterCplex);
    opl.addDataSource(masterData0);
    opl.generate();
    writeln("Solve with number of vehicles = ",numofvehicle);

    if(cplex.solve()){
    curr = cplex.getObjValue();
    writeln();
    writeln("Obj = ", curr);
    }
    else{
    writeln("No Solution");
    }
    // if(curr == best )break;
    if (curr != Infinity) {
    best = curr;
    }
    writeln("curr = ",curr);
    writeln("best = ",best);
    writeln("masterData0.nv = ",masterData0.nv);
    //if(curr = Infinity)writeln("Infeasible");
    numofvehicle++;
    masterOpl0.dataElements.nv = numofvehicle;
    masterData0.nv = numofvehicle;
    writeln("masterData0.nv = ",masterData0.nv);

    }
    0;
    }
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: from infeasible to feasible

    Posted Wed July 23, 2008 08:38 AM

    Originally posted by: SystemAdmin


    [NDHU said:]

    Hi~Alain~
    Thanks a lot~~It works~

    I think that I realize how the OPL script operate inside.

    You give me a lot of useful idea and correct thinking direction~

    Thanks~~~^^

    Ting-Yun
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: from infeasible to feasible

    Posted Wed July 23, 2008 01:18 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Happy to read that was useful.
    Alain
    #DecisionOptimization
    #OPLusingCPLEXOptimizer