Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Missing variables with SolveSolution.get_value_dict()?

    Posted 09/16/22 10:49 AM
    Hi everyone,

    I have a docplex model where I create a set of variables using something similar to

    m = Model(...)
    
    # the initial set is not relevant I think
    x = m.continuous_var_dict((k for k in ...), name="x")​
    
    # get a solution
    s = m.solve()


    When I query s for the value of x, one entry is missing. I cannot share the list of keys as it's very large, but basically

    # shows the correct keys, e.g., 10 keys
    print(x.keys())
    
    # some key in x.keys()
    k = ...
    assert k in x  # this is ok
    
    # I can query the value using .get_value(), this returns a very small (negative?) number,
    # e.g., -9.094947017729282e-13 (the value has a 0 lower-bound)
    k_value = s.get_value(x[k])
    
    # I can query the dictionary from x
    x_values = s.get_value_dict(x)
    
    # ...but the key is missing
    assert k in x_values  # this fails


    Any idea why this happens? I tried forcing keep_zeros to True in get_value_dict() (which should already be there since it's the default) but it did not change anything.



    ------------------------------
    Mikaël Capelle
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Missing variables with SolveSolution.get_value_dict()?

    Posted 09/16/22 11:00 AM
    The method signature is

    def get_value_dict(self, var_dict, keep_zeros=True, precision=1e-6)
    I think its semantic is not obvious and trivial. The implementation is buggy here.
    The keep_zeros works only on values which are really 0 or null to keep them or ignore them.
    precision is a way to consider small values as 0 and filter them, but it does not look at keep_zeros.
    That's the reason why your value is ignored.

    Decrease the precision to 1e-13 and it will keep your variable.

    We will correct docplex in a next version about this.

    ------------------------------
    Vincent Beraudier
    ------------------------------