Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Decision variable (or expression) not allowed.

    Posted 07/09/17 02:49 AM

    Originally posted by: JuanIgnacioAdame


    I'm pretty new to OPL, and recently I've been trying to write a simple .mod that I can use to solve quadratic unconstrained binary optimization (QUBO) problems.  Here is the script:

     

    int num_logical_variables = ...;

    range Logical_variables = 1..num_logical_variables;

    float Q[Logical_variables][Logical_variables] = ...;

    dvar int x[Logical_variables] in 0..1;

    dexpr float Energy = sum(j in Logical_variables, i in Logical_variables) (Q[j][i]*x[j]*x[i]);

    maximize Energy;

    // Post processing
    tuple result {
      float energy;
    }
    result energy = <Energy>;

     

    However, I am getting the error "Decision variable (or expression) "Energy" not allowed" and I am not sure why.  Could anyone help me with this?

     

    Thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Decision variable (or expression) not allowed.

    Posted 07/09/17 03:28 AM

    Hi,

    you seem to miss a subject to block

    Can you replace

    maximize Energy;

    by

    maximize Energy;

    subject to
    {

    }

    ?

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Decision variable (or expression) not allowed.

    Posted 07/09/17 03:50 AM

    Originally posted by: JuanIgnacioAdame


    That indeed seems to have helped!  However, now I have a different error coming from my .dat file:

    time_limit = 9223372036854775807;
    num_logical_variables = 10;
    Q = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]];

     

    I get "Element "time_limit" not defined."

     

    Thanks for your help!


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Decision variable (or expression) not allowed.

    Posted 07/09/17 04:23 AM

    Hi,

    you simply need to add

    int time_limit = ...;

    in your .mod

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Decision variable (or expression) not allowed.

    Posted 07/09/17 10:38 AM

    Originally posted by: JuanIgnacioAdame


    Alright, things seems to be working pretty well now; thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Decision variable (or expression) not allowed.



  • 7.  Re: Decision variable (or expression) not allowed.

    Posted 07/09/17 11:11 AM

    Originally posted by: JuanIgnacioAdame


    Thanks again, will definitely keep those links in mind for general troubleshooting in the future.

     

    I actually have another question in the meantime.  I've managed to get the optimal value of the objective function printed, but I don't know how to print the actual solution itself.  So far I have:

     

    tuple solution {
        int solution;
    }

    {solution} Solution = {<x[j]> | j in Logical_variables};

    It should be a vector of size |Logical_variables|, but in fact it's only returning a single scalar.  Do you know what I could be doing wrong?

     

    Thanks again.


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Decision variable (or expression) not allowed.

    Posted 07/09/17 11:58 AM

    Hi,

    execute
    {
    writeln("Solution=",Solution);
    writeln("x=",x);
    }

    will give

    Solution= {<1>}
    x= [1 1 1 1 1 1 1 1 1 1]

    which looks normal.

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Decision variable (or expression) not allowed.

    Posted 07/10/17 05:26 AM

    Originally posted by: JuanIgnacioAdame


    Thanks again for these very quick and helpful responses!


    #CPLEXOptimizers
    #DecisionOptimization