Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

OplDataElement with tuple variable

  • 1.  OplDataElement with tuple variable

    Posted Thu November 22, 2018 01:49 PM

    Originally posted by: AndyHam


    Dear IBM,
    I am trying to add an OplDataElement. When I tried a single integer variable for OplDataElement, it worked great. But, when I tried a tuple, it generates the following error: "Cannot use type string for …". Would you please see if how we can make the following illustration code work?

     

    //Test_Sub.mod

    tuple t_A2B {

      key int a;

      key int b;

    } {t_A2B} A2B=...;

    dexpr int Makespan  = sum(ab in A2B) ab.a*ab.b;

    minimize Makespan;

    subject to {};

     

    //main.mod

    main {

      var source = new IloOplModelSource("Test_Sub.mod");

      var def = new IloOplModelDefinition(source);

      var opl = new IloOplModel(def,cplex);

      var data= new IloOplDataElements();

      data.A2B= "{<1 1> <2 4>}";

      opl.addDataSource(data);  

      opl.generate();

      cplex.solve(); 

    }


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: OplDataElement with tuple variable

    Posted Mon November 26, 2018 02:16 AM

    Hi,

    I would rather write

     tuple t_A2B {

      key int a;

      key int b;

    } {t_A2B} s;
     
     
     main {

      var source = new IloOplModelSource("Test_Sub.mod");

      var def = new IloOplModelDefinition(source);

      var opl = new IloOplModel(def,cplex);

      var data= new IloOplDataElements();

      //data.A2B= "{<1 1> <2 4>}";
      data.A2B=thisOplModel.s;
    data.A2B.add(1,1);
    data.A2B.add(2,4);

      opl.addDataSource(data);  

      opl.generate();

      cplex.solve();
      opl.postProcess();

    }

     

    and you could read that at

    https://www.ibm.com/developerworks/community/forums/html/threadTopic?id=5b68f185-2132-4296-9ea4-a4d128937d65&ps=25

    which is part of

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

    regards

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: OplDataElement with tuple variable

    Posted Mon November 26, 2018 08:55 AM

    Originally posted by: AndyHam


    Thanks! You don't know how many times you saved me from the project failure. I am currently working with an industry to deploy a real-time scheduling system based on CP optimizer.
     


    #DecisionOptimization
    #OPLusingCPOptimizer