Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Bug in Docplex logical_and ?

    Posted 08/22/19 03:02 PM

    Originally posted by: Hans Kirchner


    Hi, I'm currently trying out Python+Docplex and when I'm executing the following code it's gives me "status = integer infeasible".

    But I think c must be 0 and this is clearly feasible, right?

     

    from docplex.mp.model import Model

    m = Model("test")

    a = m.binary_var(name="a")
    b = m.binary_var(name="b")
    c = m.binary_var(name="c")

    m.add_constraint(m.logical_and(a, b) == c)
    m.add_constraint(a == 1)
    m.add_constraint(b == 0)

    if m.solve():
        m.print_solution(print_zeros=True)
    else:
        print(m.solve_details)

     

    Version Info:

    - Python 3.6.8

    - docplex 2.10.154

    - CPLEX Studio 12.9 (academic)


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Bug in Docplex logical_and ?

    Posted 08/23/19 07:03 AM

    I'm afraid you have indeed hit on a bug in docplex (I have filed a bug report). You can do m.export_as_lp('and.lp') and then look at the generated LP file. You will see that the constraints generated are incorrect.

    You can use this function as replacement:

    def logical_and(mdl, bins):
        '''Create an expression that is 1 if and only if all
        binaries in `bins` are 1.'''
        if len(bins) == 0:
            return 1
        y = mdl.binary_var()
        # If y=1 then all x must be 1
        mdl.add_constraints(y <= x for x in bins)
        # If all x are 1 then y must be 1
        mdl.add_constraint(mdl.sum(bins) - y <= len(bins) - 1)
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Bug in Docplex logical_and ?

    Posted 08/23/19 08:20 AM

    Originally posted by: Hans Kirchner


    Thanks for the workaround and for filing a bug report!

     

    However, it leaves me with a weird feeling that such a "fundamental" function is not working.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Bug in Docplex logical_and ?

    Posted 08/30/19 12:07 PM

    Originally posted by: Hans Kirchner


    This is fixed in docplex version 2.10.155 as of Aug 27, 2019. Thanks!
    #CPLEXOptimizers
    #DecisionOptimization