ATLAS Offline Software
Loading...
Searching...
No Matches
JunctionAwareVisitor Class Reference

#include <FPGATrackSimGNNRoadMakerTool.h>

Inheritance diagram for JunctionAwareVisitor:
Collaboration diagram for JunctionAwareVisitor:

Public Member Functions

 JunctionAwareVisitor (int &current, std::vector< int > &in_control_vars, std::vector< std::vector< int > > &in_comps, std::unordered_map< Vertex, std::vector< Vertex > > &in_pred_map, ColorMap in_cmap)
template<typename VertexT, typename GraphT>
void discover_vertex (VertexT v, const GraphT &g)
template<typename EdgeT, typename GraphT>
void examine_edge (EdgeT e, const GraphT &g)
template<typename VertexT, typename GraphT>
void process_edges (VertexT src, VertexT tar, const GraphT &g)

Private Attributes

int & m_current_comp
std::vector< int > & m_control_vars
std::vector< std::vector< int > > & m_components
std::unordered_map< Vertex, std::vector< Vertex > > & m_pred_map
int m_initial_comp
ColorMap m_color_map
int m_n_iter = 1

Detailed Description

Definition at line 116 of file FPGATrackSimGNNRoadMakerTool.h.

Constructor & Destructor Documentation

◆ JunctionAwareVisitor()

JunctionAwareVisitor::JunctionAwareVisitor ( int & current,
std::vector< int > & in_control_vars,
std::vector< std::vector< int > > & in_comps,
std::unordered_map< Vertex, std::vector< Vertex > > & in_pred_map,
ColorMap in_cmap )

Definition at line 291 of file FPGATrackSimGNNRoadMakerTool.cxx.

292 :
293 m_current_comp(in_current), m_control_vars(in_control_vars), m_components(in_comps),
294 m_pred_map(in_pred_map), m_initial_comp(in_current), m_color_map(in_cmap) {}
std::unordered_map< Vertex, std::vector< Vertex > > & m_pred_map
std::vector< std::vector< int > > & m_components

Member Function Documentation

◆ discover_vertex()

template<typename VertexT, typename GraphT>
void JunctionAwareVisitor::discover_vertex ( VertexT v,
const GraphT & g )

Definition at line 297 of file FPGATrackSimGNNRoadMakerTool.cxx.

298{
299 if (m_control_vars[v] == -1){
300 m_control_vars[v] = boost:: out_degree(v,g) < 2 ? 1 : -2; // -2 labels junctions before they are transversed
301 m_components[v].push_back(m_current_comp);
302 }
303}

◆ examine_edge()

template<typename EdgeT, typename GraphT>
void JunctionAwareVisitor::examine_edge ( EdgeT e,
const GraphT & g )

Definition at line 306 of file FPGATrackSimGNNRoadMakerTool.cxx.

307{
308 auto src_node = source(e,g);
309 auto tar_node = target(e,g);
310 m_pred_map[tar_node].push_back(src_node);
311 process_edges(src_node, tar_node, g);
312
313 // If target node was already visited, propagate the component also to the nodes it is connected to
314 if ((get(m_color_map, tar_node) == boost::black_color) && (boost::out_degree(tar_node, g) > 0)){
315 m_control_vars[tar_node] = boost:: out_degree(tar_node,g) < 2 ? 1 : -2;
316 auto out_edges = boost::out_edges(tar_node, g);
317 for (auto it = out_edges.first; it != out_edges.second; ++ it){
318 Vertex next_dst = target(*it, g);
319 process_edges(tar_node, next_dst, g);
320 }
321 }
322}
boost::graph_traits< boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS > >::vertex_descriptor Vertex
void process_edges(VertexT src, VertexT tar, const GraphT &g)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130

◆ process_edges()

template<typename VertexT, typename GraphT>
void JunctionAwareVisitor::process_edges ( VertexT src,
VertexT tar,
const GraphT & g )

Definition at line 325 of file FPGATrackSimGNNRoadMakerTool.cxx.

325 {
326 std::vector<int> src_comp; // Store the components of the source that need to be tracked
327
328 for(int comp : m_components[src_node]){
329 if(comp >= m_initial_comp &&
330 std::find(m_components[tar_node].begin(), m_components[tar_node].end(), comp) == m_components[tar_node].end()){
331 src_comp.push_back(comp); // Components of source node not in target
332 }
333 }
334
335 // No junction case
336 if (m_control_vars[src_node] == 1){
337 m_components[tar_node].insert(m_components[tar_node].end(), src_comp.begin(), src_comp.end());
338 m_control_vars[tar_node] = boost::out_degree(tar_node, g) < 2 ? 1 : -2;
339 }
340
341 // First time visiting a junction
342 else if (m_control_vars[src_node] == -2){
343 m_components[tar_node].insert(m_components[tar_node].end(), src_comp.begin(), src_comp.end());
344 m_control_vars[tar_node] = boost::out_degree(tar_node, g) < 2 ? 1 : -2;
345 m_control_vars[src_node] = 2; // 2 labels a junction after the first visit to it
346 m_n_iter = src_comp.size(); // Number of indices to add to each component going out of this junction
347 }
348
349 // Going through a junction already visited
350 else if (m_control_vars[src_node] == 2){
351 for(int i = 0; i != m_n_iter; ++i){
353 m_components[tar_node].push_back(m_current_comp);
354 m_control_vars[tar_node] = boost::out_degree(tar_node, g) < 2 ? 1 : -2;
355 // Backtrace the node's predecessors to propagate the new label
356 std::unordered_set<Vertex> visited;
357 std::function<void(Vertex)> backtrace = [&](Vertex node){
358 if(visited.count(node)) return;
359 visited.insert(node);
360 const auto& node_comps = m_components[node];
361 if((std::find(node_comps.begin(), node_comps.end(), m_current_comp) == node_comps.end()) &&
362 (src_comp.empty() || std::find(node_comps.begin(), node_comps.end(), src_comp[i]) != node_comps.end())){ // Backpropagate with junction awareness
363 m_components[node].push_back(m_current_comp);
364 }
365 for (const auto& pred : m_pred_map[node]){
366 backtrace(pred);
367 }
368 };
369 backtrace(tar_node);
370 }
371 }
372}
list backtrace
Definition check_log.py:58

Member Data Documentation

◆ m_color_map

ColorMap JunctionAwareVisitor::m_color_map
private

Definition at line 137 of file FPGATrackSimGNNRoadMakerTool.h.

◆ m_components

std::vector<std::vector<int> >& JunctionAwareVisitor::m_components
private

Definition at line 134 of file FPGATrackSimGNNRoadMakerTool.h.

◆ m_control_vars

std::vector<int>& JunctionAwareVisitor::m_control_vars
private

Definition at line 133 of file FPGATrackSimGNNRoadMakerTool.h.

◆ m_current_comp

int& JunctionAwareVisitor::m_current_comp
private

Definition at line 132 of file FPGATrackSimGNNRoadMakerTool.h.

◆ m_initial_comp

int JunctionAwareVisitor::m_initial_comp
private

Definition at line 136 of file FPGATrackSimGNNRoadMakerTool.h.

◆ m_n_iter

int JunctionAwareVisitor::m_n_iter = 1
private

Definition at line 138 of file FPGATrackSimGNNRoadMakerTool.h.

◆ m_pred_map

std::unordered_map<Vertex, std::vector<Vertex> >& JunctionAwareVisitor::m_pred_map
private

Definition at line 135 of file FPGATrackSimGNNRoadMakerTool.h.


The documentation for this class was generated from the following files: