Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

getting elements from an instance of IloOplModel in form of an array

  • 1.  getting elements from an instance of IloOplModel in form of an array

    Posted Thu May 21, 2009 07:14 AM

    Originally posted by: SystemAdmin


    [rahul.raghuromeo said:]

    Hi all,
          I have stuck into a problem and want to get elements out of IloOplModel in form of an array

    code snippet is:-



    IloIntArray imAssignments = mdlRouting.getElement("TruckJob2").asIntArray();



    TruckJob2 is a 3d array of the form TruckJob2[trucks][Jobs][Jobs]

    or is there any other way to get elemets of the 3d array??? please help.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: getting elements from an instance of IloOplModel in form of an array

    Posted Thu May 21, 2009 04:41 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    HI,

    you should use asIntMap
    then IloIntMap as API (get and getSub) to dig into dimensions and access elements using all kinds of indexs (i.e. int, float, strings...)

    Alain
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: getting elements from an instance of IloOplModel in form of an array

    Posted Mon May 25, 2009 06:53 AM

    Originally posted by: SystemAdmin


    [rahul.raghuromeo said:]

    How to get elements from a 3d array like this TruckJob2[trucks][Jobs][Jobs] where 2nd & 3rd dimension are same

    code snippet is:-

    for (int i=1; i<=imAssignments.getSize(); i++) {<br />
    // Get allocation this truck
    IloIntMap imTruckAssignments = imAssignments.getSub(dataElems.getElement("Trucks").asTupleSet().makeTuple(i-1));

    for (int j=1; j<=imTruckAssignments.getSize(); j++) {<br />
                    IloIntMap imJob1Assignments = imTruckAssignments.getSub(dataElems.getElement("Jobs").asTupleSet().makeTuple(j-1));

    for( int k=1; k<=imJob1Assignments.getSize(); k++ ) {<br />
    //IloIntMap imJob2Assignments = imJob1Assignments.get(dataElems.getElement("Jobs").asTupleSet().makeTuple(k-1));

    if (imJob1Assignments.get(dataElems.getElement("Jobs").asTupleSet().makeTuple(k-1))==1) {
    cout << "Truck: " << dataElems.getElement("Trucks").asTupleSet().makeTuple(i-1).getStringValue("rego") << "\t";
    cout << "Job1: " << dataElems.getElement("Jobs").asTupleSet().makeTuple(j-1).getIntValue("number") << "\t";
    cout << "Job1: " << dataElems.getElement("Jobs").asTupleSet().makeTuple(j-1).getIntValue("size") << "\t" << "followed by" ;
    cout << "Job2: " << dataElems.getElement("Jobs").asTupleSet().makeTuple(k-1).getIntValue("number") << "\t";
    cout << "Job2: " << dataElems.getElement("Jobs").asTupleSet().makeTuple(k-1).getIntValue("size") << "\t" << endl;<br /> }
    cout << imJob1Assignments.get(dataElems.getElement("Jobs").asTupleSet().makeTuple(k-1)) <<"rahul \n" ;<br /> }
    }
    //getchar();
    cout << "end of truck:" << i << "*********************" <<endl;<br />
    }



    where:-
    imAssignments:- total 3d map of all assignments representing TruckJob2
    imTruckAssignments:- 2d map of a particular truck assignments
    imJob1Assignments:- 1d map of a particular truck and job TruckJob2[trucks][Jobs]

    now when I am trying to print the value of elements of the 3d array truckjobs nothing is printed out. Even the line
    ##cout << imJob1Assignments.get(dataElems.getElement("Jobs").asTupleSet().makeTuple(k-1)) <<"rahul \n" ;## which is out of If statement is not printed. I doubt wheather it goes in the loop iterated by k.<br />
    Is it the 2nd and 3rd dimension of the TruckJob2 (which are same), who are causing the problem??? Please tell how to handle this kind of 3d array

    Please Help.....really need to work this out for my project
    #DecisionOptimization
    #OPLusingCPLEXOptimizer