Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Optimization tasks in cycle

    Posted 11/22/10 01:23 AM

    Originally posted by: apscomeup


    Hi! I need to solve optimization tasks in cycle. So have some questions.
    1. Is it possible to change objective function and use only one .mod file?
    Possible to define objective in cycle or to define them in .mod file using 'dexpr' type and run needed objective or there exists some other ways.

    2. Another matter, is it possible to define (or redefine) parameters values which are used in the .mod file. When i try to do it you can see the comment '//opl.pTest = 3;' I have an error that it is not allowed to define via flow control.

    3. The last, is it possible to write results from flow control to Access database or the unique way is using 'opl.postProcess();' and define commands to write data in .dat file as i've done in code below

    
    main 
    { 
    
    for (var s = 1; s <= 2; s++) 
    { var source = 
    
    new IloOplModelSource(
    "prtOptim.mod"); var cplex = 
    
    new IloCplex(); var def = 
    
    new IloOplModelDefinition(source); var opl = 
    
    new IloOplModel(def,cplex); var data = 
    
    new IloOplDataSource(
    "prtOptim.dat"); opl.addDataSource(data); opl.generate(); 
    //opl.pTest = 3; 
    //opl.ACTIVESCENES = {1,2,3,4,5}; opl.ACTIVESCENES.add(s); var res = cplex.solve(); writeln(
    "Yeeeh babyMM!"); writeln(res); writeln(opl.ACTIVESCENES); 
    //writeln(cplex.getObjValue()); opl.postProcess(); 
    }; 
    };
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Optimization tasks in cycle

    Posted 11/22/10 02:24 AM

    Originally posted by: apscomeup


    Sorry! The first question is answered in the previous thread:

    https://www.ibm.com/developerworks/forums/thread.jspa?threadID=353024&tstart=0
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Optimization tasks in cycle

    Posted 11/22/10 05:33 AM

    Originally posted by: SystemAdmin


    Howdy,

    concerning the second question:
    The parameter should be defiend as "external data".
    You can than chnage it via:
    data.pTest = 3;
    

    You should do this before you generate() the model.
    Concerning the third question:
    The easiest way is indead to use the postProcess() functionality.
    If you do not want to use it, you might write your own Java-Code
    to write OPL-Elements to the data base.

    Hope these hints are of any help.

    Regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Optimization tasks in cycle

    Posted 11/22/10 03:48 PM

    Originally posted by: apscomeup


    Hi trebron!
    Thank you for help! I've just tried in accordance whith you post.

    I define pTest in .mod file like this

    
    
    
    int pTest = ...;
    


    and main flow is, i've tried both to define
    
    data.pTest = 3;
    
    both before
    
    opl.addDataSource(data);
    
    and after it but the result is the same(as to say what is right before or after adding data source command?):

    Scripting runtime error: cannot add properties to this value, "http://a IloOplMain.IloOplDataSource".

    
    main 
    { 
    
    for (var s = 1; s <= 2; s++) 
    { var source = 
    
    new IloOplModelSource(
    "prtOptim.mod"); var cplex = 
    
    new IloCplex(); var def = 
    
    new IloOplModelDefinition(source); var opl = 
    
    new IloOplModel(def,cplex); var data = 
    
    new IloOplDataSource(
    "prtOptim.dat"); data.pTest = 3; opl.addDataSource(data); 
    //data.pTest = 3; opl.generate(); 
    //opl.nStages=2; 
    //opl.ACTIVESCENES = {1,2,3,4,5}; opl.ACTIVESCENES.add(7); var res = cplex.solve(); writeln(
    "Yeeeh babyMM!"); writeln(res); writeln(opl.ACTIVESCENES); 
    //writeln(cplex.getObjValue()); opl.postProcess(); 
    }; 
    };
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Optimization tasks in cycle

    Posted 11/22/10 04:05 PM

    Originally posted by: SystemAdmin


    Hi,

    The issue you're facing is that you're trying to modify pTest after it was initialized from the .dat.
    What I would recommend is to initialize data that won't change from iterations to the other in your .dat file, and in the script, initialize data like pTest with an
    IloOplDataElements
    
    like this:
    var data2 = new IloOplDataElements();
    data2.pTest=3;
    


    If all your data have to be defined by script, then you no longer need a .dat file and can remove the IloOplDataSource from your script.
    Or if you want to have an initial data in your .dat file, then you after your first solve, you need to retrieve the data elements from the IloOplModel (data2=opl.dataElements) and update the data you want then. The cutstock example delivered with CPLEX Optimization Studio can help understand this methodology.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Optimization tasks in cycle

    Posted 11/23/10 09:58 AM

    Originally posted by: apscomeup


    Thank you, i will study example 'cutstock' more clearly.
    You see i need to load data from access database and simultaneously define some parameters of model in cycle.

    Sorry my English is not very well. As i understand from you post, there is only one way to define data
    1. via .dat file.
    or
    2. in the script.
    if not plese clarify what i should do after defining
    
    data2
    
    the instance of class
    
    IloOplDataElements();
    


    Please give an example using my full script code

    
    main 
    { 
    
    for (var s = 1; s <= 2; s++) 
    { var source = 
    
    new IloOplModelSource(
    "prtOptim.mod"); var cplex = 
    
    new IloCplex(); var def = 
    
    new IloOplModelDefinition(source); var opl = 
    
    new IloOplModel(def,cplex); var data = 
    
    new IloOplDataSource(
    "prtOptim.dat"); opl.addDataSource(data); opl.generate(); 
    //opl.pTest = 3; 
    //opl.ACTIVESCENES = {1,2,3,4,5}; opl.ACTIVESCENES.add(s); var res = cplex.solve(); writeln(
    "Yeeeh babyMM!"); writeln(res); writeln(opl.ACTIVESCENES); 
    //writeln(cplex.getObjValue()); opl.postProcess(); 
    }; 
    };
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer