Topic
  • 2 replies
  • Latest Post - ‏2012-12-08T21:01:30Z by mrmag
mrmag
mrmag
28 Posts

Pinned topic fractional variable having discrete values

‏2012-12-06T09:23:17Z |
Hello!

I have a IloNumVar v which can get only a certain set of values like: v \in {v_1, ..., v_n}.

Is it possible to make v as decision variable? What is the best way of modeling v (fractional but having discrete values) in CP Optimizer?

Best regards
Updated on 2012-12-08T21:01:30Z at 2012-12-08T21:01:30Z by mrmag
  • SystemAdmin
    SystemAdmin
    554 Posts

    Re: fractional variable having discrete values

    ‏2012-12-06T10:29:33Z  
    Hello,
    You could use as decision variable an index of the values of v and use an element expression Val[x] to get the value:

    
    
    
    float Val[i in 1..n] = ...; 
    // Val[i]=v_i dvar int+ x in 1..n; dexpr 
    
    float v = Val[x];
    


    Of course, if there is a more direct link between index i and value v_i, you can use a specific expression. Example if v \in { 0.1, 0.2, 0.3, 0.4, ..., 0.9, 1.0 }:

    
    dvar int+ x in 1..10; dexpr 
    
    float v = x/10.0;
    


    Philippe
  • mrmag
    mrmag
    28 Posts

    Re: fractional variable having discrete values

    ‏2012-12-08T21:01:30Z  
    Hello,
    You could use as decision variable an index of the values of v and use an element expression Val[x] to get the value:

    <pre class="jive-pre"> float Val[i in 1..n] = ...; // Val[i]=v_i dvar int+ x in 1..n; dexpr float v = Val[x]; </pre>

    Of course, if there is a more direct link between index i and value v_i, you can use a specific expression. Example if v \in { 0.1, 0.2, 0.3, 0.4, ..., 0.9, 1.0 }:

    <pre class="jive-pre"> dvar int+ x in 1..10; dexpr float v = x/10.0; </pre>

    Philippe
    That works very well. Thank you.