Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/02/12 08:52 PM

    Originally posted by: SystemAdmin


    I'am didn't find documentation or example on how to alter a integer dataElement with an Interface (API C# or Java).

    I use the mulprod_main exemple to show my problem.

    OPL Parameters:
    int NbPeriods = ...;
    float CapacityResources = ...;

    OPL Script data element
    var data = produce.dataElements;

    In OPL script, I can alter a parameter value this way:

    For array or int:
    data.Capacity = capFlour;
    For int:
    data.NbPeriods=3;

    With the API.

    For array of float I can do it this way:
    dataElements.GetElement("Capacity").AsNumMap().Set("flour", capFlour);

    For integer, I can't figure how to do the same operation. My problem is that this didn't work:
    dataElements.GetElement("NbPeriods").AsInt().Set(2);

    The solution is probably obvious but I didn't find anything about that in the documentation or in the examples.

    Thank you in advance,

    MB
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/04/12 08:01 AM
    Hi

    I think that your issue is that

    AsInt()

    gives a value and not a reference.
    You should change your int value into an array and then you will able to use

    AsIntMap()

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/04/12 11:28 AM

    Originally posted by: SystemAdmin


    If I treat the integer as an integer array of one by doing that:

    dataElements.GetElement("NbPeriods").AsIntMap().Set(0,2);

    I receive the following error:

    Type attendu pour l'élément "int". (type for element « int »).

    à ILOG.OPL.opl_lang_wrap.SWIGIloExceptionHelper.ThrowIloException(String message)
    à ILOG.OPL.opl_lang_wrapPINVOKE.OplElement_cpp_asIntMap(IntPtr jarg1)
    à ILOG.OPL.OplElement.cpp_asIntMap()
    à ILOG.OPL.OplElement.AsIntMap()
    à Mulprod_main.Mulprod_main.Main(String[] args) dans C:\Program Files\ibm\ILOG\CPLEX_Studio124\opl\examples\opl_interfaces\dotnet\x86_windows_vs2010\CSharp\Mulprod_main\Mulprod_main.cs:ligne 63
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/05/12 04:23 AM
    Hi,

    you should also change NBPeriods from an int to an array in your OPL model

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/05/12 09:54 AM

    Originally posted by: SystemAdmin


    This mean that we can't change a parameter define by an int :
    int NbPeriods = ...;
    with the API in C# or Java?

    MB
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/06/12 01:41 PM

    Originally posted by: SystemAdmin


    This is covered in one of IBM technotes:
    http://www-01.ibm.com/support/docview.wss?uid=swg21401478
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/24/13 03:17 AM

    Originally posted by: CplexUser1453


    So if I understand this thread, the tech note and the mulprod example correctly, you can update non integer data directly, while with integer data it is impossible, is that correct?

    To give an example :

    ...

    model.generate()

    var def = thisOplModel.modelDefinition;
    var dataLocal =  thisOplModel.dataElements;

    dataLocal.myArray[i] = x // possible

    dataLocal.myIntValue = y // impossible

    newModel = new IloOplModel(def,cplex);

    newModel.addDataSource(dataLocal);

    I understand that there is a work around with .dat files as explained in the tech note but I find it a little bit painful...  Please correct me if what I wrote above is wrong.

    Thanks!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/24/13 05:24 AM

    Hi,

     

    do you intend to use javascript API ?

    You have an example of both scalar and not scalar update at

    https://www.ibm.com/developerworks/community/forums/html/topic?id=84f171d3-48fe-4d6a-bfed-5d0837185b5e&ps=25

    is there something there that cannot fit your need ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/24/13 08:27 AM

    Originally posted by: CplexUser1453


    Hello Alex

    Yes your response was very helpful, I forgot to thank you once saw it a couple of weeks ago.

    If I understood your example and the link provided above correctly, in order to modify a scalar element it is necessary to create a new data object, (var data2= new IloOplDataElements()  )and copy the data that is unchanged (data2.y=thisOplModel.s). The alternative is to have a separate data file with elements that change to create separate data objects that can be modified before calling the generate() method. Is that right?

    Copying works fine if the amount of data that is unchanged is small. Unfortunately in my case I have only one integer data element that changes and dozens of various data elements that do not change.

    I just wanted to make sure I understood this point correctly - OPL is an amazing tool that allows the modeler great flexibility and productivity in model development. I was a little bit surprised that this kind of operation is this difficult compared to other nice features in OPL...


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: How to alter a integer dataElement with an Interface (API C# or Java)

    Posted 09/24/13 09:20 AM

    Hi,

    for the same model you may have some data handled by

    data2= new IloOplDataElements() and the rest in the .dat

    You are not limited to having everything in the .dat or everything in the "new IloOplDataElements()"

     

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer