Search code examples
python-3.xcplexdocplex

IBM cplex ilog VS docplex in python


Currently, I'm working on docplex on python.

I just found out that result from IBM cplex Ilog and docplex is way different.

Even though their constraints, objective function, everything are identical, their solution is very different.

In some cases, docplex says infeasible even though it is feasible in Ilog.

I tried to limit integrality and minimum gap in docplex tolerances but the same problem happens.

Is there anyone have idea why this happens? and how to solve this??


Solution

  • In order to understand what is different you could export models in a lp file.

    See

    mdl.export("c:\\temp\\buses.lp")
    

    in

    from docplex.mp.model import Model
    
    mdl = Model(name='buses')
    nbbus40 = mdl.integer_var(name='nbBus40')
    nbbus30 = mdl.integer_var(name='nbBus30')
    mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
    mdl.minimize(nbbus40*500 + nbbus30*400)
    
    mdl.solve()
    
    mdl.export("c:\\temp\\buses.lp")
    
    for v in mdl.iter_integer_vars():
        print(v," = ",v.solution_value)
    
    
    """
    which gives
    nbBus40  =  6.0
    nbBus30  =  2.0
    """