Decision Optimization

 View Only
  • 1.  read a nested tuple input from python into OPL (doopl)

    Posted Fri July 10, 2020 01:51 AM
    I have a nested list of tuples defined in python, and I want to feed this to the .mod file of OPL. I am getting an error while doing so. Could you please refer to the below code snippet. Thanks 
    from doopl.factory import *

    // nested tuple list
    test = [((1,2),"Q"),((3,4),"R")]

    with create_opl_model(model="test.mod") as opl:
    opl.set_input("test", test)

    // followed by other code (excluding it for now)
    // following is starting few lines of the .mod file
    tuple tup1 {
       int a;
       int b;   
     }
      
    tuple nested_tup {
       tup1 x;
       string y;
     }
     
    {nested_tup} test = ...;
    // excluding other parts of the file
    ​​​​​​

    ------------------------------
    Bhartendu Awasthi
    ------------------------------

    #DecisionOptimization


  • 2.  RE: read a nested tuple input from python into OPL (doopl)

    Posted Sat July 11, 2020 02:32 AM
    Hi,

    I am not sure that s supported yet.
    So in the meantime you could transform your nested tupleset into a flat tuple set:

    test = [((1,2),"Q"),((3,4),"R")]
    test2=[ [i[0][0],i[0][1],i[1]] for i in test]
    
    print(test2)​
    which gives

    [[1, 2, 'Q'], [3, 4, 'R']]​

    and then you rely on the tuple set input for doopl

    regards

    PS: better doopl is already a wish in https://ibm-data-and-ai.ideas.aha.io/?project=CPLEX

    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 3.  RE: read a nested tuple input from python into OPL (doopl)

    Posted Sat July 11, 2020 03:47 AM
    Thank you Alex !

    ------------------------------
    Bhartendu Awasthi
    ------------------------------