Originally posted by: SinaF
Hi,
I used to work with Gurobi-python interface to solve my optimization problem and I have recently switched to CPLEX python API. I want to add some lazy constraints through callback function. In Gurobi, once a MIP solution is found, I can check a condition and if it is necessary, I will add the lazy constraints. The only example of callback function for CPLEX python API is as follows:
class BendersLazyConsCallback(LazyConstraintCallback):
def __call__(self):
x = self.x
workerLP = self.workerLP
numNodes = len(x)
# Get the current x solution
sol = []
for i in range(numNodes):
sol.append([])
sol[i] = self.get_values(x[i])
# Benders' cut separation
if workerLP.separate(sol, x):
self.add(constraint=workerLP.cutLhs,
sense="G",
rhs=workerLP.cutRhs)
Now, I have some basic questions:
1- Do I have to define a class?
2- What is 'self' here?
3- How can I make sure that this function is called when a MIP solution is found?
4- Can I simply call this function as model.solve(callback)?
I appreciate your help in advance.
#CPLEXOptimizers#DecisionOptimization