Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to integrate the .ops file into the opl model created in java api?

    Posted 03/20/13 11:29 PM

    Originally posted by: SystemAdmin


    Hi,

    I have been recently using java api of opl to convert the established .mod and .dat file into a solvable .lp file. Yet I found the setting file .ops not involved in the process. Since I might want to revise the settings from the cplex studio view, I really want to find a way to involve it into the opl model too.

    I see a line on the reference manual that the task can actually be done using the run configuration. Yet I found the sample is not illustrative enough.

    So can someone tell me how to read the .ops file and then build a new opl model and thus a lp file with it?

    Many thanks.

    Zitong
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to integrate the .ops file into the opl model created in java api?

    Posted 03/21/13 04:01 AM
    Hi,

    in the factory IloOplFactory, instead of createOplModel you may use createOplProject.

    You have an example in \opl\examples\opl_interfaces\java\oplrunsample\src\oplrunsample
    IloOplErrorHandler errHandler = oplF.createOplErrorHandler();
            IloOplRunConfiguration rc = null;
            if (_cl.isProject()) {
                IloOplProject prj = oplF.createOplProject(_cl.getProjectPath());
                rc = prj.makeRunConfiguration(_cl.getRunConfigurationName());
            } else {
                if (_cl.getDataFileNames().size() == 0) {
                    rc = oplF.createOplRunConfiguration(_cl.getModelFileName());
                } else {
                    String[] dataFiles = _cl.getDataFileNames().toArray(
                            new String[_cl.getDataFileNames().size()]);
                    rc = oplF.createOplRunConfiguration(_cl.getModelFileName(),
                            dataFiles);
                }
            }
    


    in the configuration, you will have your ops file

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to integrate the .ops file into the opl model created in java api?

    Posted 03/21/13 04:13 AM

    Originally posted by: SystemAdmin


    Thanks for your answer.

    I already read this sample. But it doesn't involve the process of integrating an already established ops file.

    I think your reply suggests that I can have my own newly built ops file through the creation of the project. But this is not what I want.

    What I want is to revise the ops file in the cplex studio and then put this revised ops file in my java model.

    I hope I have made myself clear.

    Thanks again for your help.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to integrate the .ops file into the opl model created in java api?

    Posted 03/21/13 04:20 AM

    Originally posted by: SystemAdmin


    I think the method ReadProjectSettings is what I want in this case.

    I wrote the following code:

    IloOplFactory.setDebugMode(true);
    IloOplFactory oplF = new IloOplFactory();
    IloOplErrorHandler errHandler = oplF.createOplErrorHandler(System.out);

    IloOplProject prj = oplF.createOplProject(".\\MILP.mod");

    String modpath= ".\\MILP.mod";

    String datpath= ".\\input.dat";

    IloCplex cplex = oplF.createCplex();
    IloCplex.ParameterSet paraset = cplex.getParameterSet();
    IloOplSettings settings = oplF.createOplSettings(errHandler);
    settings.setWithNames(true);

    FileInputStream ifs = new FileInputStream(".\\MIPconfig.ops");

    IloOplRunConfiguration rc = oplF.createOplRunConfiguration(modpath,datpath);

    prj.ReadProjectSettings(ifs,"OPSFILE",cplex,paraset,settings);

    ifs.close();

    IloOplModel opl=rc.getOplModel();

    opl.generate();

    cplex.exportModel(".\\test.lp");
    cplex.end();
    oplF.end();
    I tried to run and got the error saying that there exists mismatches of types between the arguments I gave and that it requires.

    Again many thanks.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: How to integrate the .ops file into the opl model created in java api?

    Posted 03/26/14 11:59 AM

    Originally posted by: DBRE


    Try the following method from IloOplProject:

    public  static void ApplyProjectSettings(istream opsStream, String name, IloOplModel model)


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: How to integrate the .ops file into the opl model created in java api?

    Posted 04/04/14 09:20 AM

    Originally posted by: DBRE


    An example:

        IloOplFactory oplF = new IloOplFactory();
        IloOplErrorHandler errHandler = oplF.createOplErrorHandler();
        IloOplFactory.setDebugMode(true);
        IloOplModelSource modelSource = oplF.createOplModelSource(
            getResourcePath("muModel.mod"), false);
        IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,
            errHandler);
        IloCplex cplex = oplF.createCplex();
        IloOplModel opl = oplF.createOplModel(def, cplex);

        // Read one setting before changing the setting
        double tilim = cplex.getParam(DoubleParam.TiLim);
        System.out.println("BEFORE ApplyProjectSettings : tilim = " + tilim);

        // Apply the ops file to the OPL model
        String opsPath = "C:/rtc/trunk/opl_lang/examples/tests/data/projectSettings.ops";
        FileInputStream opsStream = new FileInputStream(opsPath);
        JavaToCppInputStreamAdapter streamAdapter = new JavaToCppInputStreamAdapter(
            opsStream);
        String again = "again" + opsPath;
        IloOplProject.ApplyProjectSettings(streamAdapter, again, opl);

        // Re read the setting to see its new value, as set in the ops file
        tilim = cplex.getParam(DoubleParam.TiLim);
        System.out.println("After ApplyProjectSettings : tilim = " + tilim);
        opsStream.close();

        opl.generate();


    #DecisionOptimization
    #OPLusingCPLEXOptimizer