Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Obtaining dvar values using C++

    Posted Mon March 18, 2024 05:40 PM
    Hello everyone,
     
    I'm diving into concert technology for the first time and I'm currently navigating through the process of extracting the solution after solving a problem. I've managed to read the formulation from a .mod file using C++, but I could use some guidance on retrieving the values of decision variables. Additionally, I'm curious about the approach for extracting values if my dvar is a multi-dimensional array.
     
    Appreciate any insights or advice!
     dvar float+ x1;
     dvar float+ x2;
     
     maximize
     	12*x1 + 9*x2;
    
    subject to {
      
      x1  <= 1000;
      x2  <= 1500;
      x1 +x2 <= 1750;
      4*x1 + 2*x2 <= 4800;
      
    }

    Here is my C++ program. 

    try {
    
            IloNum curr = IloInfinity;
            IloOplErrorHandler errHandler(env, cout);
            IloOplSettings settings(env, errHandler);
            settings.setWithWarnings(IloFalse);
    
            IloOplModelSource masterSource(env, "C:\\LOCATION.mod");
            IloOplModelDefinition masterDef(masterSource, settings);
            IloCplex masterCplex(env);
            IloOplModel oplModel(masterDef, masterCplex);
    
            masterCplex.setOut(env.getNullStream());
            masterCplex.setParam(IloCplex::TiLim, 30);
    
            IloOplRunConfiguration masterRC(masterDef);
            masterRC.setCplex(masterCplex);
            IloOplModel masterOpl = masterRC.getOplModel();
            masterOpl.generate();
    
            cout << masterCplex.getModel() << endl;
    
            cout << "Solve master." << endl;
            if (masterCplex.solve()) {
                curr = masterCplex.getObjValue();
                cout << endl
                    << "MASTER OBJECTIVE: " << fixed << setprecision(2) << curr
                    << endl;
    
                //cout << masterOpl.getElement("x1") << endl;
               // cout << masterCplex.getValue(x2) << endl;
                
                status = 0;
            }
            else {
                cout << "No solution!" << endl;
                status = 1;
            }
    
    }



    ------------------------------
    Dheeban Kumar Srinivasan Sampathi
    ------------------------------


  • 2.  RE: Obtaining dvar values using C++

    Posted Tue March 19, 2024 10:11 AM

    Hi,

    in CPLEX_Studio2211\opl\examples\opl_interfaces\cpp\src you have many examples

    And special focus on iterators.cpp



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Obtaining dvar values using C++

    Posted Tue March 19, 2024 11:14 AM

    Thank you for showing me the right direction! I was able to understand and make it work for my problem instance.



    ------------------------------
    Dheeban Kumar Srinivasan Sampathi
    ------------------------------