Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Custom Data Source Array and TupleSet

    Posted 02/19/18 09:06 PM

    Originally posted by: llDubs


    Hi,

    I've been trying to modify the custom interface .NET example found below to read in my data from an Access database. 

    https://github.com/IBMDecisionOptimization/OPL-.net-custom-data-source

     

    The example is great for reading in Sets or Tuple Sets.  However, I am trying to read in a set of tuples into an array indexed by a set of strings:

    {string} worker = {"worker1", "worker2"};

     

     tuple Break{
      int s;
      int e; 
     };

     

    {Break} work_break[worker] = ...;

     

    In the dat file, I would load it as something like this:  

    work_break =#["worker1: {<1,4>, <10, 14>},
                    "worker2": {<1, 8>} ]#;

     

    I've stored the data in my database with column names worker, s and e.

    So to read in the data to work_break, I can see that the OplElementDefinitionType.Type = 'Array" but I'm not quite sure how to read in each tuple set and match it up with appropriate index of the array in .NET.  Could someone please point me in right direction?   

     

    Thanks for the help.

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Custom Data Source Array and TupleSet

    Posted 02/20/18 02:33 AM

    Hi,

    once you have the tuple set it is quite easy to get the array you need:

    .mod

    tuple t
    {
    string name;
    int st;
    int en;
    }

    {t} raw_work_break = ...;

     {string} worker = {i.name | i in raw_work_break};

     
     tuple Break{
      int s;
      int e;
     };

     

    {Break} work_break[w in worker] = {<i.st,i.en> | i in raw_work_break : i.name==w};

    execute
    {
    writeln(work_break);
    }

    .dat

    raw_work_break ={
     <"worker1", 1,4>,
     <"worker1", 10,14>,
    <"worker2", 1,8>
                    
    };
      

    gives

     [{<1 4> <10 14>} {<1 8>}]

    regards

     

    https://www.linkedin.com/pulse/how-opl-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Custom Data Source Array and TupleSet

    Posted 02/20/18 03:03 PM

    Originally posted by: llDubs


    Hi Alex,

    Thanks so much for the speedy response. I really appreciate it.  I had thought of that as a workaround and will probably go with it but I am still quite curious about reading directly into arrays for two reasons.  

     

    1)  I'd like to better understand the best way to structure and store more complex data structures and have the ability to access the data as needed.   Perhaps loading data directly into an array is not the recommended approach and there are some best practices that I should be following but it would give me more flexibility for the future.

     

    2)  In generally, I'm struggling to understand the data structure hierarchy in .NET in order to customize the example code as needed.  For example, if my element is of type array, how can I access the set it's indexed by and the tuple sets that are stored in there.  Sorry, I'm not very experienced in .NET development so I'm learning it out of necessity.  I've tried to to reference the IBM documentation but I'm just missing some conceptual understanding about the data structures that is making the documentation not very helpful just yet.  

     

    Thanks,

    Leah


    #DecisionOptimization
    #OPLusingCPLEXOptimizer