docplex

Obtaining different solutions on solving a cplex model many times

喜你入骨 提交于 2021-02-11 17:38:43
问题 I have an MIP model written with docplex and a solution pool written with cplex. My model has billions of solutions in reality. I need to solve this model several times (10 for example) with a certain populate number (10,000 for example) but I need the solutions of these multiple solves to be entirely different than each other. How can I achieve that with cplex? Is there a parameter or a approach for it? 回答1: You can use a diversity filter for the solution pool, see CPLEX > User's Manual for

how to write a conditional constraint in CPLEX python?

前提是你 提交于 2021-02-11 12:12:34
问题 I have a model that has one binary variable x [i] [j] [k]. I need to add a constraint that fullfils this condition: if x[i][j][k1]==1 and x[j][i][k2]==1 Then: k2-k1>8 I have this code but I assum it is not correct : mdl.add((y[(i,j,k)]+y[(j,i,k1)]==2),(k1-k>8) ) I also, put this: mdl.add(mdl.if_then(y[(i,j,k1)]+y[(j,i,k2)]==2, k2-k1>8)) but I got this error: raise DOcplexException(resolved_message) DOcplexException: Expecting linear constraint, got: False How can I model this with cplex

How to use Continuous Variables for IF-THEN constraints on DOCPLEX (Python)?

随声附和 提交于 2021-02-10 14:27:43
问题 I'm using DOCPLEX to build up a Mixed Integer Linear Programming (MILP) problem which is then solved via CPLEX on Python. However, upon trying to solve the MILP problem using IF-THEN constraints, I receive the following error: DOcplexException: Model.if_then(), nbBus40 >= 3.0 is not discrete This is happening because I have declared nbbus40 variable to be continuous , as shown in the code below: from docplex.mp.model import Model mdl = Model(name='buses') nbbus40 = mdl.continuous_var(name=

How to use Continuous Variables for IF-THEN constraints on DOCPLEX (Python)?

[亡魂溺海] 提交于 2021-02-10 14:27:01
问题 I'm using DOCPLEX to build up a Mixed Integer Linear Programming (MILP) problem which is then solved via CPLEX on Python. However, upon trying to solve the MILP problem using IF-THEN constraints, I receive the following error: DOcplexException: Model.if_then(), nbBus40 >= 3.0 is not discrete This is happening because I have declared nbbus40 variable to be continuous , as shown in the code below: from docplex.mp.model import Model mdl = Model(name='buses') nbbus40 = mdl.continuous_var(name=

Cplex solution pool generates duplicate solutions

流过昼夜 提交于 2021-01-28 04:33:12
问题 I put this question on IBM forum, since nobody responded I am going to ask here. I have an MIP model written with docplex and a solution pool that populates a massive number of solutions. My problem is, when my solution pool finishes most of the solutions are duplicated. In 1000 solutions there are only 4 unique solutions. I don't understand how and why this happens. My solution pool settings is below: cpx = mdl.get_cplex() cpx.parameters.mip.pool.intensity.set(4) cpx.parameters.mip.pool

Implementing TSP with Lazy constraint callback

笑着哭i 提交于 2020-04-18 06:53:11
问题 I am trying to TSP with Lazy constraint callback. From Answer given here and here, I have tried to use the code from the links and was able to add the call back function. Now I am struggling with add_lazy_constraints . Here is my current code: It is a 9 Node TSP. import docplex.mp.model as cpx from cplex.callbacks import LazyConstraintCallback from docplex.mp.callbacks.cb_mixin import * class DOLazyCallback(ConstraintCallbackMixin, LazyConstraintCallback): def __init__(self, env):

TSP implementation in docplex python

久未见 提交于 2020-04-18 02:34:12
问题 Is there any python implementation available of TSP using the IBM cplex tool, with Dantzig-Fulkerson-Johnson formulation. If there is any can I get the link for it? 回答1: The exact same question was asked here. Here is my (slightly modified) answer from there: The distribution does not have an example implementation in Python, but there is one in OPL: opl/examples/opl/models/TravelingSalesmanProblem/tsp.mod in your installation. This could serve as a good starting point when implementing

Cplex Error: Adding trivial infeasible linear constraint

杀马特。学长 韩版系。学妹 提交于 2020-04-17 19:05:31
问题 I want to solve an integer programming model with cplex python. I have this model: a and h are matrixes with 0s and 1s. p is a set of numbers. here is a part of my cplex code for this model: p=[i for i in range (len(h))] x=mdl.binary_var_dict(p,name='x') #objective mdl.minimize(0) #constraints #1 mdl.add_constraints(mdl.sum(h[i][k]*x[i] for i in p)==4 for k in T) #2 mdl.add_constraints(mdl.sum(a[i][k]*x[i] for i in p)==4 for k in T) mdl.print_information() Solution = mdl.solve(log_output

How to initiate the interval variable bounds in docplex (python)?

£可爱£侵袭症+ 提交于 2020-02-06 07:43:10
问题 I have the following OPL code and need to implement it in docplex (python), i'm newbie in that field... using CP; dvar interval I1 in 0..20; dvar interval I2 in 0..20; dvar interval I3 in 0..20; dvar int over1; dvar int start1; dvar int end1; dvar interval artificialInterval; maximize over1; subject to { over1==overlapLength(I1,I2); start1==maxl(startOf(I1),startOf(I2)); end1==minl(endOf(I1),endOf(I2)); startOf(artificialInterval)==start1; endOf(artificialInterval)==end1; over1==overlapLength

model.solve() method is not working (“CPLEX DLL not found”) for DOcplex for Python

爱⌒轻易说出口 提交于 2020-01-15 06:24:08
问题 I build my mathematical model using DOcplex IBM package for Python. I am sure that the other part of the modeling is correct, however when the call to Model.solve() is executed, and I get the following error: "CPLEX DLL not found: please provide DOcplexcloud credentials" I have CPLEX Studio 12.6 installed on my pc, and I want to solve the problem locally not on cloud. 回答1: It sounds like you do not have the CPLEX Python API "installed". By default, when you install CPLEX Optimization Studio