I would update the code for obtaining a subgraph here:
from
for node_id, node in self.graph.nodes.items():
if solution[node_selected[node_id]]:
selected_graph.add_node(node_id, node)
for edge_id, edge in self.graph.edges.items():
if solution[edge_selected[edge_id]]:
selected_graph.add_edge(edge_id, edge)
to become,
for node_id, node in self.graph.nodes.items():
if solution[node_selected[node_id]] > 0.5:
selected_graph.add_node(node_id, node)
for edge_id, edge in self.graph.edges.items():
if solution[edge_selected[edge_id]] > 0.5:
selected_graph.add_edge(edge_id, edge)
Since the selected subgraph at times can skip a few nodes and edges if the solution indicator value on them is not exactly 1 but is 1.0000002etc.
I would update the code for obtaining a subgraph here:
from
to become,
Since the selected subgraph at times can skip a few nodes and edges if the solution indicator value on them is not exactly
1
but is1.0000002
etc.