Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  problem on inserting new variables when using a column generation

    Posted 07/15/19 12:17 PM

    Originally posted by: Sultan_Niz7755


    Hello, everybody. At the moment I am dealing with the topic of planning patients into surgery. I have to apply Column Genearation and implement it in OPL. In this respect I had two questions. I have successfully written original problem in opl, but I have some difficulties in writing the master and sub problem. the questions are as follows:
    1. let Ω be the set of all feasible columns. How can I write this in OPL?


    2. i have the problem with inserting the dual variables in the sub problem. like this:


    Let πi , λt , βt , and γt be the optimal dual variables to an RMP, associated respectively with constraints (10), (11) and (12).

    I am very thankful for any feedback.

    Regards, Sherzod

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: problem on inserting new variables when using a column generation

    Posted 07/16/19 05:38 AM

    Here is a very simple .mod file (adapted from the opl/examples/opl_interfaces/java/javaknapsack/cutstock_ext_main.mod example in the distribution) that shows how you can add variables to a model:

    // This tuple represents a variable that can be added.
    // The variable has an index, an objective coefficient and a coefficient
    // for the one constraint that our model has. If the model had more
    // constraints in which the variable could appear, then we would of course
    // need more constraints (either add more fields or change the type of the
    // field to an array of floats).
    tuple T {
      key int   idx;
          float obj;   // Objective coefficient of variable
          float coef;  // Coefficient of variable in constraint
    }

    // Each element in this set defines a variable.
    {T} columns = ...;

    // The variables.
    dvar boolean x[columns];


    maximize sum(j in columns) j.obj * x[j];

    subject to {
      // A simple constraints: Pick at most 5 variables.
      sum(j in columns) j.coef * x[j] <= 5;
    }

    main {
      // Generate the initial model and extract required data from it.
      var masterOpl = thisOplModel;
      masterOpl.generate();
      var masterDef = masterOpl.modelDefinition;
      var masterCplex = cplex;
      var masterData = masterOpl.dataElements;

      for (var iter = 1; iter <= 9; ++iter) {
        // Solve a model with the current set of columns.
        sub = new IloOplModel(masterDef,masterCplex);
        sub.addDataSource(masterData);
        sub.generate();
        masterCplex.solve();
        writeln("## Iteration " + iter + ": " + masterCplex.getObjValue());
        for (var j in masterData.columns) {
           writeln("x[" + j.idx + "] = " + sub.x[j]);
        }

        // TODO: Find a column to add.

        // Add the new column to the master data.
        // Here we simply add a new column with objective 'iter' and coefficient
        // 1.0 in our constraint.
        masterData.columns.add(masterData.columns.size, // idx
                               iter, // obj
                               1.0   // coef
                               );

        sub.end();
      }

      0;
    }

    In addition to the .mod you also need this .dat:

    columns = { };


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: problem on inserting new variables when using a column generation

    Posted 07/17/19 09:40 AM

    Originally posted by: Sultan_Niz7755


    Hi, Daniel,

    Thank you so much for your reply. I'm actually new to Cplex, I'm not really that pure. I understood Column Generation to mean that I first have to create compact model, then master and subproblem.  And then to connect all the models together, I need the Main function, right?  The column-oriented formulation of the model confuses me all the time. In the Cutting Stock example, only a dual variable pi was inserted, but in my case I have to define that the above 4 variables are optimal dual variables for my restricted master problem. These optimal dual variables I need to apply to my pricing problem to have the solution to the subproblem. Hier ist my OPL Code for Master Problem:

     int  N = ...;// Number of Patients
      int j = ...; // Number of tasks
      range Patient = 1..N;
      range Task = 1..j;
      int P = ...; // Number of Porters
      range Porter = 1..P;
      int R = ...; // Number of Operating rooms
      range Room = 1..R;
      int B = ...; // Number of recovery beds
      range Bed = 1..B;
      int Period = ...;
      range H = 0..Period-1; // discrete Time horizon of H Periods, The discrete Time unit is set equal to 10 Minutes
      int A = ...;
      range K = 1..A;
       
      
      int p[Patient, Task] = ...;
      dvar float+ c[K];
      dvar boolean x[Patient, K];//1,if column k is related to patient i
      dvar int+ s[K,Task];//starting time of the task j according to column k
      dvar int+ y[K];//let y(k) for k€K be a binary decision variable that takes 1 if the feasible column k is selected and 0 otherwise
      dvar boolean u[H,K];
      dvar boolean v[H,K];
      dvar boolean w[H,K];
      
      minimize sum (k in K)c[k]*y[k];
      subject to  {
      forall (k in K) c[k] == s[k,4] + (sum (i in Patient) x[i,k]*p[i,4]);
      forall (i in Patient, k in K, t in H) u[t,k] == (((s[k, 1] <= t)  && (s[k, 1] + p[i, 1] - 1) >= t) + ((s[k, 4] <= t)  && (s[k, 4] + p[i, 4] - 1) >= t));
      forall (i in Patient, k in K, t in H) v[t,k] == ((s[k, 2] <= t)  && (s[k, 2] + p[i, 2] + p[i,5] - 1) >= t);
      forall (i in Patient, k in K, t in H) u[t,k] == ((s[k, 4] <= t)  && (s[k, 4] + p[i, 4] - 1) >= t);
      
      forall (i in Patient) sum (k in K) (x[i,k]*y[k]) == 1;
      forall (t in H, pi in Porter) sum (k in K) u[t,k]*y[k] <= pi;
      forall (t in H, r in Room) sum (k in K) v[t,k]*y[k] <= r;
      forall (t in H, b in Bed) sum (k in K) w[t,k]*y[k] <= b;
      
        
      }
      

     

    and here pricing problem

     

    thank you again,

     

    regards Sherzod

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: problem on inserting new variables when using a column generation

    Posted 07/17/19 10:17 AM

    Originally posted by: Sultan_Niz7755


    hier is pricing problem


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: problem on inserting new variables when using a column generation

    Posted 07/25/19 06:09 AM

    Sorry, I cannot dig into your particular model in detail. But I think there is some confusion about the cutstock example. Maybe I did not point to the best variant of that. You could take a look at

    opl/examples/opl/cutstock/cutstock_main.mod

    That is similar but a bit simpler. The dual values are used for communicating with the sub problem. However, the columns that are added to the master are added implicitly via this statement:

    masterData.Patterns.add(masterData.Patterns.size,1,subOpl.Use.solutionValue);

    This adds a new elements to the set

    {pattern} Patterns = ...;

    and since the variables are defined as

    dvar float Cut[Patterns] in 0..1000000;

    this results in one more variable if we regerenate the model from scratch.


    #CPLEXOptimizers
    #DecisionOptimization