This is more cargo cult programming than anything, as this is not super well documented, but...
Reading through routing.cc and searching for max_callback_cache_size
, it is clear that the cache size is really just used to set a boolean:
cache_callbacks_ = (nodes_ <= parameters.max_callback_cache_size());
So the max callback cache size has to be bigger than the number of nodes.
Later, the actual cache size used is (nodes + number of vehicles)^2:
if (cache_callbacks_) {
const int size = Size() + vehicles();
std::vector<int64_t> cache(size * size, 0);
So just in case the developers "fix" this inconsistency and the boolean check changes in a future version, and because I really want caching to always happen, I generally do (in python)
model_parameters = pywrapcp.DefaultRoutingModelParameters()
model_parameters.max_callback_cache_size = 2 * num_nodes * num_nodes
This should turn on caching of all of your callback functions in the dimension definitions. I have never noticed an issue with RAM doing this, and I am not sure why it is not the default always, as the improvement in running time is massive.
Regards,
James
-- You received this message because you are subscribed to the Google Groups "or-tools-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/2a03b31b-6fb0-4e75-b329-a8ccf324f658n%40googlegroups.com.
Thank you so much James!
On Thursday, July 14, 2022 at 5:47:17 PM UTC+3 blind.lin...@gmail.com wrote:This is more cargo cult programming than anything, as this is not super well documented, but...
Reading through routing.cc and searching for
max_callback_cache_size
, it is clear that the cache size is really just used to set a boolean:cache_callbacks_ = (nodes_ <= parameters.max_callback_cache_size());
So the max callback cache size has to be bigger than the number of nodes.
Later, the actual cache size used is (nodes + number of vehicles)^2:
if (cache_callbacks_) { const int size = Size() + vehicles(); std::vector<int64_t> cache(size * size, 0);
So just in case the developers "fix" this inconsistency and the boolean check changes in a future version, and because I really want caching to always happen, I generally do (in python)
model_parameters = pywrapcp.DefaultRoutingModelParameters() model_parameters.max_callback_cache_size = 2 * num_nodes * num_nodes
This should turn on caching of all of your callback functions in the dimension definitions. I have never noticed an issue with RAM doing this, and I am not sure why it is not the default always, as the improvement in running time is massive.
Regards,
James
On Nov 30, 2022, at 11:53, Fernanda Bia Peteam <fernand...@gmail.com> wrote:
I tried to work with max_callback_cache_size but I got "AttributeError: Protocol message RoutingSearchParameters has no "max_callback_cache_size" field"
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/69f793c7-fd73-49d2-9fdd-05b0b67b9a5en%40googlegroups.com.