Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  writing to file.

    Posted 07/29/08 02:49 AM

    Originally posted by: SystemAdmin


    [ArushGadkar said:]

    Hello ,
    I have a cplex code which works fine. I want to add some functionality in the code. i want to write all solutions  to a text file when the objective value is >= some value.
    I could manage writing the final solution in a file , how do i write the intermediate results also?

    Thanks Arush. 
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: writing to file.

    Posted 07/29/08 05:59 AM

    Originally posted by: SystemAdmin


    [aroso said:]

    You can either use goals or callbacks to control what happens at each individual node during the branch and cut process. This way, you can check whether or not the solution of a node is integer feasible and >= some value, and write it to a file. You can learn more about both of these features (goals and callbacks) in the ILOG CPLEX User's Manuel provided.

    Antonio
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: writing to file.

    Posted 07/29/08 07:01 AM

    Originally posted by: SystemAdmin


    [ArushGadkar said:]

    Is the following coreect :
    To print out values of d everytime the objective function is greater than 20.

    #include <ilcplex/ilocplex.h>
    ILOSTLBEGIN

    ILOMIPCALLBACK1(MyCallback) {

      if ( getObjValue() >= 20 ) {
        cout << "Objective = " << getObjValue() << endl;<br />    cout<< "d = "<<getValues()<<endl;<br />              }
      }



    int main()


    IloEnv env;
      try {
        ...........
        Rest OF the Program code
        ............

        cplex.use(MyCallback(env));
        cplex.solve();

    // To ouput final result
    env.out() << "Solution status = " << cplex.getStatus() << endl;<br />env.out() << "Solution value  = " << cplex.getObjValue() << endl;<br />

    }

    return 0;

    }
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: writing to file.

    Posted 07/29/08 02:29 PM

    Originally posted by: SystemAdmin


    [aroso said:]

    You need to tell CPLEX what variable you want to get:

    #include <ilcplex/ilocplex.h>
    ILOSTLBEGIN

    ILOMIPCALLBACK1(MyCallback) {

      if ( getObjValue() >= 20 ) {
        IloNumVar DVar(env);
        DVar = opl.getElement("d").asNumVar();
        cout << "Objective = " << getObjValue() << endl;<br />    cout<< "d = "<<getValue(DVar)<<endl;<br />              }
      }



    int main()


    IloEnv env;
      try {
        ...........
        Rest OF the Program code
        ............

        cplex.use(MyCallback(env));
        cplex.solve();

    // To ouput final result
    env.out() << "Solution status = " << cplex.getStatus() << endl;<br />env.out() << "Solution value  = " << cplex.getObjValue() << endl;<br />

    }

    return 0;
    }


    Also, be careful with the way you use values returned by CPLEX, as they are rarely integer - CPLEX considers values within a tolerance, so 20 can be either 19.999999999999998 or 20.000000000000002. However, C++ has no tolerance at all, so it is a good practice to either round the values (when storing them) or accept them within a certain interval (in if-then-else statements).

    Antonio

    #CPLEXOptimizers
    #DecisionOptimization