Does pyomo provide access to cplex callbacks?










1














I'm relatively new in Pyomo and I have some problems getting access to the cplex callback for generating user cuts.
I'm using Pyomo 5.5.0 and cplex 12.8.0.0, I've already defined an Abstract model and loaded the data, now I would like to specify the cplex UserCutCallback in order to add user-written cuts during the branch-and-cut search performed by cplex.



I tried the following:



# model definition
model = AbstractModel()
...

# load the instance
instance = model.create_instance(data = 'data.dat')

# the callback that cplex should call during the branch-and-cut search
def cut_callback(solver, model):
print("CB-Cut")

opt = SolverFactory('cplex_direct')
opt.set_callback('cut-callback', cut_callback)


But I got the following error:



~/miniconda3/envs/opt/lib/python3.6/site-packages/pyomo/opt/bas/solvers.py in set_callback(self, name, callback_fn)
815 if not self._allow_callbacks:
816 raise pyutilib.common.ApplicationError(
--> 817 "Callbacks disabled for solver %s" % self.name)
818 if callback_fn is None:
819 if name in self._callback:

ApplicationError: Callbacks disabled for solver cplexdirect


The interface cplex direct works correctly when I do not specify any callbacks, but when I call the method set_callback I got the above error, and so I started wondering if there is a way to get access to the cplex callbacks from pyomo. I really need that!



Is this feature available in pyomo? Am I missing something?



Thanks for your help










share|improve this question





















  • I'm not a pyomo expert, but the error seems to be pretty clear. The cplex_direct solver has an attribute (_allow_callbacks) which is False and when you try to set the callback it tells you that callbacks are not supported. Is there some reason why you don't trust the error? This seems like a question that should really go directly to the developers of pyomo (they must have a forum somewhere). In order to use CPLEX callbacks you may need to consider using either docplex (a Python modeling language provided by IBM) or the CPLEX Python API directly (i.e., the cplex package).
    – rkersh
    Nov 14 '18 at 16:50










  • rkersh, you are right the error is very clear, but the problem is that I wasn't expecting the value False for the attribute _allow_callbacks. I even notice that in the source code there is no method that set _allow_callback to True, and it seems to me that this feature is not implemented. Or maybe I just forgot something that enable the cplex callbacks. The cplex API are a valid alternative but I would like to use pyomo, since I already have my models written with Pyomo. Anyway, If I won't find a way to solve this problem I will consider docplex or the cplex python API. - Thanks, Riccardo
    – Riccardo
    Nov 16 '18 at 9:13















1














I'm relatively new in Pyomo and I have some problems getting access to the cplex callback for generating user cuts.
I'm using Pyomo 5.5.0 and cplex 12.8.0.0, I've already defined an Abstract model and loaded the data, now I would like to specify the cplex UserCutCallback in order to add user-written cuts during the branch-and-cut search performed by cplex.



I tried the following:



# model definition
model = AbstractModel()
...

# load the instance
instance = model.create_instance(data = 'data.dat')

# the callback that cplex should call during the branch-and-cut search
def cut_callback(solver, model):
print("CB-Cut")

opt = SolverFactory('cplex_direct')
opt.set_callback('cut-callback', cut_callback)


But I got the following error:



~/miniconda3/envs/opt/lib/python3.6/site-packages/pyomo/opt/bas/solvers.py in set_callback(self, name, callback_fn)
815 if not self._allow_callbacks:
816 raise pyutilib.common.ApplicationError(
--> 817 "Callbacks disabled for solver %s" % self.name)
818 if callback_fn is None:
819 if name in self._callback:

ApplicationError: Callbacks disabled for solver cplexdirect


The interface cplex direct works correctly when I do not specify any callbacks, but when I call the method set_callback I got the above error, and so I started wondering if there is a way to get access to the cplex callbacks from pyomo. I really need that!



Is this feature available in pyomo? Am I missing something?



Thanks for your help










share|improve this question





















  • I'm not a pyomo expert, but the error seems to be pretty clear. The cplex_direct solver has an attribute (_allow_callbacks) which is False and when you try to set the callback it tells you that callbacks are not supported. Is there some reason why you don't trust the error? This seems like a question that should really go directly to the developers of pyomo (they must have a forum somewhere). In order to use CPLEX callbacks you may need to consider using either docplex (a Python modeling language provided by IBM) or the CPLEX Python API directly (i.e., the cplex package).
    – rkersh
    Nov 14 '18 at 16:50










  • rkersh, you are right the error is very clear, but the problem is that I wasn't expecting the value False for the attribute _allow_callbacks. I even notice that in the source code there is no method that set _allow_callback to True, and it seems to me that this feature is not implemented. Or maybe I just forgot something that enable the cplex callbacks. The cplex API are a valid alternative but I would like to use pyomo, since I already have my models written with Pyomo. Anyway, If I won't find a way to solve this problem I will consider docplex or the cplex python API. - Thanks, Riccardo
    – Riccardo
    Nov 16 '18 at 9:13













1












1








1


1





I'm relatively new in Pyomo and I have some problems getting access to the cplex callback for generating user cuts.
I'm using Pyomo 5.5.0 and cplex 12.8.0.0, I've already defined an Abstract model and loaded the data, now I would like to specify the cplex UserCutCallback in order to add user-written cuts during the branch-and-cut search performed by cplex.



I tried the following:



# model definition
model = AbstractModel()
...

# load the instance
instance = model.create_instance(data = 'data.dat')

# the callback that cplex should call during the branch-and-cut search
def cut_callback(solver, model):
print("CB-Cut")

opt = SolverFactory('cplex_direct')
opt.set_callback('cut-callback', cut_callback)


But I got the following error:



~/miniconda3/envs/opt/lib/python3.6/site-packages/pyomo/opt/bas/solvers.py in set_callback(self, name, callback_fn)
815 if not self._allow_callbacks:
816 raise pyutilib.common.ApplicationError(
--> 817 "Callbacks disabled for solver %s" % self.name)
818 if callback_fn is None:
819 if name in self._callback:

ApplicationError: Callbacks disabled for solver cplexdirect


The interface cplex direct works correctly when I do not specify any callbacks, but when I call the method set_callback I got the above error, and so I started wondering if there is a way to get access to the cplex callbacks from pyomo. I really need that!



Is this feature available in pyomo? Am I missing something?



Thanks for your help










share|improve this question













I'm relatively new in Pyomo and I have some problems getting access to the cplex callback for generating user cuts.
I'm using Pyomo 5.5.0 and cplex 12.8.0.0, I've already defined an Abstract model and loaded the data, now I would like to specify the cplex UserCutCallback in order to add user-written cuts during the branch-and-cut search performed by cplex.



I tried the following:



# model definition
model = AbstractModel()
...

# load the instance
instance = model.create_instance(data = 'data.dat')

# the callback that cplex should call during the branch-and-cut search
def cut_callback(solver, model):
print("CB-Cut")

opt = SolverFactory('cplex_direct')
opt.set_callback('cut-callback', cut_callback)


But I got the following error:



~/miniconda3/envs/opt/lib/python3.6/site-packages/pyomo/opt/bas/solvers.py in set_callback(self, name, callback_fn)
815 if not self._allow_callbacks:
816 raise pyutilib.common.ApplicationError(
--> 817 "Callbacks disabled for solver %s" % self.name)
818 if callback_fn is None:
819 if name in self._callback:

ApplicationError: Callbacks disabled for solver cplexdirect


The interface cplex direct works correctly when I do not specify any callbacks, but when I call the method set_callback I got the above error, and so I started wondering if there is a way to get access to the cplex callbacks from pyomo. I really need that!



Is this feature available in pyomo? Am I missing something?



Thanks for your help







cplex pyomo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 22:30









Riccardo

61




61











  • I'm not a pyomo expert, but the error seems to be pretty clear. The cplex_direct solver has an attribute (_allow_callbacks) which is False and when you try to set the callback it tells you that callbacks are not supported. Is there some reason why you don't trust the error? This seems like a question that should really go directly to the developers of pyomo (they must have a forum somewhere). In order to use CPLEX callbacks you may need to consider using either docplex (a Python modeling language provided by IBM) or the CPLEX Python API directly (i.e., the cplex package).
    – rkersh
    Nov 14 '18 at 16:50










  • rkersh, you are right the error is very clear, but the problem is that I wasn't expecting the value False for the attribute _allow_callbacks. I even notice that in the source code there is no method that set _allow_callback to True, and it seems to me that this feature is not implemented. Or maybe I just forgot something that enable the cplex callbacks. The cplex API are a valid alternative but I would like to use pyomo, since I already have my models written with Pyomo. Anyway, If I won't find a way to solve this problem I will consider docplex or the cplex python API. - Thanks, Riccardo
    – Riccardo
    Nov 16 '18 at 9:13
















  • I'm not a pyomo expert, but the error seems to be pretty clear. The cplex_direct solver has an attribute (_allow_callbacks) which is False and when you try to set the callback it tells you that callbacks are not supported. Is there some reason why you don't trust the error? This seems like a question that should really go directly to the developers of pyomo (they must have a forum somewhere). In order to use CPLEX callbacks you may need to consider using either docplex (a Python modeling language provided by IBM) or the CPLEX Python API directly (i.e., the cplex package).
    – rkersh
    Nov 14 '18 at 16:50










  • rkersh, you are right the error is very clear, but the problem is that I wasn't expecting the value False for the attribute _allow_callbacks. I even notice that in the source code there is no method that set _allow_callback to True, and it seems to me that this feature is not implemented. Or maybe I just forgot something that enable the cplex callbacks. The cplex API are a valid alternative but I would like to use pyomo, since I already have my models written with Pyomo. Anyway, If I won't find a way to solve this problem I will consider docplex or the cplex python API. - Thanks, Riccardo
    – Riccardo
    Nov 16 '18 at 9:13















I'm not a pyomo expert, but the error seems to be pretty clear. The cplex_direct solver has an attribute (_allow_callbacks) which is False and when you try to set the callback it tells you that callbacks are not supported. Is there some reason why you don't trust the error? This seems like a question that should really go directly to the developers of pyomo (they must have a forum somewhere). In order to use CPLEX callbacks you may need to consider using either docplex (a Python modeling language provided by IBM) or the CPLEX Python API directly (i.e., the cplex package).
– rkersh
Nov 14 '18 at 16:50




I'm not a pyomo expert, but the error seems to be pretty clear. The cplex_direct solver has an attribute (_allow_callbacks) which is False and when you try to set the callback it tells you that callbacks are not supported. Is there some reason why you don't trust the error? This seems like a question that should really go directly to the developers of pyomo (they must have a forum somewhere). In order to use CPLEX callbacks you may need to consider using either docplex (a Python modeling language provided by IBM) or the CPLEX Python API directly (i.e., the cplex package).
– rkersh
Nov 14 '18 at 16:50












rkersh, you are right the error is very clear, but the problem is that I wasn't expecting the value False for the attribute _allow_callbacks. I even notice that in the source code there is no method that set _allow_callback to True, and it seems to me that this feature is not implemented. Or maybe I just forgot something that enable the cplex callbacks. The cplex API are a valid alternative but I would like to use pyomo, since I already have my models written with Pyomo. Anyway, If I won't find a way to solve this problem I will consider docplex or the cplex python API. - Thanks, Riccardo
– Riccardo
Nov 16 '18 at 9:13




rkersh, you are right the error is very clear, but the problem is that I wasn't expecting the value False for the attribute _allow_callbacks. I even notice that in the source code there is no method that set _allow_callback to True, and it seems to me that this feature is not implemented. Or maybe I just forgot something that enable the cplex callbacks. The cplex API are a valid alternative but I would like to use pyomo, since I already have my models written with Pyomo. Anyway, If I won't find a way to solve this problem I will consider docplex or the cplex python API. - Thanks, Riccardo
– Riccardo
Nov 16 '18 at 9:13

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271028%2fdoes-pyomo-provide-access-to-cplex-callbacks%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271028%2fdoes-pyomo-provide-access-to-cplex-callbacks%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線