Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Column Generation using Cplex with C++

    Posted 02/20/14 03:17 PM

    Originally posted by: Justdu


    Dear all:

    The cutting stock example uses the following technique to add columns:
     
    Cut.add(IloNumVar(RollsUsed(1) + Fill[j](int(rollWidth / size[j]))));

    That is, by using:

    Variable.add(IloNumVar(objective(Objective Coefficient) + Constraint 1(Constraint 1 Coefficient) + Constraint 2(Constraint 2 Coefficient)......);

     

    What if I need add the variable into thousands of constraints? It is impossible to declare the constraint one by one within the parenthesis. Are there any other ways that I can add the variable into thousands of constraints?

     

    Thanks.

    Justin


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Column Generation using Cplex with C++

    Posted 02/20/14 03:39 PM

    operator+= in class IloNumColumn is your friend:

    #include <iostream>
    #include <ilcplex/ilocplex.h>

    int
    main(void)
    {
       IloEnv env;

       IloObjective obj(env);
       IloRangeArray r(env);
       IloNumVar x(env, "x");
       for (int i = 1; i <= 10; ++i)
          r.add(i * x <= i);

       IloNumColumn ycol(env);
       for (int i = 1; i <= 10; ++i)
          ycol += r[i-1](i);
       ycol += obj(0.5);

       IloNumVar y(ycol, 0, 1, IloNumVar::Float, "y");

       IloModel model(env);
       model.add(obj);
       model.add(r);
       std::cout << model << std::endl;

       env.end();
       return 0;
    }

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Column Generation using Cplex with C++

    Posted 02/24/14 08:39 PM

    Originally posted by: Justdu


    Hi Daniel,

     

    Thank you so much!

    Could you please further explain how can I add multiple columns (thousands of) to the model?

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Column Generation using Cplex with C++

    Posted 02/25/14 01:26 AM

    Well, you just have to instantiate IloNumColumn and IloNumVar for each variable you want to add. This can be done in a loop as well.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Column Generation using Cplex with C++

    Posted 04/06/16 05:34 PM

    Originally posted by: Mehdi.M


    Dear all cplex experts,

    I have a question on column major model.

    In my model, I defined the constraints, added to the model, and  then add the columns. 

    I added one specific column two times to the same constraint. But the coefficient is not doubled ?

    The coefficient would be replaced or added to the previous one?

     

    The following code is not exactly the same but it simulate what I did:

       IloObjective obj(env);
       IloRangeArray r(env);

       for (int i = 1; i <= 10; ++i)
            r[i-1].add ( 100 - x[i-1] <= 0)

       IloModel model(env);

       model.add(obj);
       model.add(r);

     

       IloNumColumn ycol(env);

       ycol += r[0](1);

       ycol += r[0](1);


       IloNumVar y(ycol, 0, 1, IloNumVar::Float, "y");

     

    But finally the coefficient of y in the constraint r[0] is 1 not 2? why?

     

    Thanks

     

    Mehdi


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Column Generation using Cplex with C++

    Posted 04/08/16 02:05 AM

    Your code does not compile for me because this lines

    r[i-1].add ( 100 - x[i-1] <= 0);

    produces an error that the IloRange type has no add() member. After changing this to

    r.add ( 100 - x[i-1] <= 0);

    the code compiles and runs fine. But the coefficient of y in r[0] is 2, as expected. How did you conclude that the coefficient is 1?

    I used this code to export the model

       IloCplex cplex(model);
       cplex.exportModel("double.lp");

    and got this model in double.lp:

    Minimize
     obj:
    Subject To
     c1:  - x(0) + 2 y <= -100
     c2:  - x(1) <= -100
     c3:  - x(2) <= -100
     c4:  - x(3) <= -100
     c5:  - x(4) <= -100
     c6:  - x(5) <= -100
     c7:  - x(6) <= -100
     c8:  - x(7) <= -100
     c9:  - x(8) <= -100
     c10: - x(9) <= -100
    Bounds

     ...


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Column Generation using Cplex with C++

    Posted 04/08/16 05:45 PM

    Originally posted by: Mehdi.M


    Hi Daniel,

    Thanks a lot for your reply. 

    Yes, I exactly did r.add ( 100 - x[i-1] <= 0);

    So, you confirm it should be added but it does not happen in my code!

    I have to check again every thing. 

    Thanks again

    Mehdi


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Column Generation using Cplex with C++

    Posted 04/11/16 02:05 PM

    I suggest to first check the way in which you check the coefficients. For example, if I do

    std::cout << r[0] << std::endl;

    right after the IloNumVar y(...) construction then I can see coefficient 2 for y. I am pretty sure you should see the same.


    #CPLEXOptimizers
    #DecisionOptimization