Skip to content

Visitor object is copied #1

@CodeFinder2

Description

@CodeFinder2

Hi!

First of all: great work!

I am using your algorithm (as part of the boost library) very similiar to the example in hawick_circuits.cpp. The problem is that I am storing additional state in my (modified) cycle_printer struct and that state does not seem to change or, more precisely, the changes do not seem to persist/survive the call: boost::hawick_circuits(graph, visitor). More specifically, I am analyzing the detected cycles in my visitor and if a certain type of cycle is detected, I am setting a member variable within the cycle_printe::cycle() method to true. After running the algorithm, that variable is still false (as initialized in my visitor's constructor).

After taking a look at the source code, it seems that this line may cause this issue. Is it intended that the visitor parameter is passed by value (as even stated in the code comment) and not by reference (&)? Do you know whether it is safe to simply change this to create a call by reference here, like (see 63009c7):

void call_hawick_circuits(Graph const& graph,
                          Visitor& visitor,
                          VertexIndexMap const& vertex_index_map) { ... }

? IMHO, the fact that a visitor survives a call of the associated algorithm is one of the advantages of having a "stateful callback" (= visitor) in general.

If this is really a bug, it should also be fixed in the boost implemenation. ;-)

Glad to hear your opinion on that, thanks you!

Edit: I just tested this fix and it seems to work fine.

Edit2: Would it be possible to let cycle_printer::cycle() return a boolean indicating whether to continue (true) or to abort (false) the search for elementary circuits? Would allow an early-abort which is useful in many situations. I guess this line would need an update, correct? However, a simple return true doesn't seem to be enough :-D (since there's more logic "above" circuit() that needs to be aborted as well).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions