Decision Optimization

 View Only

 black_box function

Ross Dye's profile image
Ross Dye posted Sun June 01, 2025 11:12 PM

In docplex cp is it possible to use a user defined function or black_box function in search_phases

I am trying in vain to 'guide' search strategy
The best result i get is simple letting solver decide on variables and values. 
I can see opportunities to improve the result, & consider search_phase & objectives as the likely methods
Is that correct?

Olivier Lhomme's profile image
Olivier Lhomme

Search phases are the simplest and first thing to try. 

Otherwise, sometimes it is possible to decompose the problem, define several solving steps, and use the solution of one step to define the model (or just the starting point) of the following step. 

If you have a precise solving strategy that cannot be expressed with such simple approaches and which is expected to work very well for your problem, you may need to use custom goals, available only in C++ API. Nevertheless, note that the use of custom goals is quite rare today as it is generally hard to beat the solver default search. 

PhR's profile image
PhR

CP Optimizer proposes several levels of search guidance.
In all cases, using runseeds to average performance over 10 to 30 runs is mandatory to evaluate the effects on performance.

  1. Use parameters tuning. 
  2. Use Search Phases to order groups of variables to instantiate.
  3. Use Search Phases to decide how to select and instantiate a variable in a group by using predefined selectors (this is for integer models only, not scheduling ones).
    Black boxes functions cannot be used for evaluating variables in search phases, it is for model expressions only.
  4. Define your own selectors (this is available in C++ only and for integer models only, not scheduling ones).
  5. Define your own search with goals (in C++ only). This is a very advanced usage. When using search phases the search of CP Optimizer is used and it is based on advanced techniques like branch and bound, local search, portfolios of strategies, parallelism and many others. When moving to goals you lose all this and the effort to make an efficient search can be high.