we add an objective and a new constraint and then we solve """ from docplex.cp.model import CpoModel from doopl.factory import * # Create an OPL model from a .mod file with create_opl_model(model="zoooplschedulingwithoutobjective.mod") as opl: # Generate the problem and solve it. opl.run() mdl = CpoModel(name='buses') mdl.import_model("zoooplschedulingwithoutobj.cpo") vars = mdl.get_all_variables() bus40 = [] bus30 = [] for i in vars: print(i.name) if ("roundTrip" in i.name) and ("500" in i.name): bus40.append(i) if ("roundTrip" in i.name) and ("400" in i.name): bus30.append(i) #add docplex objective mdl.minimize(500*sum(mdl.presence_of(b40) for b40 in bus40) +\
we add an objective and a new constraint and then we solve """ from docplex.cp.model import CpoModel from doopl.factory import * # Create an OPL model from a .mod file with create_opl_model(model="zoooplwithoutobjectivecpo.mod") as opl: # Generate the problem and solve it. opl.run() mdl = CpoModel(name='buses') mdl.import_model("zoowithoutobj.cpo") vars = mdl.get_all_variables() for i in vars: print(i.name) if (i.name == "nbBus40"): nbbus40 = i if (i.name == "nbBus30"): nbbus30 = i #add docplex constraint mdl.add(nbbus40 <= 4) #add docplex objective mdl.minimize(nbbus40 * 500 + nbbus30 * 400)