Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Using ISolution when Model is read from .mod File

  • 1.  Using ISolution when Model is read from .mod File

    Posted 09/15/14 07:50 AM

    Originally posted by: jako123


    Hi,

    use the .Net Inteface and read my model directly from  a .mod File written in OPL. I add my data as objects by implementing the CustomOplDataSource class and overriding the CustomRead methods. This works all perfect and my model is solved. I can write the solution to a streamwriter using the PrintSolution method of the OplModel class, but I want my solution as a C# object.

    Can anybody tell me what to do? Do I need to implement the ISolution interface? Does anybody have sample code?

    many thanks in advance

     

    Jana

     

     


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Using ISolution when Model is read from .mod File

    Posted 09/17/14 05:25 AM

    Originally posted by: ArnaudS


    Hi
     
    You can access the solution through the OplModel.
    For example, if you have following decision variables:
        dvar int slot[Slots] in AllConfs;
        dvar int lastSlot in nbCars..nbSlots;
    
     
    After the solve, to retrieve the values, you can use:
    int lastSlot = opl.GetElement("lastSlot").AsInt();
     Console.Out.WriteLine("lastSlotValue = " + lastSlot);
       
     IIntMap slot = opl.GetElement("slot").AsIntMap();
     IIntRange slots = opl.GetElement("Slots").AsIntRange();
     for( IEnumerator e = slots.GetEnumerator(); e.MoveNext(); ) {
     
           Console.Out.Write(slot.Get((int)e.Current) + " ");
     }
    
     
    Hope this helps,
     
    Regards,
    Arnaud

    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Using ISolution when Model is read from .mod File

    Posted 09/17/14 08:25 AM

    Originally posted by: jako123


    Hi Arnaud,

     

    this helps a lot. My dvar is 2-dimensional array.

    dvar int  job[c in Cabins][j in Calls] in 0..bound

    I get it as an IIntMap perfectly.

     IIntMap job = opl.GetElement("job").AsIntMap();

    Can you show me a code sample how to enumerate the IntMape elements correctly?

    many thanks in advance

     

    Jana

     


    #CPOptimizer
    #DecisionOptimization