I'm trying to use the user cut or lazy cut to solve my problem. But I find out the callback function will never be run during the solving. So I test an simple example, which is learned from sc_script example.
I'm expecting to get at least one print out from three callback functions, but I don't.
from pyomo.core import *
model = AbstractModel(name="Master")
model.x = Var(within=Integers, bounds=(0,2))
model.y = Var(within=Integers, bounds=(0,2))
def min_obj_rule(model):
return model.y
model.oMaster = Objective(rule=min_obj_rule,sense=minimize)
def solve_callback(solver, test_inst ):
print "CB-Solve"
def cut_callback(solver, test_inst ):
print "CB-Cut"
def node_callback(solver, test_inst ):
print "CB-Node"
opt = SolverFactory('_cplex_direct')
opt.set_callback('cut-callback', cut_callback)
opt.set_callback('node-callback', node_callback)
opt.set_callback('solve-callback', solve_callback)
results = opt.solve(test_inst , tee=True)
print results
==========results============
Warning: Control callbacks may disable some MIP features.
CPXPARAM_Read_DataCheck 1
CPXPARAM_Read_APIEncoding "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP 0
Found incumbent of value 0.000000 after 0.00 sec. (0.00 ticks)
Root node processing (before b&c):
Real time = 0.00 sec. (0.00 ticks)
Sequential b&c:
Real time = 0.00 sec. (0.00 ticks)
------------
Total (root+branch&cut) = 0.00 sec. (0.00 ticks)
Problem:
- Name:
Lower bound: None
Upper bound: None
Number of objectives: 1
Number of constraints: 0
Number of variables: 2
Number of binary variables: 0
Number of integer variables: 2
Number of continuous variables: 0
Number of nonzeros: None
Sense: unknown
Solver:
- Name: CPLEX 12.7.1.0
Status: ok
Return code: None
Message: None
User time: 0.0
System time: None
Wallclock time: None
Termination condition: optimal
Termination message: None
Solution:
- number of solutions: 0
number of solutions displayed: 0