Non-backtracked memory in propagators

12 views
Skip to first unread message

John

unread,
Jun 24, 2022, 8:50:06 AM6/24/22
to Gecode
Hello. I have the following question:

I have a custom propagator which creates some data structures that do not need to be backtracked. This is because some of them are either never modified through the lifetime of the whole search, or some others are modified but it's semantically correct to use their most recent version during search, even after we backtrack. They can be big structures and so I would like to avoid copying them for no reason. Initially I was just placing them on the heap with raw pointers, and in the copy constructor I would copy just the pointer (shallow copy), and in the destructor I would never delete it. While this seems efficient, of course it has the problem of memory leaks. One way to get around it is to use shared_ptr but I noticed a performance drop by this change. Is there any other alternative, or a more "correct" way?

Thank you!

Mikael Zayenz Lagerkvist

unread,
Jun 27, 2022, 3:04:46 AM6/27/22
to gec...@googlegroups.com
HI,

It is quite common to have shared data-structures in Gecode for data
that never changes. Read chapter 31.3 in MPG on shared objects and
handles to see how to handle such data in a structured way that works
well with Gecode.

For data that is changed while being backtrack stable, it is harder to solve.

First of all, shared data needs to handle multi-threaded access.
Perhaps some copy-on-write solution can be used for that, but it very
much depends on the particulars of your data and propagator.

Furthermore, and this is the bigger issue, if the data is only
backtrack stable for direct ancestors of the node that is backtracked
from that is not a concept that Gecode supplies a standard hook for.
What node is next expanded is known only to the search engine, and is
not known by propagators. As far as I know, there is no reasonable way
to get this information from Gecode, which means that you would have
to track it externally somehow.

Cheers,
Mikael
> --
> You received this message because you are subscribed to the Google Groups "Gecode" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gecode+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/gecode/827bc5a2-c4ff-4336-8169-66284b5f874bn%40googlegroups.com.



--
Mikael Zayenz Lagerkvist
Reply all
Reply to author
Forward
0 new messages