Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Accessing decision variables

    Posted 04/10/12 11:15 AM

    Originally posted by: SongYang


    Hi all,
    I am a fresh man on it. Now I want to access the decision variables in my codes of Java, but it reports that " Type dvar int expected for element "b". Here is my code ,it is very simple, but I just can not figure it out. Can you help me, thanks in advance!!!

    IloOplFactory.setDebugMode(true);
    IloOplFactory oplF = new IloOplFactory();

    IloOplErrorHandler errHandler = oplF.createOplErrorHandler(System.out);
    IloOplSettings settings = oplF.createOplSettings(errHandler);

    IloOplModelSource modelSource = oplF.createOplModelSource("D:/songyang/opl/Test/test3.mod");

    IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,settings);
    IloCplex cplex = oplF.createCplex();
    IloOplDataSource dataSource= oplF.createOplDataSource("D:/songyang/opl/Test/test3.dat");
    IloOplModel opl = oplF.createOplModel(def, cplex);
    opl.addDataSource(dataSource);

    double objective_result;

    IloOplRunConfiguration rc = oplF.createOplRunConfiguration(opl.getModelDefinition(), opl.makeDataElements());
    rc.getCplex().setOut(null);
    rc.getOplModel().generate();

    IloOplDataElements myData;
    IloOplElement DeVariable;

    if (rc.getCplex().solve())
    {
    objective_result = rc.getOplModel().getCplex().getObjValue();

    myData=rc.getOplModel().makeDataElements();

    DeVariable=rc.getOplModel().getElement("b");
    IloIntMap DeData=DeVariable.asIntMap();
    int opx=DeData.get(1);

    System.out.println(opx);
    System.out.print("The optimum value is:");
    System.out.println(objective_result);
    BufferedWriter bw = new BufferedWriter(new FileWriter("D:/songyang/opl/Test/result111.txt"));
    String str=String.valueOf(objective_result);

    bw.write(str);

    bw.close();
    }
    else
    {
    System.out.println("No solution!");
    System.out.flush();
    }

    rc.end();
    rc = null;
    }catch( Exception e) {

    e.printStackTrace();
    }
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Accessing decision variables

    Posted 05/22/12 08:42 AM

    Originally posted by: SystemAdmin


    I think the problem from the fact that you try to directly transform an array of variables intro an array of ints.
    DeVariable=rc.getOplModel().getElement("b");
    IloIntMap DeData=DeVariable.asIntMap();
    int opx=DeData.get(1);
    


    should perhaps be written as
    DeVariable=rc.getOplModel().getElement("b");
    IloIntVarMap DeData=DeVariable.asIntVarMap();
    int opx=DeData.get(1);
    


    or
    DeVariable=rc.getOplModel().getElement("b");
    IloIntVarMap DeData=DeVariable.asIntVarMap();
    IloIntVar opx=DeData.get(1);
    int x = rc.getOplModel().getCplex().getValue(opx);
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer