PandA-2024.02
graph.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
41 #ifndef GRAPH_HPP
42 #define GRAPH_HPP
43 
45 #include "edge_info.hpp"
46 #include "graph_info.hpp"
47 #include "node_info.hpp"
48 
50 #include <fstream>
51 #include <ostream>
52 
54 #include "custom_set.hpp"
55 #include <deque>
56 #include <list>
57 
59 #include "exceptions.hpp"
60 #include "refcount.hpp"
61 #include <boost/config.hpp>
62 #include <boost/graph/adjacency_list.hpp>
63 #include <boost/graph/breadth_first_search.hpp>
64 #include <boost/graph/filtered_graph.hpp>
65 #include <boost/graph/graph_utility.hpp>
66 #include <boost/graph/graphviz.hpp>
67 #include <boost/graph/strong_components.hpp>
68 #include <boost/graph/topological_sort.hpp>
69 #include <boost/version.hpp>
70 #include <utility>
71 
86 
87 using boost_raw_graph =
88  boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS,
89  boost::property<boost::vertex_index_t, std::size_t, NodeInfoRef>, EdgeInfoRef, GraphInfoRef>;
90 
91 struct RawGraph : public boost_raw_graph
92 {
93  public:
98  explicit RawGraph(GraphInfoRef g_info)
99  {
100  (*this)[boost::graph_bundle] = g_info;
101  }
102 
106  ~RawGraph() = default;
107 
108  inline boost::graph_traits<boost_raw_graph>::vertex_descriptor AddVertex(const NodeInfoRef v_info)
109  {
110  size_t index = boost::num_vertices(*this);
111  boost::graph_traits<boost_raw_graph>::vertex_descriptor new_v = boost::add_vertex(*this);
112  (*this)[new_v] = v_info;
113  boost::get(boost::vertex_index_t(), *this)[new_v] = index;
114  return new_v;
115  };
116 
117  inline void RemoveVertex(boost::graph_traits<boost_raw_graph>::vertex_descriptor v)
118  {
119  boost::remove_vertex(v, *this);
121  boost::get(boost::vertex_index_t(), *this);
122  boost::graph_traits<boost_raw_graph>::vertex_iterator v_it, v_it_end;
123  size_t index = 0;
124  for(boost::tie(v_it, v_it_end) = boost::vertices(*this); v_it != v_it_end; v_it++, index++)
125  {
126  index_map[*v_it] = index;
127  }
128  }
129 
130  inline boost::graph_traits<boost_raw_graph>::edge_descriptor
131  AddEdge(boost::graph_traits<boost_raw_graph>::vertex_descriptor src,
132  boost::graph_traits<boost_raw_graph>::vertex_descriptor tgt, const EdgeInfoRef e_info)
133  {
134  boost::graph_traits<boost_raw_graph>::edge_descriptor e;
135  bool found;
136  boost::tie(e, found) = boost::edge(src, tgt, *this);
137  THROW_ASSERT(not found, "Trying to insert an already existing edge");
138  boost::tie(e, found) = boost::add_edge(src, tgt, e_info, *this);
139  (*this)[e] = e_info;
140  return e;
141  }
142 
143  inline void RemoveEdge(boost::graph_traits<boost_raw_graph>::edge_descriptor e)
144  {
145  boost::remove_edge(boost::source(e, *this), boost::target(e, *this), *this);
146  }
147 
148  inline void RemoveEdge(boost::graph_traits<boost_raw_graph>::vertex_descriptor src,
149  boost::graph_traits<boost_raw_graph>::vertex_descriptor tgt)
150  {
151  boost::graph_traits<boost_raw_graph>::edge_descriptor e;
152  bool found;
153  boost::tie(e, found) = boost::edge(src, tgt, *this);
154  THROW_ASSERT(found, "Edge not found");
155  boost::remove_edge(boost::source(e, *this), boost::target(e, *this), *this);
156  }
157 };
158 
166 template <class info_object, class Graph>
167 info_object* get_raw_edge_info(typename boost::graph_traits<Graph>::edge_descriptor e, Graph& g)
168 {
170  EdgeInfoRef& info = g[e];
171  if(!info)
172  {
173  info = EdgeInfoRef(new info_object);
174  }
175  THROW_ASSERT(GetPointer<info_object>(info) != nullptr,
176  "Function get_raw_edge_info: the edges associated with the graph used are not derived from "
177  "info_object\n\tCheck the actual type of info_object and the type of the edge of Graph");
178  return GetPointer<info_object>(info);
179 }
187 template <class info_object, class Graph>
188 const info_object* Cget_raw_edge_info(typename boost::graph_traits<Graph>::edge_descriptor e, const Graph& g)
189 {
190  const EdgeInfo* info = g[e].get();
191  THROW_ASSERT(!info || dynamic_cast<const info_object*>(info) != nullptr,
192  "Function Cget_raw_edge_info: the edges associated with the graph used are not derived from "
193  "info_object\n\tCheck the actual type of info_object and the type of the edge of Graph");
194  return info ? dynamic_cast<const info_object*>(info) : nullptr;
195 }
196 
197 #define GET_RAW_EDGE_INFO(data, edge_info, edge_index) get_edge_info<edge_info>(edge_index, *(data))
198 
199 #define CGET_RAW_EDGE_INFO(data, edge_info, edge_index) Cget_edge_info<edge_info>(edge_index, *(data))
200 
205 {
206  public:
208  int selector;
209 
212 
216  EdgeProperty() : selector(0)
217  {
218  }
219 
224  explicit EdgeProperty(int _selector) : selector(_selector)
225  {
226  }
227 
232  EdgeProperty(const int _selector, EdgeInfoRef _info) : selector(_selector), info(_info)
233  {
234  }
235 };
236 #if BOOST_VERSION >= 104600
237 using boost_graphs_collection = boost::adjacency_list<
238  boost::listS, boost::listS, boost::bidirectionalS,
239  boost::property<boost::vertex_index_t, std::size_t,
240  boost::property<boost::vertex_color_t, boost::default_color_type, NodeInfoRef>>,
242 
243 using undirected_boost_graphs_collection = boost::adjacency_list<
244  boost::listS, boost::listS, boost::undirectedS,
245  boost::property<boost::vertex_index_t, std::size_t,
246  boost::property<boost::vertex_color_t, boost::default_color_type, NodeInfoRef>>,
248 
249 #define boost_CGetOpGraph_property(graph_arg) (graph_arg)[boost::graph_bundle]
250 
251 #else
252 
259 {
261  typedef boost::graph_property_tag kind;
262 };
263 
264 typedef boost::property<graph_info_t, GraphInfoRef> GraphProperty;
265 
266 typedef boost::adjacency_list<
267  boost::listS, boost::listS, boost::bidirectionalS,
268  boost::property<boost::vertex_index_t, std::size_t,
269  boost::property<boost::vertex_color_t, boost::default_color_type, NodeInfoRef>>,
272 
273 typedef boost::adjacency_list<
274  boost::listS, boost::listS, boost::undirectedS,
275  boost::property<boost::vertex_index_t, std::size_t,
276  boost::property<boost::vertex_color_t, boost::default_color_type, NodeInfoRef>>,
279 
280 #define boost_CGetOpGraph_property(graph_arg) boost::get_property(graph_arg, graph_info_t())
281 
282 #endif
283 
288 {
289  public:
292 
297  graphs_collection(GraphInfoRef info, const ParameterConstRef _parameters) : parameters(_parameters)
298  {
299  boost_CGetOpGraph_property(*this) = info;
300  }
301 
303  virtual ~graphs_collection() = default;
304 
310  inline boost::graph_traits<graphs_collection>::edge_descriptor
311  AddSelector(const boost::graph_traits<graphs_collection>::edge_descriptor edge, const int selector)
312  {
313  (*this)[edge].selector |= selector;
314  return edge;
315  }
316 
322  inline boost::graph_traits<graphs_collection>::edge_descriptor
323  AddSelector(const boost::graph_traits<graphs_collection>::vertex_descriptor source,
324  const boost::graph_traits<graphs_collection>::vertex_descriptor target, const int selector)
325  {
326  boost::graph_traits<graphs_collection>::edge_descriptor edge;
327  bool inserted;
328  boost::tie(edge, inserted) = boost::edge(source, target, *this);
329  THROW_ASSERT(inserted, "Edge not found");
330  AddSelector(edge, selector);
331  return edge;
332  }
333 
338  inline void RemoveSelector(boost::graph_traits<graphs_collection>::edge_descriptor edge)
339  {
340  (*this)[edge].selector = 0;
341  }
342 
348  inline void RemoveSelector(boost::graph_traits<graphs_collection>::edge_descriptor edge, const int selector)
349  {
350  (*this)[edge].selector = (*this)[edge].selector & ~selector;
351  }
352 
356  inline void RemoveSelector(boost::graph_traits<graphs_collection>::vertex_descriptor source,
357  boost::graph_traits<graphs_collection>::vertex_descriptor target, const int selector)
358  {
359  boost::graph_traits<graphs_collection>::edge_descriptor edge;
360  bool inserted;
361  boost::tie(edge, inserted) = boost::edge(source, target, *this);
362  THROW_ASSERT(inserted, "Edge not found");
363  RemoveSelector(edge, selector);
364  }
365 
371  inline int GetSelector(const edge_descriptor e) const
372  {
373  return (*this)[e].selector;
374  }
375 
381  virtual boost::graph_traits<boost_graphs_collection>::vertex_descriptor AddVertex(const NodeInfoRef info);
382 
391  inline boost::graph_traits<graphs_collection>::edge_descriptor
392  AddEdge(boost::graph_traits<graphs_collection>::vertex_descriptor,
393  boost::graph_traits<graphs_collection>::vertex_descriptor, const int)
394  {
395  THROW_UNREACHABLE("This function should be overriden by derived classes");
396  return boost::graph_traits<graphs_collection>::edge_descriptor();
397  }
398 
407  inline boost::graph_traits<graphs_collection>::edge_descriptor
408  InternalAddEdge(boost::graph_traits<graphs_collection>::vertex_descriptor source,
409  boost::graph_traits<graphs_collection>::vertex_descriptor target, const int selector,
410  const EdgeInfoRef info)
411  {
412  boost::graph_traits<graphs_collection>::edge_descriptor edge;
413  bool inserted;
414  boost::tie(edge, inserted) = boost::edge(source, target, *this);
415  THROW_ASSERT(not inserted, "Trying to add an already existing edge");
416  boost::add_edge(source, target, EdgeProperty(selector), *this);
417  boost::tie(edge, inserted) = boost::edge(source, target, *this);
418  AddSelector(source, target, selector);
419  (*this)[edge].info = info;
420  return edge;
421  }
422 
427  virtual void RemoveVertex(boost::graph_traits<boost_graphs_collection>::vertex_descriptor v);
428 
435  inline bool ExistsEdge(const boost::graph_traits<graphs_collection>::vertex_descriptor source,
436  const boost::graph_traits<graphs_collection>::vertex_descriptor target) const
437  {
438  boost::graph_traits<graphs_collection>::edge_descriptor edge;
439  bool inserted;
440  boost::tie(edge, inserted) = boost::edge(source, target, *this);
441  return inserted;
442  }
443 
444  inline void CompressEdges()
445  {
446  std::deque<boost::graph_traits<graphs_collection>::edge_descriptor> toBeRemoved;
447  boost::graph_traits<graphs_collection>::edge_iterator ei0, ei0_end;
448  for(boost::tie(ei0, ei0_end) = boost::edges(*this); ei0 != ei0_end; ++ei0)
449  {
450  if((*this)[*ei0].selector == 0)
451  {
452  toBeRemoved.push_back(*ei0);
453  }
454  }
455  for(auto e0 : toBeRemoved)
456  {
457  boost::remove_edge(e0, *this);
458  }
459  }
460 };
461 
463 
468 {
470  undirected_graphs_collection() = default;
471 
473  ~undirected_graphs_collection() = default;
474 
479  inline boost::graph_traits<undirected_boost_graphs_collection>::vertex_descriptor AddVertex()
480  {
481  size_t index = boost::num_vertices(*this);
482  boost::graph_traits<undirected_boost_graphs_collection>::vertex_descriptor v = boost::add_vertex(*this);
483  boost::get(boost::vertex_index_t(), *this)[v] = index;
484  return v;
485  }
486 
491  inline void RemoveVertex(boost::graph_traits<undirected_boost_graphs_collection>::vertex_descriptor v)
492  {
493  boost::remove_vertex(v, *this);
495  boost::get(boost::vertex_index_t(), *this);
496  boost::graph_traits<undirected_boost_graphs_collection>::vertex_iterator v_it, v_it_end;
497  size_t index = 0;
498  for(boost::tie(v_it, v_it_end) = boost::vertices(*this); v_it != v_it_end; v_it++, index++)
499  {
500  index_map[*v_it] = index;
501  }
502  }
503 
509  inline int GetSelector(const edge_descriptor e) const
510  {
511  return (*this)[e].selector;
512  }
513 
519  inline void SetSelector(edge_descriptor e, const int selector)
520  {
521  (*this)[e].selector = selector;
522  }
523 };
524 
526 
534 template <class info_object, class Graph>
535 NodeInfoRef& Cget_node_infoRef(typename boost::graph_traits<Graph>::vertex_descriptor v, Graph& g)
536 {
537  NodeInfoRef& info = g[v];
538  if(!info)
539  {
540  info = NodeInfoRef(new info_object);
541  }
542  return info;
543 }
544 
552 template <class info_object, class Graph>
553 void set_node_info(typename boost::graph_traits<Graph>::vertex_descriptor v, const refcount<info_object>& obj, Graph& g)
554 {
555  NodeInfoRef& info = g[v];
556  info = obj;
557 }
558 
559 #define SET_NODE_INFO_REF(data, NodeInfo, obj, vertex_index) set_node_info<NodeInfo>(vertex_index, obj, *(data))
560 
561 #define GET_NODE_INFO_REF(data, NodeInfo, vertex_index) Cget_node_infoRef<NodeInfo>(vertex_index, *(data))
562 
570 template <class info_object, class Graph>
571 info_object* get_node_info(typename boost::graph_traits<Graph>::vertex_descriptor v, Graph& g)
572 {
573  NodeInfoRef& info = g[v];
574  if(!info)
575  {
576  info = NodeInfoRef(new info_object);
577  }
578  THROW_ASSERT(GetPointer<info_object>(info) != nullptr,
579  "Function get_node_info: the vertices associated with the graph used are not derived from "
580  "info_object\n\tCheck the actual type of info_object and the type of the node of Graph");
581  return GetPointer<info_object>(info);
582 }
583 
591 template <class info_object, class Graph>
592 const info_object* Cget_node_info(typename boost::graph_traits<Graph>::vertex_descriptor v, const Graph& g)
593 {
594  const NodeInfo* info = g[v].get();
595  THROW_ASSERT(!info || dynamic_cast<const info_object*>(info) != nullptr,
596  "Function Cget_node_info: the nodes associated with the graph used are not derived from "
597  "info_object\n\tCheck the actual type of info_object and the type of the node of Graph");
598  return info ? dynamic_cast<const info_object*>(info) : nullptr;
599 }
600 
601 #define GET_NODE_INFO(data, NodeInfo, vertex_index) get_node_info<NodeInfo>(vertex_index, *(data))
602 
603 #define CGET_NODE_INFO(data, NodeInfo, vertex_index) Cget_node_info<NodeInfo>(vertex_index, *(data))
604 
612 template <class info_object, class Graph>
613 info_object* get_edge_info(typename boost::graph_traits<Graph>::edge_descriptor e, Graph& g)
614 {
616  EdgeInfoRef& info = g[e].info;
617  if(!info)
618  {
619  info = EdgeInfoRef(new info_object);
620  }
621  THROW_ASSERT(GetPointer<info_object>(info) != nullptr,
622  "Function get_edge_info: the edges associated with the graph used are not derived from "
623  "info_object\n\tCheck the actual type of info_object and the type of the edge of Graph");
624  return GetPointer<info_object>(info);
625 }
633 template <class info_object, class Graph>
634 const info_object* Cget_edge_info(typename boost::graph_traits<Graph>::edge_descriptor e, const Graph& g)
635 {
636  const EdgeInfo* info = g[e].info.get();
637  THROW_ASSERT(!info || dynamic_cast<const info_object*>(info) != nullptr,
638  "Function Cget_edge_info: the edges associated with the graph used are not derived from "
639  "info_object\n\tCheck the actual type of info_object and the type of the edge of Graph");
640  return info ? dynamic_cast<const info_object*>(info) : nullptr;
641 }
642 
643 #define GET_EDGE_INFO(data, edge_info, edge_index) get_edge_info<edge_info>(edge_index, *(data))
644 
645 #define CGET_EDGE_INFO(data, edge_info, edge_index) Cget_edge_info<edge_info>(edge_index, *(data))
646 
650 template <typename Graph>
652 {
653  private:
655  bool all;
656 
659 
660  public:
664  SelectVertex() : all(true), subset()
665  {
666  }
667 
672  explicit SelectVertex(const CustomUnorderedSet<typename boost::graph_traits<Graph>::vertex_descriptor>& _subset)
673  : all(false), subset(_subset)
674  {
675  }
676 
682  bool operator()(const typename boost::graph_traits<Graph>::vertex_descriptor& v) const
683  {
684  if(all)
685  {
686  return true;
687  }
688  else
689  {
690  return (subset.find(v) != subset.end());
691  }
692  }
693 };
694 
698 template <typename Graph>
700 {
701  private:
703  int selector;
704 
707 
710 
712  bool empty;
713 
714  public:
718  SelectEdge() : selector(0), g(nullptr), subgraph_vertices(), empty(true)
719  {
720  }
721 
727  SelectEdge(const int _selector, Graph* _g) : selector(_selector), g(_g), subgraph_vertices(), empty(true)
728  {
729  }
730 
737  SelectEdge(const int _selector, Graph* _g,
738  const CustomUnorderedSet<typename boost::graph_traits<Graph>::vertex_descriptor>& _subgraph_vertices)
739  : selector(_selector), g(_g), subgraph_vertices(_subgraph_vertices), empty(false)
740  {
741  }
742 
743  template <typename Edge>
744  bool operator()(const Edge& e) const
745  {
746  if(empty)
747  {
748  return selector & (*g)[e].selector;
749  }
750  else
751  {
752  typename boost::graph_traits<Graph>::vertex_descriptor u, v;
753  u = boost::source(e, *g);
754  v = boost::target(e, *g);
755  if((selector & (*g)[e].selector) && subgraph_vertices.find(v) != subgraph_vertices.end() &&
756  subgraph_vertices.find(u) != subgraph_vertices.end())
757  {
758  return true;
759  }
760  else
761  {
762  return false;
763  }
764  }
765  }
766 };
767 
771 struct graph : public boost::filtered_graph<boost_graphs_collection, SelectEdge<boost_graphs_collection>,
772  SelectVertex<boost_graphs_collection>>
773 {
774  protected:
780  inline const NodeInfoConstRef
781  CGetNodeInfo(typename boost::graph_traits<graphs_collection>::vertex_descriptor node) const
782  {
783  const NodeInfoRef info = (*this)[node];
784  THROW_ASSERT(info, "Node without associate info");
785  return info;
786  }
787 
794  inline EdgeInfoRef GetEdgeInfo(typename boost::graph_traits<graphs_collection>::vertex_descriptor source,
795  typename boost::graph_traits<graphs_collection>::vertex_descriptor target)
796  {
797  bool found;
798  typename boost::graph_traits<graphs_collection>::edge_descriptor edge;
799  boost::tie(edge, found) = boost::edge(source, target, *this);
800  THROW_ASSERT(found, "Edge not present in the graph");
801  return GetEdgeInfo(edge);
802  }
803 
810  inline const EdgeInfoConstRef
811  CGetEdgeInfo(typename boost::graph_traits<graphs_collection>::vertex_descriptor source,
812  typename boost::graph_traits<graphs_collection>::vertex_descriptor target) const
813  {
814  bool found;
815  typename boost::graph_traits<graphs_collection>::edge_descriptor edge;
816  boost::tie(edge, found) = boost::edge(source, target, *this);
817  THROW_ASSERT(found, "Edge not present in the graph");
818  return CGetEdgeInfo(edge);
819  }
820 
826  inline EdgeInfoRef GetEdgeInfo(typename boost::graph_traits<graphs_collection>::edge_descriptor edge) const
827  {
828  const EdgeInfoRef info = (*this)[edge].info;
829  THROW_ASSERT(info, "Info not associated with the edge");
830  return info;
831  }
832 
838  inline EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits<graphs_collection>::edge_descriptor edge) const
839  {
840  const EdgeInfoConstRef info = (*this)[edge].info;
841  THROW_ASSERT(info, "Info not associated with the edge");
842  return info;
843  }
844 
847 
849  const int selector;
850 
858  template <typename VertexWriterTemplate, typename EdgeWriterTemplate, typename GraphWriterTemplate>
859  void InternalWriteDot(const std::string& file_name, const VertexWriterConstRef vertex_writer,
860  const EdgeWriterConstRef edge_writer, const GraphWriterConstRef graph_writer) const
861  {
862  std::ofstream file_stream(file_name.c_str());
863  boost::write_graphviz(file_stream, *this, *(GetPointer<VertexWriterTemplate>(vertex_writer)),
864  *(GetPointer<EdgeWriterTemplate>(edge_writer)),
865  *(GetPointer<GraphWriterTemplate>(graph_writer)));
866  }
867 
868  public:
870 
871 
876  graph(graphs_collection* g, const int _selector)
880  collection(g),
881  selector(_selector)
882  {
883  }
884 
891  graph(graphs_collection* g, const int _selector,
892  const CustomUnorderedSet<boost::graph_traits<graphs_collection>::vertex_descriptor>& vertices)
895  *g, SelectEdge<boost_graphs_collection>(_selector, g, vertices),
897  collection(g),
898  selector(_selector)
899  {
900  }
902 
904  friend boost::graph_traits<graph>::vertex_descriptor VERTEX(const boost::graph_traits<graph>::vertices_size_type,
905  const graph&);
906 
908  virtual ~graph() = default;
909 
913  bool is_in_subset(const boost::graph_traits<graph>::vertex_descriptor v) const
914  {
915  return m_vertex_pred(v);
916  }
917 
922  inline int GetSelector() const
923  {
924  return selector;
925  }
926 
932  inline int GetSelector(const edge_descriptor e) const
933  {
934  return collection->GetSelector(e) & GetSelector();
935  }
936 
943  inline int GetSelector(const boost::graph_traits<graphs_collection>::vertex_descriptor source,
944  const boost::graph_traits<graphs_collection>::vertex_descriptor target) const
945  {
946  bool found;
947  typename boost::graph_traits<graphs_collection>::edge_descriptor edge;
948  boost::tie(edge, found) = boost::edge(source, target, *this);
949  return collection->GetSelector(edge);
950  }
951 
958  std::map<size_t, UnorderedSetStdStable<boost::graph_traits<graphs_collection>::vertex_descriptor>>&
959  strongly_connected_components) const
960  {
961  std::map<boost::graph_traits<graphs_collection>::vertex_descriptor, size_t> temp_vertex_to_component;
962  boost::associative_property_map<std::map<boost::graph_traits<graphs_collection>::vertex_descriptor, size_t>>
963  vertex_to_component(temp_vertex_to_component);
964  boost::strong_components(*this, vertex_to_component);
965  boost::graph_traits<graph>::vertex_iterator vertex_it, vertex_end;
966  for(boost::tie(vertex_it, vertex_end) = boost::vertices(*this); vertex_it != vertex_end; vertex_it++)
967  {
968  const size_t strongly_connected_component = vertex_to_component[*vertex_it];
969  strongly_connected_components[strongly_connected_component].insert(*vertex_it);
970  }
971  }
972 
976  void BreadthFirstSearch(const boost::graph_traits<graphs_collection>::vertex_descriptor node,
977  boost::bfs_visitor<>* vis) const
978  {
979  boost::breadth_first_search(*this, node, visitor(*vis));
980  }
981 
986  void
987  ReverseTopologicalSort(std::deque<boost::graph_traits<graphs_collection>::vertex_descriptor>& sorted_vertices) const
988  {
989  boost::topological_sort(*this, std::back_inserter(sorted_vertices));
990  }
991 
996  void TopologicalSort(std::list<boost::graph_traits<graphs_collection>::vertex_descriptor>& sorted_vertices) const
997  {
998  boost::topological_sort(*this, std::front_inserter(sorted_vertices));
999  }
1000 
1004  bool IsReachable(const boost::graph_traits<graphs_collection>::vertex_descriptor x,
1005  const boost::graph_traits<graphs_collection>::vertex_descriptor y) const
1006  {
1007  std::list<boost::graph_traits<graphs_collection>::vertex_descriptor> running_vertices;
1009  running_vertices.push_back(x);
1010  encountered_vertices.insert(x);
1011  while(not running_vertices.empty())
1012  {
1013  const boost::graph_traits<graphs_collection>::vertex_descriptor current = running_vertices.front();
1014  running_vertices.pop_front();
1015  boost::graph_traits<graph>::out_edge_iterator oe, oe_end;
1016  for(boost::tie(oe, oe_end) = boost::out_edges(current, *this); oe != oe_end; oe++)
1017  {
1018  const boost::graph_traits<graphs_collection>::vertex_descriptor target = boost::target(*oe, *this);
1019  if(target == y)
1020  {
1021  return true;
1022  }
1023  if(encountered_vertices.find(target) == encountered_vertices.end())
1024  {
1025  encountered_vertices.insert(target);
1026  running_vertices.push_back(target);
1027  }
1028  }
1029  }
1030  return false;
1031  }
1032 
1039  inline NodeInfoRef GetNodeInfo(typename boost::graph_traits<graphs_collection>::vertex_descriptor node)
1040  {
1041  NodeInfoRef info = (*this)[node];
1042  THROW_ASSERT(info, "Node without associate info");
1043  return info;
1044  }
1045 
1052  {
1054  return info;
1055  }
1056 
1062  inline const GraphInfoConstRef CGetGraphInfo() const
1063  {
1065  return info;
1066  }
1067 
1075  template <typename VertexWriterTemplate, typename EdgeWriterTemplate>
1076  void InternalWriteDot(const std::string& file_name, const VertexWriterConstRef vertex_writer,
1077  const EdgeWriterConstRef edge_writer) const
1078  {
1079  std::ofstream file_stream(file_name.c_str());
1080  boost::write_graphviz(file_stream, *this, *(GetPointer<VertexWriterTemplate>(vertex_writer)),
1081  *(GetPointer<EdgeWriterTemplate>(edge_writer)));
1082  }
1083 
1090  inline bool ExistsEdge(const boost::graph_traits<graphs_collection>::vertex_descriptor source,
1091  const boost::graph_traits<graphs_collection>::vertex_descriptor target) const
1092  {
1093  boost::graph_traits<graphs_collection>::edge_descriptor edge;
1094  bool inserted;
1095  boost::tie(edge, inserted) = boost::edge(source, target, *this);
1096  return inserted;
1097  }
1098 
1105  inline boost::graph_traits<graphs_collection>::edge_descriptor
1106  CGetEdge(const boost::graph_traits<graphs_collection>::vertex_descriptor source,
1107  const boost::graph_traits<graphs_collection>::vertex_descriptor target) const
1108  {
1109  boost::graph_traits<graphs_collection>::edge_descriptor edge;
1110  bool inserted;
1111  boost::tie(edge, inserted) = boost::edge(source, target, *this);
1112  THROW_ASSERT(inserted, "Edge does not exist in this graph");
1113  return edge;
1114  }
1115 
1116 #if BOOST_VERSION >= 104200
1117  using edge_property_type = boost::edge_property_type<graphs_collection>::type;
1118  using vertex_property_type = boost::vertex_property_type<graphs_collection>::type;
1119  using graph_property_type = boost::graph_property_type<graphs_collection>::type;
1120 #endif
1121 };
1124 
1125 #if BOOST_VERSION >= 104600
1126 namespace boost
1127 {
1128  namespace detail
1129  {
1130  struct filtered_graph_property_selector
1131  {
1132  template <class FilteredGraph, class Property, class Tag>
1133  struct bind_
1134  {
1135  using Graph = typename FilteredGraph::graph_type;
1136  using Map = property_map<Graph, Tag>;
1137  using type = typename Map::type;
1138  using const_type = typename Map::const_type;
1139  };
1140  };
1141  } // namespace detail
1142  template <>
1143  struct vertex_property_selector<filtered_graph_tag>
1144  {
1145  using type = detail::filtered_graph_property_selector;
1146  };
1147  template <>
1148  struct edge_property_selector<filtered_graph_tag>
1149  {
1150  using type = detail::filtered_graph_property_selector;
1151  };
1152 
1153 } // namespace boost
1154 #endif
1155 
1159 struct ugraph
1160  : public boost::filtered_graph<undirected_boost_graphs_collection, SelectEdge<undirected_boost_graphs_collection>,
1161  SelectVertex<undirected_boost_graphs_collection>>
1162 {
1163  protected:
1166 
1168  const int selector;
1169 
1176  template <typename UVertexWriterTemplate, typename UEdgeWriterTemplate>
1177  void InternalWriteDot(const std::string& file_name, const UVertexWriterConstRef uvertex_writer,
1178  const UEdgeWriterConstRef uedge_writer) const
1179  {
1180  std::ofstream file_stream(file_name.c_str());
1181  boost::write_graphviz(file_stream, *this, *(GetPointer<UVertexWriterTemplate>(uvertex_writer)),
1182  *(GetPointer<UEdgeWriterTemplate>(uedge_writer)));
1183  }
1184 
1185  public:
1187 
1188 
1193  ugraph(undirected_graphs_collection* g, const int _selector)
1198  collection(g),
1199  selector(_selector)
1200  {
1201  }
1202 
1210  undirected_graphs_collection* g, const int _selector,
1211  const CustomUnorderedSet<boost::graph_traits<undirected_boost_graphs_collection>::vertex_descriptor>& vertices)
1214  *g, SelectEdge<undirected_boost_graphs_collection>(_selector, g, vertices),
1216  collection(g),
1217  selector(_selector)
1218 
1219  {
1220  }
1222 
1224  friend boost::graph_traits<ugraph>::vertex_descriptor VERTEX(const boost::graph_traits<ugraph>::vertices_size_type,
1225  const ugraph&);
1226 
1228  ~ugraph() = default;
1229 
1233  bool is_in_subset(const boost::graph_traits<ugraph>::vertex_descriptor v) const
1234  {
1235  return m_vertex_pred(v);
1236  }
1237 
1242  inline int GetSelector() const
1243  {
1244  return selector;
1245  }
1246 
1252  inline int GetSelector(const edge_descriptor e) const
1253  {
1254  return collection->GetSelector(e);
1255  }
1256 
1257 #if BOOST_VERSION >= 104200
1261 #endif
1262 };
1263 
1265 
1269 template <typename Graph>
1270 struct ltedge
1271 {
1272  private:
1274  const Graph* g;
1275 
1276  public:
1280  explicit ltedge(const Graph* _g) : g(_g)
1281  {
1282  }
1283 
1287  bool operator()(const typename boost::graph_traits<Graph>::edge_descriptor first,
1288  const typename boost::graph_traits<Graph>::edge_descriptor second) const
1289  {
1290  if(boost::source(first, *g) < boost::source(second, *g))
1291  {
1292  return true;
1293  }
1294  if(boost::source(first, *g) > boost::source(second, *g))
1295  {
1296  return false;
1297  }
1298  return boost::target(first, *g) < boost::target(second, *g);
1299  }
1300 };
1301 
1303 using vertex = boost::graph_traits<graph>::vertex_descriptor;
1305 #define NULL_VERTEX boost::graph_traits<graph>::null_vertex()
1306 using VertexIterator = boost::graph_traits<graph>::vertex_iterator;
1308 
1310 using InEdgeIterator = boost::graph_traits<graph>::in_edge_iterator;
1312 using OutEdgeIterator = boost::graph_traits<graph>::out_edge_iterator;
1314 using EdgeIterator = boost::graph_traits<graph>::edge_iterator;
1316 using EdgeDescriptor = boost::graph_traits<graph>::edge_descriptor;
1317 
1321 namespace std
1322 {
1323  template <>
1324  struct hash<EdgeDescriptor> : public unary_function<EdgeDescriptor, size_t>
1325  {
1326  size_t operator()(EdgeDescriptor edge) const
1327  {
1328  size_t hash_value = 0;
1329  boost::hash_combine(hash_value, edge.m_source);
1330  boost::hash_combine(hash_value, edge.m_target);
1331  return hash_value;
1332  }
1333  };
1334 } // namespace std
1335 
1336 template <typename H>
1337 H AbslHashValue(const H& h, const EdgeDescriptor& m)
1338 {
1339  return H::combine(h, m.m_source, m.m_target);
1340 }
1342 using uvertex = boost::graph_traits<ugraph>::vertex_descriptor;
1344 #define NULL_UVERTEX boost::graph_traits<ugraph>::null_vertex()
1345 
1347 using UGCvertex = boost::graph_traits<undirected_graphs_collection>::vertex_descriptor;
1348 #define NULL_UGCVERTEX boost::graph_traits<undirected_graphs_collection>::null_vertex()
1349 
1351 using UVertexIterator = boost::graph_traits<ugraph>::vertex_iterator;
1352 
1354 using UInEdgeIterator = boost::graph_traits<ugraph>::in_edge_iterator;
1356 using UOutEdgeIterator = boost::graph_traits<ugraph>::out_edge_iterator;
1358 using UEdgeIterator = boost::graph_traits<ugraph>::edge_iterator;
1360 using UEdgeDescriptor = boost::graph_traits<ugraph>::edge_descriptor;
1361 
1368 inline boost::graph_traits<graph>::vertex_descriptor VERTEX(const boost::graph_traits<graph>::vertices_size_type i,
1369  const graph& g)
1370 {
1371  return boost::vertex(i, (g.m_g));
1372 }
1373 
1380 inline boost::graph_traits<ugraph>::vertex_descriptor VERTEX(const boost::graph_traits<ugraph>::vertices_size_type i,
1381  const ugraph& g)
1382 {
1383  return boost::vertex(i, (g.m_g));
1384 }
1385 
1386 template <class Graph>
1387 void ADD_UEDGE(typename boost::graph_traits<Graph>::vertex_descriptor A,
1388  typename boost::graph_traits<Graph>::vertex_descriptor B, int selector, Graph& g)
1389 {
1390  UEdgeDescriptor e;
1391  bool inserted;
1392  boost::tie(e, inserted) = boost::edge(A, B, g);
1393  if(inserted)
1394  {
1395  g[e].selector = g[e].selector | selector;
1396  }
1397  else
1398  {
1399  boost::add_edge(A, B, selector, g);
1400  }
1401 }
1402 
1407 {
1408  protected:
1411 
1413  const int detail_level;
1414 
1415  public:
1421  VertexWriter(const graph* _graph, const int _detail_level) : printing_graph(_graph), detail_level(_detail_level)
1422  {
1423  }
1424 
1428  virtual ~VertexWriter() = default;
1429 
1435  virtual void operator()(std::ostream& out, const vertex& v) const = 0;
1436 };
1437 
1442 {
1443  protected:
1446 
1448  const int selector;
1449 
1451  const int detail_level;
1452 
1453  public:
1459  EdgeWriter(const graph* _printing_graph, const int _detail_level)
1460  : printing_graph(_printing_graph), selector(printing_graph->GetSelector()), detail_level(_detail_level)
1461  {
1462  }
1463 
1467  virtual ~EdgeWriter() = default;
1468 
1474  virtual void operator()(std::ostream& out, const EdgeDescriptor& edge) const = 0;
1475 };
1476 
1481 {
1482  protected:
1485 
1487  const int detail_level;
1488 
1489  public:
1495  GraphWriter(const graph* _printing_graph, const int _detail_level)
1496  : printing_graph(_printing_graph), detail_level(_detail_level)
1497  {
1498  }
1499 
1503  virtual ~GraphWriter() = default;
1504 
1509  virtual void operator()(std::ostream& out) const = 0;
1510 };
1511 
1516 {
1517  protected:
1520 
1522  const int detail_level;
1523 
1524  public:
1530  UVertexWriter(const ugraph* _printing_ugraph, const int _detail_level)
1531  : printing_ugraph(_printing_ugraph), detail_level(_detail_level)
1532  {
1533  }
1534 
1538  virtual ~UVertexWriter() = default;
1539 
1545  virtual void operator()(std::ostream& out, const uvertex& v) const = 0;
1546 };
1547 
1552 {
1553  protected:
1556 
1558  const int selector;
1559 
1561  const int detail_level;
1562 
1563  public:
1569  UEdgeWriter(const ugraph* _printing_ugraph, const int _detail_level)
1570  : printing_ugraph(_printing_ugraph), selector(printing_ugraph->GetSelector()), detail_level(_detail_level)
1571  {
1572  }
1573 
1577  virtual ~UEdgeWriter() = default;
1578 
1584  virtual void operator()(std::ostream& out, const UEdgeDescriptor& edge) const = 0;
1585 };
1586 #endif
NodeInfoRef & Cget_node_infoRef(typename boost::graph_traits< Graph >::vertex_descriptor v, Graph &g)
Function returning the reference to the edge information associated with the specified edge...
Definition: graph.hpp:535
Functor used to write the content of the edges to a dotty file.
Definition: graph.hpp:1551
boost::graph_traits< ugraph >::edge_iterator UEdgeIterator
edge_iterator definition.
Definition: graph.hpp:1358
int GetSelector() const
Return the selector of this graph.
Definition: graph.hpp:922
info_object * get_raw_edge_info(typename boost::graph_traits< Graph >::edge_descriptor e, Graph &g)
Function returning the edge information associated with the specified edge.
Definition: graph.hpp:167
boost::graph_traits< ugraph >::in_edge_iterator UInEdgeIterator
in_edge_iterator definition.
Definition: graph.hpp:1354
UVertexWriter(const ugraph *_printing_ugraph, const int _detail_level)
Constructor.
Definition: graph.hpp:1530
#define boost_CGetOpGraph_property(graph_arg)
Definition: graph.hpp:280
boost::graph_traits< graph >::out_edge_iterator OutEdgeIterator
out_edge_iterator definition.
Definition: graph.hpp:1312
absl::node_hash_set< _Value, _Hash, _Pred, _Alloc > UnorderedSetStdStable
Definition: custom_set.hpp:215
const int detail_level
The detail level.
Definition: graph.hpp:1413
int selector
The selector associated with the edge.
Definition: graph.hpp:208
Graph * g
The bulk graph.
Definition: graph.hpp:706
VertexWriter(const graph *_graph, const int _detail_level)
Constructor.
Definition: graph.hpp:1421
void RemoveVertex(boost::graph_traits< boost_raw_graph >::vertex_descriptor v)
Definition: graph.hpp:117
const ParameterConstRef parameters
Set of input parameters.
Definition: graph.hpp:291
const graph * printing_graph
The graph to be printed.
Definition: graph.hpp:1410
const graph * printing_graph
The graph to be printed.
Definition: graph.hpp:1484
boost::graph_traits< graphs_collection >::edge_descriptor AddEdge(boost::graph_traits< graphs_collection >::vertex_descriptor, boost::graph_traits< graphs_collection >::vertex_descriptor, const int)
Add an edge to this graph FIXME: this should be pure virtual.
Definition: graph.hpp:392
boost::graph_traits< boost_raw_graph >::vertex_descriptor AddVertex(const NodeInfoRef v_info)
Definition: graph.hpp:108
ugraph(undirected_graphs_collection *g, const int _selector)
Standard constructor.
Definition: graph.hpp:1193
This algorithm is to find coloring of a graph Algorithm: Let G = (V,E) be a graph with vertices v_1...
string target
Definition: lenet_tvm.py:16
boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS, boost::property< boost::vertex_index_t, std::size_t, NodeInfoRef >, EdgeInfoRef, GraphInfoRef > boost_raw_graph
Definition: graph.hpp:89
const int detail_level
The deail level; if one, tate of the graph is printed.
Definition: graph.hpp:1561
const int detail_level
The detail level (i.e., how much information has to be included)
Definition: graph.hpp:1487
EdgeProperty()
Default constructor.
Definition: graph.hpp:216
EdgeInfoRef GetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target)
Get the edge property.
Definition: graph.hpp:794
void GetStronglyConnectedComponents(std::map< size_t, UnorderedSetStdStable< boost::graph_traits< graphs_collection >::vertex_descriptor >> &strongly_connected_components) const
Compute the strongly connected components of the graph.
Definition: graph.hpp:957
void CompressEdges()
Definition: graph.hpp:444
RawGraph(GraphInfoRef g_info)
Constructor.
Definition: graph.hpp:98
boost::graph_traits< ugraph >::vertex_iterator UVertexIterator
vertex_iterator definition.
Definition: graph.hpp:1351
EdgeWriter(const graph *_printing_graph, const int _detail_level)
Constructor.
Definition: graph.hpp:1459
ltedge(const Graph *_g)
The constructors.
Definition: graph.hpp:1280
void BreadthFirstSearch(const boost::graph_traits< graphs_collection >::vertex_descriptor node, boost::bfs_visitor<> *vis) const
Compute the breadth first search.
Definition: graph.hpp:976
void InternalWriteDot(const std::string &file_name, const VertexWriterConstRef vertex_writer, const EdgeWriterConstRef edge_writer, const GraphWriterConstRef graph_writer) const
Print the graph in dot format.
Definition: graph.hpp:859
boost::graph_traits< ugraph >::edge_descriptor UEdgeDescriptor
edge definition.
Definition: graph.hpp:1360
int GetSelector(const edge_descriptor e) const
Return the selectors associated with an edge.
Definition: graph.hpp:371
void RemoveVertex(boost::graph_traits< undirected_boost_graphs_collection >::vertex_descriptor v)
Remove a vertex from this graph.
Definition: graph.hpp:491
boost::graph_traits< graph >::in_edge_iterator InEdgeIterator
in_edge_iterator definition.
Definition: graph.hpp:1310
exceptions managed by PandA
const EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Get the edge property.
Definition: graph.hpp:811
int GetSelector(const boost::graph_traits< graphs_collection >::vertex_descriptor source, const boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Return the selectors associated with an edge.
Definition: graph.hpp:943
int GetSelector(const edge_descriptor e) const
Return the selectors associated with an edge.
Definition: graph.hpp:509
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
The property associated with edge.
Definition: graph.hpp:204
EdgeInfoRef info
The info associated with an edge.
Definition: graph.hpp:211
const Graph * g
the graph
Definition: graph.hpp:1274
bool ExistsEdge(const boost::graph_traits< graphs_collection >::vertex_descriptor source, const boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Check if an edge exists.
Definition: graph.hpp:1090
SelectEdge()
Default constructor.
Definition: graph.hpp:718
info_object * get_node_info(typename boost::graph_traits< Graph >::vertex_descriptor v, Graph &g)
Function returning the node information associated with the specified node.
Definition: graph.hpp:571
SelectVertex(const CustomUnorderedSet< typename boost::graph_traits< Graph >::vertex_descriptor > &_subset)
Constructor.
Definition: graph.hpp:672
boost::graph_traits< graph >::vertex_descriptor VERTEX(const boost::graph_traits< graph >::vertices_size_type i, const graph &g)
Given a filtered graph and an index returns the vertex exploiting the boost::vertex applied on the or...
Definition: graph.hpp:1368
void RemoveSelector(boost::graph_traits< graphs_collection >::edge_descriptor edge)
Remove all the selectors of an edge from this graph.
Definition: graph.hpp:338
bool all
True if all the vertices have to be selected.
Definition: graph.hpp:655
NodeInfoRef GetNodeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor node)
FIXME: this method should become protected and called by equivalent method in subclasses Get the node...
Definition: graph.hpp:1039
Custom graph property: GraphInfo.
Definition: graph.hpp:258
bool operator()(const Edge &e) const
Definition: graph.hpp:744
void RemoveEdge(boost::graph_traits< boost_raw_graph >::vertex_descriptor src, boost::graph_traits< boost_raw_graph >::vertex_descriptor tgt)
Definition: graph.hpp:148
Functor used to sort edges.
Definition: graph.hpp:1270
boost::graph_traits< boost_raw_graph >::edge_descriptor AddEdge(boost::graph_traits< boost_raw_graph >::vertex_descriptor src, boost::graph_traits< boost_raw_graph >::vertex_descriptor tgt, const EdgeInfoRef e_info)
Definition: graph.hpp:131
#define A
Definition: generate.c:13
~RawGraph()=default
Destructor.
graphs_collection(GraphInfoRef info, const ParameterConstRef _parameters)
Constructor of graph.
Definition: graph.hpp:297
boost::graph_traits< graphs_collection >::edge_descriptor AddSelector(const boost::graph_traits< graphs_collection >::vertex_descriptor source, const boost::graph_traits< graphs_collection >::vertex_descriptor target, const int selector)
Add a selector to an existing edge.
Definition: graph.hpp:323
void ADD_UEDGE(typename boost::graph_traits< Graph >::vertex_descriptor A, typename boost::graph_traits< Graph >::vertex_descriptor B, int selector, Graph &g)
Definition: graph.hpp:1387
SelectVertex()
Constructor to select all the vertices.
Definition: graph.hpp:664
const graph * printing_graph
The graph to be printed.
Definition: graph.hpp:1445
boost::graph_traits< ugraph >::vertex_descriptor uvertex
vertex definition.
Definition: graph.hpp:1342
boost::graph_traits< graph >::edge_iterator EdgeIterator
edge_iterator definition.
Definition: graph.hpp:1314
void RemoveEdge(boost::graph_traits< boost_raw_graph >::edge_descriptor e)
Definition: graph.hpp:143
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
const ugraph * printing_ugraph
The graph to be printed.
Definition: graph.hpp:1519
bool is_in_subset(const boost::graph_traits< ugraph >::vertex_descriptor v) const
return true in case the vertex is a vertex of the subgraph.
Definition: graph.hpp:1233
unsigned edges[4545]
Definition: graph.h:25
EdgeInfoRef GetEdgeInfo(typename boost::graph_traits< graphs_collection >::edge_descriptor edge) const
Get the edge property.
Definition: graph.hpp:826
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
Predicate functor object used to select the proper set of edges.
Definition: graph.hpp:699
Functor used to write the content of the property of a graph to a dotty file.
Definition: graph.hpp:1480
void RemoveSelector(boost::graph_traits< graphs_collection >::vertex_descriptor source, boost::graph_traits< graphs_collection >::vertex_descriptor target, const int selector)
Remove an edge from this graph.
Definition: graph.hpp:356
boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS, boost::property< boost::vertex_index_t, std::size_t, boost::property< boost::vertex_color_t, boost::default_color_type, NodeInfoRef > >, EdgeProperty, GraphProperty > boost_graphs_collection
Definition: graph.hpp:271
Functor used to write the content of a vertex to dotty file.
Definition: graph.hpp:1406
bool empty
true when the subvertices set is empty
Definition: graph.hpp:712
void RemoveSelector(boost::graph_traits< graphs_collection >::edge_descriptor edge, const int selector)
Remove an edge from this graph.
Definition: graph.hpp:348
const NodeInfoConstRef CGetNodeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor node) const
Get the node property.
Definition: graph.hpp:781
Base class description of data information associated with each node of a graph.
void SetSelector(edge_descriptor e, const int selector)
Set the selector associated with an edge.
Definition: graph.hpp:519
const int selector
selector
Definition: graph.hpp:849
refcount< EdgeInfo > EdgeInfoRef
RefCount type definition of the edge_info class structure.
Definition: edge_info.hpp:67
#define index(x, y)
Definition: Keccak.c:74
redefinition of set to manage ordered/unordered structures
const int h[24]
Definition: adpcm.c:87
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
const int selector
The selector of the graph to be printed.
Definition: graph.hpp:1448
graph(graphs_collection *g, const int _selector)
Standard constructor.
Definition: graph.hpp:876
General class used to describe a graph in PandA.
Definition: graph.hpp:771
boost::graph_traits< graphs_collection >::edge_descriptor CGetEdge(const boost::graph_traits< graphs_collection >::vertex_descriptor source, const boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Returns the edge connecting two vertices; throw error if it does not exist.
Definition: graph.hpp:1106
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
Definition: graph.hpp:1307
const info_object * Cget_node_info(typename boost::graph_traits< Graph >::vertex_descriptor v, const Graph &g)
Function returning the node information associated with the specified node.
Definition: graph.hpp:592
const int detail_level
The detail level.
Definition: graph.hpp:1451
Base class storing user data information.
Definition: edge_info.hpp:55
const info_object * Cget_edge_info(typename boost::graph_traits< Graph >::edge_descriptor e, const Graph &g)
Function returning the edge information associated with the specified edge.
Definition: graph.hpp:634
boost::graph_traits< graphs_collection >::edge_descriptor AddSelector(const boost::graph_traits< graphs_collection >::edge_descriptor edge, const int selector)
Add a selector to an existing edge.
Definition: graph.hpp:311
Functor used to write the content of a vertex to dotty file.
Definition: graph.hpp:1515
refcount< NodeInfo > NodeInfoRef
RefCount type definition of the NodeInfo class structure.
Definition: node_info.hpp:98
Base class for graph property.
GraphInfoRef GetGraphInfo()
FIXME: this method should become protected and called by equivalent method in subclasses Get the grap...
Definition: graph.hpp:1051
ugraph(undirected_graphs_collection *g, const int _selector, const CustomUnorderedSet< boost::graph_traits< undirected_boost_graphs_collection >::vertex_descriptor > &vertices)
Sub-graph constructor.
Definition: graph.hpp:1209
boost::graph_property_tag kind
typedef defining graph_info_t as graph object
Definition: graph.hpp:261
Template definition of refcount.
void TopologicalSort(std::list< boost::graph_traits< graphs_collection >::vertex_descriptor > &sorted_vertices) const
Compute the topological order of the graph.
Definition: graph.hpp:996
const info_object * Cget_raw_edge_info(typename boost::graph_traits< Graph >::edge_descriptor e, const Graph &g)
Function returning the edge information associated with the specified edge.
Definition: graph.hpp:188
GraphWriter(const graph *_printing_graph, const int _detail_level)
Constructor.
Definition: graph.hpp:1495
Base class description of data information associated with each edge of a graph.
CustomUnorderedSet< typename boost::graph_traits< Graph >::vertex_descriptor > subgraph_vertices
The vertices of subgraph.
Definition: graph.hpp:709
bool operator()(const typename boost::graph_traits< Graph >::vertex_descriptor &v) const
Operator to check if a vertex has to be selected.
Definition: graph.hpp:682
bulk graph.
Definition: graph.hpp:287
bool IsReachable(const boost::graph_traits< graphs_collection >::vertex_descriptor x, const boost::graph_traits< graphs_collection >::vertex_descriptor y) const
Compute if vertex y is reachable from x.
Definition: graph.hpp:1004
EdgeProperty(int _selector)
Constructor with selector.
Definition: graph.hpp:224
bool is_in_subset(const boost::graph_traits< graph >::vertex_descriptor v) const
return true in case the vertex is a vertex of the subgraph.
Definition: graph.hpp:913
int selector
The selector associated with the filtered graph.
Definition: graph.hpp:703
SelectEdge(const int _selector, Graph *_g)
Constructor for filtering only on selector.
Definition: graph.hpp:727
Functor used to write the content of the edges to a dotty file.
Definition: graph.hpp:1441
const GraphInfoConstRef CGetGraphInfo() const
FIXME: this method should become protected and called by equivalent method in subclasses Get the grap...
Definition: graph.hpp:1062
int GetSelector(const edge_descriptor e) const
Return the selectors associated with an edge.
Definition: graph.hpp:932
void ReverseTopologicalSort(std::deque< boost::graph_traits< graphs_collection >::vertex_descriptor > &sorted_vertices) const
Compute the reverse topological order of the graph.
Definition: graph.hpp:987
#define H
Definition: deriche.h:37
SelectEdge(const int _selector, Graph *_g, const CustomUnorderedSet< typename boost::graph_traits< Graph >::vertex_descriptor > &_subgraph_vertices)
Constructor for filtering also on vertices.
Definition: graph.hpp:737
General class used to describe a graph in PandA.
Definition: graph.hpp:1159
unsigned int size_t
Definition: test.c:1
Predicate functor object used to select the proper set of vertexes.
Definition: graph.hpp:651
int GetSelector(const edge_descriptor e) const
Return the selectors associated with an edge.
Definition: graph.hpp:1252
EdgeProperty(const int _selector, EdgeInfoRef _info)
Constructor with selector and property.
Definition: graph.hpp:232
UEdgeWriter(const ugraph *_printing_ugraph, const int _detail_level)
Constructor.
Definition: graph.hpp:1569
bool operator()(const typename boost::graph_traits< Graph >::edge_descriptor first, const typename boost::graph_traits< Graph >::edge_descriptor second) const
Redefinition of binary operator as less than.
Definition: graph.hpp:1287
undirected_graphs_collection * collection
The graph collection.
Definition: graph.hpp:1165
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
void set_node_info(typename boost::graph_traits< Graph >::vertex_descriptor v, const refcount< info_object > &obj, Graph &g)
Function returning the node information associated with the specified node.
Definition: graph.hpp:553
int GetSelector() const
Return the selector of this graph.
Definition: graph.hpp:1242
boost::graph_traits< undirected_graphs_collection >::vertex_descriptor UGCvertex
vertex definition for undirected_graphs_collection.
Definition: graph.hpp:1347
REF_FORWARD_DECL(NodeInfo)
const int detail_level
The detail level.
Definition: graph.hpp:1522
boost::adjacency_list< boost::listS, boost::listS, boost::undirectedS, boost::property< boost::vertex_index_t, std::size_t, boost::property< boost::vertex_color_t, boost::default_color_type, NodeInfoRef > >, EdgeProperty, GraphProperty > undirected_boost_graphs_collection
Definition: graph.hpp:278
const int selector
The selector of the graph to be printed.
Definition: graph.hpp:1558
info_object * get_edge_info(typename boost::graph_traits< Graph >::edge_descriptor e, Graph &g)
Function returning the edge information associated with the specified edge.
Definition: graph.hpp:613
boost::graph_traits< ugraph >::out_edge_iterator UOutEdgeIterator
out_edge_iterator definition.
Definition: graph.hpp:1356
void InternalWriteDot(const std::string &file_name, const VertexWriterConstRef vertex_writer, const EdgeWriterConstRef edge_writer) const
Print the graph in dot format FIXME: this method should become protected and called by WriteDot...
Definition: graph.hpp:1076
CustomUnorderedSet< typename boost::graph_traits< Graph >::vertex_descriptor > subset
The set of vertices to be considered.
Definition: graph.hpp:658
x
Return the smallest n such that 2^n >= _x.
boost::property< graph_info_t, GraphInfoRef > GraphProperty
Definition: graph.hpp:264
const int selector
selector
Definition: graph.hpp:1168
boost::graph_traits< graphs_collection >::edge_descriptor InternalAddEdge(boost::graph_traits< graphs_collection >::vertex_descriptor source, boost::graph_traits< graphs_collection >::vertex_descriptor target, const int selector, const EdgeInfoRef info)
Add an edge to this graph FIXME: this should be protected.
Definition: graph.hpp:408
size_t operator()(EdgeDescriptor edge) const
Definition: graph.hpp:1326
graphs_collection * collection
The graph collection.
Definition: graph.hpp:846
#define B
Definition: generate.c:14
EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits< graphs_collection >::edge_descriptor edge) const
Get the edge property.
Definition: graph.hpp:838
CONSTREF_FORWARD_DECL(EdgeInfo)
boost::graph_traits< undirected_boost_graphs_collection >::vertex_descriptor AddVertex()
Add a vertex to this graph.
Definition: graph.hpp:479
const ugraph * printing_ugraph
The graph to be printed.
Definition: graph.hpp:1555
graph(graphs_collection *g, const int _selector, const CustomUnorderedSet< boost::graph_traits< graphs_collection >::vertex_descriptor > &vertices)
Sub-graph constructor.
Definition: graph.hpp:891
bool ExistsEdge(const boost::graph_traits< graphs_collection >::vertex_descriptor source, const boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Check if an edge exists.
Definition: graph.hpp:435
H AbslHashValue(const H &h, const EdgeDescriptor &m)
Definition: graph.hpp:1337
void InternalWriteDot(const std::string &file_name, const UVertexWriterConstRef uvertex_writer, const UEdgeWriterConstRef uedge_writer) const
Print the graph in dot format.
Definition: graph.hpp:1177
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:53 for PandA-2024.02 by doxygen 1.8.13