Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Issue with IloConversion

    Posted 08/15/11 04:09 PM

    Originally posted by: ecnirp


    Hi,

    I'm solving a problem with column generation. At some point, I want to take the master problem called mpModel and change all variables' type to ILOBOOL from ILOFLOAT. I then want to solve the integer program and retrieve the solution. Cplex does seem to be solving the integer program correctly (and to optimality), but when I try to print out the optimal objective function value and variable values, it gives me fractional values. Here is some of the code:

    IloModel model1(env);                               //create a new model
    IloCplex cplex1(model1);                        //create cplex object
                                    
    model1.add(mpModel);                            //copy the current model
     
    for (int b=0; b< (*data).NoBlocks; b++)
        for (int p=0; p < (*pcol)[b].size; p++)
            model1.add(IloConversion(env, MU[b][p], ILOBOOL));        
     
    for (int w=0; w<(*wcol).size; w++)
        model1.add(IloConversion(env, LAMBDA[w], ILOBOOL)); 
     
    cplex1.exportModel("MIPnew.lp");
    cplex1.solve();                                                                                         
    ofstream outfileSOL("IntegerSolution.txt");
                    
    outfileSOL << "Objective Function value: " << cplex1.getObjValue() << endl << endl;
    for (int w=0; w < (*wcol).size; w++)
         outfileSOL << "LAMBDA[" << w << "]=" << cplex1.getValue(LAMBDA[w]) << endl;
     
    for (int b=0; b < (*data).NoBlocks; b++)
        for (int p=0; p < (*pcol)[b].size; p++)
             outfileSOL << "MU[" << b << "][" << p << "]=" << cplex1.getValue(MU[b][p]) << endl;
    

    The strange thing is that when I check IntegerSolution.txt, I do not see integer values, and the objective is not the optimal integer solution objective function value. However, if I solve MIPnew.lp using the interactive optimizer, the solution file gives me integer values.

    Any idea what is going on?
    I am especially surprised because when I created the following example (which mimics my code above), it prints out integer values from cplex1.

    IloModel model(env);
    IloCplex cplex(model);
     
    IloNumVar x(env);
    IloNumVar y(env);
     
    model.add(IloMinimize(env,x + y));
     
    model.add(x >=0.5);
    model.add(y >= 0.25);
     
    cplex.solve();
     
    cout << "Objective function value: " << cplex.getObjValue() << endl;
    cout << "x: " << cplex.getValue(x) << endl;
    cout << "y: " << cplex.getValue(y) << endl << endl;
     
    IloModel model1(env);
    IloCplex cplex1(model1);
     
    model1.add(model);
     
    model1.add(IloConversion(env, x, ILOBOOL));  
    model1.add(IloConversion(env, y, ILOBOOL));  
                    
    cplex1.solve();
    cout << "Objective function value: " << cplex1.getObjValue() << endl;
    cout << "x: " << cplex1.getValue(x) << endl;
    cout << "y: " << cplex1.getValue(y) << endl;
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Issue with IloConversion

    Posted 08/19/11 03:15 AM

    Originally posted by: SystemAdmin


    These fractional values you observe, are they "almost" integral? Is it possible that it is just round-off error and you see values like 0.9999999 or 1.000001 instead of a plain 1?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Issue with IloConversion

    Posted 08/21/11 05:45 PM

    Originally posted by: ecnirp


    Daniel,

    Thank you for your response, but no they are not just round off errors. However I was able to solve this issue but just converting the variables in the current model. There was no need for me to create the second model.

    Unfortunately, had I actually needed a copy of the model, I would still have the issue.
    #CPLEXOptimizers
    #DecisionOptimization