简体   繁体   中英

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??

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
"""

To complement Alex's answer: in Docplex, Model.export_as_lp(path'c:/temp/mymodel.lp') is the way to generate a LP file from you Docplex model. In Cplex's Python API, you have a Cplex instance, use cpx.write('c:/temp/mymodel_cplex.lp') to generate the LP files.

If your models are identical, then both LP files should also be identical (except maybe some differences in variable ordering, eg x2+x1 instead of x1+x2). If you need to work the same model both APIs, then you must first reach this equality before going further.

DOcplex has tools to investigate infeasible models, but there is no point until you ensure both models are identical.

Something must be different between the two versions. You can use refine_conflict to know the source of infeasibility

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM