CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Attributes
math::Graph< N, E > Class Template Reference

#include <Graph.h>

Classes

class  const_iterator
 
struct  value_type
 

Public Types

using adj_iterator = adj_list::iterator
 
using adj_list = std::vector< edge_list >
 
using const_adj_iterator = adj_list::const_iterator
 
using const_edge_iterator = edge_list::const_iterator
 
using const_edge_range = std::pair< const_edge_iterator, const_edge_iterator >
 
using const_indexer_iterator = typename indexer_type::const_iterator
 
using edge_iterator = edge_list::iterator
 
using edge_list = std::vector< edge_type >
 
using edge_range = std::pair< edge_iterator, edge_iterator >
 
using edge_store = std::vector< E >
 
using edge_type = std::pair< index_type, index_type >
 
using index_result = std::pair< index_type, bool >
 
using index_type = std::vector< double >::size_type
 
using indexer_iterator = typename indexer_type::iterator
 
using indexer_type = std::map< N, index_type >
 
using node_list = std::vector< N >
 

Public Member Functions

void addEdge (const N &from, const N &to, const E &edge)
 
index_type addNode (const N &)
 
adj_iterator begin ()
 
const_adj_iterator begin () const
 
const_iterator begin_iter () const
 
void clear ()
 it clear everything! More...
 
size_t edge_size () const
 
const E & edgeData (index_type i) const
 
edge_range edges (index_type nodeIndex)
 
const_edge_range edges (index_type nodeIndex) const
 
edge_range edges (const N &)
 
const_edge_range edges (const N &) const
 
adj_iterator end ()
 
const_adj_iterator end () const
 
const_iterator end_iter () const
 
void findRoots (edge_list &) const
 
 Graph ()
 
void invert (Graph &g) const
 
const NnodeData (const edge_type &) const
 
const NnodeData (index_type) const
 
const NnodeData (const const_adj_iterator &) const
 
index_result nodeIndex (const N &) const
 
bool replace (const N &oldNode, const N &newNode)
 
bool replaceEdge (const E &ldEdge, const E &newEdge)
 
auto size () const -> adj_list::size_type
 
void swap (Graph< N, E > &)
 
 ~Graph ()
 

Private Attributes

adj_list adjl_
 
edge_store edges_
 
edge_list emptyEdges_
 
indexer_type indexer_
 
node_list nodes_
 

Detailed Description

template<class N, class E>
class math::Graph< N, E >

Definition at line 13 of file Graph.h.

Member Typedef Documentation

template<class N, class E>
using math::Graph< N, E >::adj_iterator = adj_list::iterator

Definition at line 124 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::adj_list = std::vector<edge_list>

Definition at line 22 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::const_adj_iterator = adj_list::const_iterator

Definition at line 125 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::const_edge_iterator = edge_list::const_iterator

Definition at line 134 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::const_edge_range = std::pair<const_edge_iterator, const_edge_iterator>

Definition at line 136 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::const_indexer_iterator = typename indexer_type::const_iterator

Definition at line 130 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::edge_iterator = edge_list::iterator

Definition at line 133 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::edge_list = std::vector<edge_type>

Definition at line 20 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::edge_range = std::pair<edge_iterator, edge_iterator>

Definition at line 135 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::edge_store = std::vector<E>

Definition at line 121 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::edge_type = std::pair<index_type, index_type>

Definition at line 18 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::index_result = std::pair<index_type, bool>

Definition at line 137 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::index_type = std::vector<double>::size_type

Definition at line 16 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::indexer_iterator = typename indexer_type::iterator

Definition at line 129 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::indexer_type = std::map<N, index_type>

Definition at line 128 of file Graph.h.

template<class N, class E>
using math::Graph< N, E >::node_list = std::vector<N>

Definition at line 120 of file Graph.h.

Constructor & Destructor Documentation

template<class N, class E>
math::Graph< N, E >::Graph ( )
inline

Definition at line 141 of file Graph.h.

141 : edges_(1) { }
edge_store edges_
Definition: Graph.h:216
template<class N, class E>
math::Graph< N, E >::~Graph ( )
inline

Definition at line 142 of file Graph.h.

142 { }

Member Function Documentation

template<class N, class E>
void math::Graph< N, E >::addEdge ( const N from,
const N to,
const E &  edge 
)

Definition at line 261 of file Graph.h.

References math::Graph< N, E >::addNode(), math::Graph< N, E >::adjl_, and math::Graph< N, E >::edges_.

Referenced by graph_combine(), math::Graph< N, E >::invert(), DDCompactViewImpl::position(), and math::Graph< Node2, AnotherDummy2 >::~Graph().

262 {
263  index_type iFrom = addNode(from);
264  index_type iTo = addNode(to);
265 
266  adjl_[iFrom].emplace_back(edge_type(iTo,edges_.size()));
267  edges_.emplace_back(edge);
268 }
edge_store edges_
Definition: Graph.h:216
std::vector< double >::size_type index_type
Definition: Graph.h:16
index_type addNode(const N &)
Definition: Graph.h:229
std::pair< index_type, index_type > edge_type
Definition: Graph.h:18
adj_list adjl_
Definition: Graph.h:210
template<class N, class E >
Graph< N, E >::index_type math::Graph< N, E >::addNode ( const N node)

Definition at line 229 of file Graph.h.

References math::Graph< N, E >::adjl_, training_settings::idx, math::Graph< N, E >::indexer_, math::Graph< N, E >::nodes_, and mps_fire::result.

Referenced by math::Graph< N, E >::addEdge(), and math::Graph< Node2, AnotherDummy2 >::~Graph().

230 {
231  index_type idx = indexer_.size() ; // +1;
232  std::pair<indexer_iterator,bool> result
233  = indexer_.insert(typename indexer_type::value_type(node,idx));
234 
235  if ( result.second ) { // new index!
236  nodes_.emplace_back(node);
237  adjl_.emplace_back(edge_list());
238  }
239  else {
240  idx = result.first->second;
241  }
242  return idx;
243 }
node_list nodes_
Definition: Graph.h:213
std::vector< double >::size_type index_type
Definition: Graph.h:16
std::vector< edge_type > edge_list
Definition: Graph.h:20
indexer_type indexer_
Definition: Graph.h:219
adj_list adjl_
Definition: Graph.h:210
template<class N, class E>
adj_iterator math::Graph< N, E >::begin ( void  )
inline
template<class N, class E>
const_adj_iterator math::Graph< N, E >::begin ( void  ) const
inline

Definition at line 193 of file Graph.h.

193 { return adjl_.begin(); }
adj_list adjl_
Definition: Graph.h:210
template<class N, class E>
const_iterator math::Graph< N, E >::begin_iter ( ) const
inline

Definition at line 185 of file Graph.h.

185 { return const_iterator(*this); }
template<class N , class E >
void math::Graph< N, E >::clear ( void  )
template<class N, class E>
size_t math::Graph< N, E >::edge_size ( ) const
inline

Definition at line 189 of file Graph.h.

189 { return edges_.size(); }
edge_store edges_
Definition: Graph.h:216
template<class N, class E>
const E& math::Graph< N, E >::edgeData ( index_type  i) const
inline
template<class N , class E >
Graph< N, E >::edge_range math::Graph< N, E >::edges ( index_type  nodeIndex)
inline

Definition at line 272 of file Graph.h.

References math::Graph< N, E >::adjl_, and math::Graph< N, E >::nodeIndex().

Referenced by DDCheckAll(), math::Graph< N, E >::edges(), DDErrorDetection::lp_cpv(), DDCompactViewImpl::~DDCompactViewImpl(), and math::Graph< Node2, AnotherDummy2 >::~Graph().

273 {
275  return edge_range(edges.begin(), edges.end());
276 }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:272
std::pair< edge_iterator, edge_iterator > edge_range
Definition: Graph.h:135
index_result nodeIndex(const N &) const
Definition: Graph.h:247
std::vector< edge_type > edge_list
Definition: Graph.h:20
adj_list adjl_
Definition: Graph.h:210
template<class N , class E >
Graph< N, E >::const_edge_range math::Graph< N, E >::edges ( index_type  nodeIndex) const
inline

Definition at line 280 of file Graph.h.

References math::Graph< N, E >::adjl_, math::Graph< N, E >::edges(), and math::Graph< N, E >::nodeIndex().

281 {
282  const edge_list & edges = adjl_[nodeIndex];
283  return const_edge_range(edges.begin(), edges.end());
284 }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:272
std::pair< const_edge_iterator, const_edge_iterator > const_edge_range
Definition: Graph.h:136
index_result nodeIndex(const N &) const
Definition: Graph.h:247
std::vector< edge_type > edge_list
Definition: Graph.h:20
adj_list adjl_
Definition: Graph.h:210
template<class N, class E >
Graph< N, E >::edge_range math::Graph< N, E >::edges ( const N node)
inline

Definition at line 288 of file Graph.h.

References math::Graph< N, E >::edges(), math::Graph< N, E >::emptyEdges_, math::Graph< N, E >::nodeIndex(), and mps_fire::result.

289 {
290  index_result idxResult = nodeIndex(node);
291  edge_range result(emptyEdges_.begin(),emptyEdges_.end());
292  if (idxResult.second) {
293  result = edges(idxResult.first);
294  }
295  return result;
296 }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:272
std::pair< index_type, bool > index_result
Definition: Graph.h:137
std::pair< edge_iterator, edge_iterator > edge_range
Definition: Graph.h:135
edge_list emptyEdges_
Definition: Graph.h:222
index_result nodeIndex(const N &) const
Definition: Graph.h:247
template<class N, class E >
Graph< N, E >::const_edge_range math::Graph< N, E >::edges ( const N node) const
inline

Definition at line 300 of file Graph.h.

References math::Graph< N, E >::edges(), math::Graph< N, E >::emptyEdges_, math::Graph< N, E >::nodeIndex(), and mps_fire::result.

301 {
302  index_result idxResult = nodeIndex(node);
304  if (idxResult.second) {
305  result = edges(idxResult.first);
306  }
307  return result;
308 }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:272
std::pair< const_edge_iterator, const_edge_iterator > const_edge_range
Definition: Graph.h:136
std::pair< index_type, bool > index_result
Definition: Graph.h:137
edge_list emptyEdges_
Definition: Graph.h:222
index_result nodeIndex(const N &) const
Definition: Graph.h:247
template<class N, class E>
adj_iterator math::Graph< N, E >::end ( void  )
inline
template<class N, class E>
const_adj_iterator math::Graph< N, E >::end ( void  ) const
inline

Definition at line 195 of file Graph.h.

Referenced by Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

195 { return adjl_.end(); }
adj_list adjl_
Definition: Graph.h:210
template<class N, class E>
const_iterator math::Graph< N, E >::end_iter ( ) const
inline

Definition at line 187 of file Graph.h.

187 { return const_iterator(*this, adjl_.size(),0); }
adj_list adjl_
Definition: Graph.h:210
template<class N , class E >
void math::Graph< N, E >::findRoots ( edge_list result) const

Definition at line 332 of file Graph.h.

References math::Graph< N, E >::begin(), math::Graph< N, E >::end(), and math::Graph< N, E >::size().

Referenced by math::Graph< Node2, AnotherDummy2 >::size().

333 {
334  result.clear();
335 
336  const_adj_iterator it = begin();
337  const_adj_iterator ed = end();
338  std::vector<bool> rootCandidate(size(), true);
339 
340  for (; it != ed; ++it) {
341  const edge_list & el = *it;
342  for (auto const & el_it : el) {
343  rootCandidate[el_it.first]=false;
344  }
345  }
347  std::vector<bool>::size_type v_ed = rootCandidate.size();
348  for (; v_sz < v_ed; ++v_sz) {
349  if (rootCandidate[v_sz]) {
350  result.emplace_back(edge_type(v_sz,0));
351  }
352  }
353 }
uint16_t size_type
std::pair< index_type, index_type > edge_type
Definition: Graph.h:18
adj_iterator end()
Definition: Graph.h:194
std::vector< edge_type > edge_list
Definition: Graph.h:20
auto size() const -> adj_list::size_type
Definition: Graph.h:196
adj_iterator begin()
Definition: Graph.h:192
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:125
template<class N , class E >
void math::Graph< N, E >::invert ( Graph< N, E > &  g) const

Definition at line 395 of file Graph.h.

References math::Graph< N, E >::addEdge(), math::Graph< N, E >::adjl_, MillePedeFileConverter_cfg::e, math::Graph< N, E >::edgeData(), and math::Graph< N, E >::nodeData().

Referenced by math::Graph< Node2, AnotherDummy2 >::size().

396 {
397  adj_list::size_type it = 0;
398  adj_list::size_type ed = adjl_.size();
399  // loop over adjacency-list of this Graph
400  for (; it < ed; ++it) {
401  const edge_list & el = adjl_[it];
402  edge_list::size_type eit = 0;
403  edge_list::size_type eed = el.size();
404  // loop over edges of current node
405  for (; eit < eed; ++eit) {
406  const edge_type & e = el[eit];
407  g.addEdge(nodeData(e.first), nodeData(it), edgeData(e.second));
408  }
409  }
410 }
uint16_t size_type
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
const N & nodeData(const edge_type &) const
Definition: Graph.h:312
const E & edgeData(index_type i) const
Definition: Graph.h:178
std::pair< index_type, index_type > edge_type
Definition: Graph.h:18
std::vector< edge_type > edge_list
Definition: Graph.h:20
adj_list adjl_
Definition: Graph.h:210
template<class N , class E >
const N & math::Graph< N, E >::nodeData ( const edge_type edge) const
inline
template<class N , class E >
const N & math::Graph< N, E >::nodeData ( index_type  i) const
inline

Definition at line 319 of file Graph.h.

References mps_fire::i, and math::Graph< N, E >::nodes_.

320 {
321  return nodes_[i];
322 }
node_list nodes_
Definition: Graph.h:213
template<class N , class E >
const N & math::Graph< N, E >::nodeData ( const const_adj_iterator it) const
inline

Definition at line 326 of file Graph.h.

References math::Graph< N, E >::adjl_, and math::Graph< N, E >::nodes_.

327 {
328  return nodes_[it-adjl_.begin()];
329 }
node_list nodes_
Definition: Graph.h:213
adj_list adjl_
Definition: Graph.h:210
template<class N, class E >
Graph< N, E >::index_result math::Graph< N, E >::nodeIndex ( const N node) const
inline

Definition at line 247 of file Graph.h.

References RemoveAddSevLevel::flag, training_settings::idx, math::Graph< N, E >::indexer_, and mps_fire::result.

Referenced by math::Graph< N, E >::edges(), DDErrorDetection::lp_cpv(), and math::Graph< Node2, AnotherDummy2 >::~Graph().

248 {
249  typename indexer_type::const_iterator result = indexer_.find(node);
250  index_type idx = 0;
251  bool flag = false;
252  if (result != indexer_.end()) {
253  flag = true;
254  idx = result->second;
255  }
256  return index_result(idx, flag);
257 }
std::vector< double >::size_type index_type
Definition: Graph.h:16
std::pair< index_type, bool > index_result
Definition: Graph.h:137
indexer_type indexer_
Definition: Graph.h:219
template<class N, class E >
bool math::Graph< N, E >::replace ( const N oldNode,
const N newNode 
)

Definition at line 356 of file Graph.h.

References math::Graph< N, E >::indexer_, and math::Graph< N, E >::nodes_.

Referenced by graph_combine(), and math::Graph< Node2, AnotherDummy2 >::~Graph().

357 {
358  typename indexer_type::iterator it = indexer_.find(oldNode);
359  if (it != indexer_.end()) {
360  index_type oldIndex = it->second;
361  nodes_[oldIndex]=newNode;
362  indexer_[newNode]=oldIndex;
363  indexer_.erase(it);
364  }
365  else throw(oldNode);
366  return true;
367 }
node_list nodes_
Definition: Graph.h:213
std::vector< double >::size_type index_type
Definition: Graph.h:16
indexer_type indexer_
Definition: Graph.h:219
template<class N , class E>
bool math::Graph< N, E >::replaceEdge ( const E &  ldEdge,
const E &  newEdge 
)

Definition at line 370 of file Graph.h.

References math::Graph< N, E >::edges_, and mps_fire::result.

Referenced by math::Graph< Node2, AnotherDummy2 >::~Graph().

371 {
372  typename edge_store::size_type it = 0;
373  typename edge_store::size_type ed = edges_.size();
374  bool result = false;
375  for (; it < ed; ++it) {
376  if ( edges_[it] == oldEdge ) {
377  result = true;
378  edges_[it] = newEdge;
379  break;
380  }
381  }
382  return result;
383 }
edge_store edges_
Definition: Graph.h:216
uint16_t size_type
template<class N, class E>
auto math::Graph< N, E >::size ( void  ) const -> adj_list::size_type
inline
template<class N, class E>
void math::Graph< N, E >::swap ( Graph< N, E > &  g)

Definition at line 413 of file Graph.h.

References math::Graph< N, E >::adjl_, math::Graph< N, E >::edges_, math::Graph< N, E >::emptyEdges_, math::Graph< N, E >::indexer_, and math::Graph< N, E >::nodes_.

Referenced by math::Graph< Node2, AnotherDummy2 >::size(), and DDCompactViewImpl::swap().

413  {
414  adjl_.swap(g.adjl_);
415  nodes_.swap(g.nodes_);
416  edges_.swap(g.edges_);
417  indexer_.swap(g.indexer_);
418  emptyEdges_.swap(g.emptyEdges_);
419 }
edge_store edges_
Definition: Graph.h:216
node_list nodes_
Definition: Graph.h:213
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
edge_list emptyEdges_
Definition: Graph.h:222
indexer_type indexer_
Definition: Graph.h:219
adj_list adjl_
Definition: Graph.h:210

Member Data Documentation

template<class N, class E>
adj_list math::Graph< N, E >::adjl_
private
template<class N, class E>
edge_store math::Graph< N, E >::edges_
private
template<class N, class E>
edge_list math::Graph< N, E >::emptyEdges_
private

Definition at line 222 of file Graph.h.

Referenced by math::Graph< N, E >::edges(), and math::Graph< N, E >::swap().

template<class N, class E>
indexer_type math::Graph< N, E >::indexer_
private
template<class N, class E>
node_list math::Graph< N, E >::nodes_
private