Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

OplDataHandler StartElement for indexed array

  • 1.  OplDataHandler StartElement for indexed array

    Posted Wed September 28, 2011 06:16 PM

    Originally posted by: alex.filipovik


    In my model I have:
    range myRange = 1..10;
    float myArrmyRange = ...;

    In my code I have:
    public class MyDataHandler : CustomOplDataSource
    {
    public MyDataSource(OplFactory oplFactory) : base(oplFactory)
    {
    }

    public override void CustomRead()
    {
    DataHandler.StartElement("myArr");
    DataHanlder.StartIndexedArray();
    DataHandler.SetItemIntIndex(1);
    DataHandler.SetIntItem(1);
    ...
    DataHandler.EndIndexedArray();
    DataHandler.EndElement();
    }
    }

    An exception "no refcounter: calling on bad env" is thrown on DataHandler.StartElement("myArr") call.
    Please tell me what's wrong with my code?

    Thank you,
    Alex
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: OplDataHandler StartElement for indexed array

    Posted Thu September 29, 2011 02:51 PM

    Originally posted by: alex.filipovik


    In my code I have:
    Cplex cplex = new Cplex();

    It should be replaced with:
    Cplex cplex = oplFactory.CreateCplex();
    where oplFactory is OplFactory properly initialized.

    This resolves the issue with initializing arrays. It's strange that it allowed to initialize integers, floats, and sets, but it was failing only on arrays.
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: OplDataHandler StartElement for indexed array

    Posted Fri September 30, 2011 04:24 AM

    Originally posted by: rdumeur


    Dear Alex,

    You found the right way to create the Cplex object. The Cplex object is special in that the Cplex factory performs memory related initializations that are required for it object to work properly. Note that this is the "OPL using CP Optimizer forum", and your question would have been more quickly processed on the CPLEX forum: http://www.ibm.com/developerworks/forums/forum.jspa?forumID=2059

    Cheers,
    #DecisionOptimization
    #OPLusingCPOptimizer