util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType > Class Template Reference

Detailed Description

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
class util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >

StaticGraph with reverse arc.

  • NodeIndexType can be unsigned, but ArcIndexType must be signed.
  • It has most of the same advantanges and disadvantages as StaticGraph.
  • It takes 2 * ArcIndexType * node_capacity()
  • If the ArcIndexPermutation is needed, then an extra ArcIndexType * arc_capacity() is needed for it.
  • The reverse arcs from a node are sorted by head (so we could add a log() time lookup function).

Definition at line 547 of file graph.h.

Classes

class  IncomingArcIterator
 
class  OppositeIncomingArcIterator
 
class  OutgoingArcIterator
 
class  OutgoingOrOppositeIncomingArcIterator
 

Public Types

typedef NodeIndexType NodeIndex
 Typedef so you can use Graph::NodeIndex and Graph::ArcIndex to be generic but also to improve the readability of your code. More...
 
typedef ArcIndexType ArcIndex
 

Public Member Functions

 ReverseArcStaticGraph ()
 
 ReverseArcStaticGraph (NodeIndexType num_nodes, ArcIndexType arc_capacity)
 
ArcIndexType OutDegree (NodeIndexType node) const
 ReverseArcStaticGraph<>::OutDegree() and ::InDegree() work in O(1). More...
 
ArcIndexType InDegree (NodeIndexType node) const
 
BeginEndWrapper< OutgoingArcIteratorOutgoingArcs (NodeIndexType node) const
 
BeginEndWrapper< IncomingArcIteratorIncomingArcs (NodeIndexType node) const
 
BeginEndWrapper< OutgoingOrOppositeIncomingArcIteratorOutgoingOrOppositeIncomingArcs (NodeIndexType node) const
 
BeginEndWrapper< OppositeIncomingArcIteratorOppositeIncomingArcs (NodeIndexType node) const
 
BeginEndWrapper< OutgoingArcIteratorOutgoingArcsStartingFrom (NodeIndexType node, ArcIndexType from) const
 
BeginEndWrapper< IncomingArcIteratorIncomingArcsStartingFrom (NodeIndexType node, ArcIndexType from) const
 
BeginEndWrapper< OutgoingOrOppositeIncomingArcIteratorOutgoingOrOppositeIncomingArcsStartingFrom (NodeIndexType node, ArcIndexType from) const
 
BeginEndWrapper< OppositeIncomingArcIteratorOppositeIncomingArcsStartingFrom (NodeIndexType node, ArcIndexType from) const
 
BeginEndWrapper< NodeIndexType const * > operator[] (NodeIndexType node) const
 This loops over the heads of the OutgoingArcs(node). More...
 
ArcIndexType OppositeArc (ArcIndexType arc) const
 
NodeIndexType Head (ArcIndexType arc) const
 
NodeIndexType Tail (ArcIndexType arc) const
 
void ReserveArcs (ArcIndexType bound) override
 
void AddNode (NodeIndexType node)
 
ArcIndexType AddArc (NodeIndexType tail, NodeIndexType head)
 
void Build ()
 
void Build (std::vector< ArcIndexType > *permutation)
 
NodeIndexType num_nodes () const
 Returns the number of valid nodes in the graph. More...
 
ArcIndexType num_arcs () const
 Returns the number of valid arcs in the graph. More...
 
IntegerRange< NodeIndexAllNodes () const
 Allows nice range-based for loop: for (const NodeIndex node : graph.AllNodes()) { ... More...
 
IntegerRange< ArcIndexAllForwardArcs () const
 
bool IsNodeValid (NodeIndexType node) const
 Returns true if the given node is a valid node of the graph. More...
 
bool IsArcValid (ArcIndexType arc) const
 Returns true if the given arc is a valid arc of the graph. More...
 
NodeIndexType node_capacity () const
 Capacity reserved for future nodes, always >= num_nodes_. More...
 
ArcIndexType arc_capacity () const
 Capacity reserved for future arcs, always >= num_arcs_. More...
 
virtual void ReserveNodes (NodeIndexType bound)
 Changes the graph capacities. More...
 
void Reserve (NodeIndexType node_capacity, ArcIndexType arc_capacity)
 
void FreezeCapacities ()
 FreezeCapacities() makes any future attempt to change the graph capacities crash in DEBUG mode. More...
 
void GroupForwardArcsByFunctor (const A &a, B *b)
 
ArcIndexType max_end_arc_index () const
 

Static Public Attributes

static const NodeIndexType kNilNode
 Constants that will never be a valid node or arc. More...
 
static const ArcIndexType kNilArc
 

Protected Member Functions

void ComputeCumulativeSum (std::vector< ArcIndexType > *v)
 Functions commented when defined because they are implementation details. More...
 
void BuildStartAndForwardHead (SVector< NodeIndexType > *head, std::vector< ArcIndexType > *start, std::vector< ArcIndexType > *permutation)
 Given the tail of arc #i in (*head)[i] and the head of arc #i in (*head)[~i]. More...
 

Protected Attributes

NodeIndexType num_nodes_
 
NodeIndexType node_capacity_
 
ArcIndexType num_arcs_
 
ArcIndexType arc_capacity_
 
bool const_capacities_
 

Member Typedef Documentation

◆ ArcIndex

typedef ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::ArcIndex
inherited

Definition at line 190 of file graph.h.

◆ NodeIndex

typedef NodeIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::NodeIndex
inherited

Typedef so you can use Graph::NodeIndex and Graph::ArcIndex to be generic but also to improve the readability of your code.

We also recommend that you define a typedef ... Graph; for readability.

Definition at line 189 of file graph.h.

Constructor & Destructor Documentation

◆ ReverseArcStaticGraph() [1/2]

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::ReverseArcStaticGraph ( )
inline

Definition at line 558 of file graph.h.

◆ ReverseArcStaticGraph() [2/2]

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::ReverseArcStaticGraph ( NodeIndexType  num_nodes,
ArcIndexType  arc_capacity 
)
inline

Definition at line 559 of file graph.h.

Member Function Documentation

◆ AddArc()

template<typename NodeIndexType , typename ArcIndexType >
ArcIndexType util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::AddArc ( NodeIndexType  tail,
NodeIndexType  head 
)

We inverse head and tail here because it is more convenient this way during build time, see Build().

Definition at line 1745 of file graph.h.

◆ AddNode()

template<typename NodeIndexType , typename ArcIndexType >
void util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::AddNode ( NodeIndexType  node)

Definition at line 1737 of file graph.h.

◆ AllForwardArcs()

IntegerRange< ArcIndexType > util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::AllForwardArcs ( ) const
inherited

Definition at line 935 of file graph.h.

◆ AllNodes()

IntegerRange< NodeIndexType > util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::AllNodes ( ) const
inherited

Allows nice range-based for loop: for (const NodeIndex node : graph.AllNodes()) { ...

BaseGraph implementation -------------------------------------------------—.

} for (const ArcIndex arc : graph.AllForwardArcs()) { ... }

Definition at line 929 of file graph.h.

◆ arc_capacity()

ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::arc_capacity ( ) const
inherited

Capacity reserved for future arcs, always >= num_arcs_.

Todo:
(user): Same questions as the ones in node_capacity().

Definition at line 959 of file graph.h.

◆ Build() [1/2]

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
void util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::Build ( )
inline

Definition at line 606 of file graph.h.

◆ Build() [2/2]

template<typename NodeIndexType , typename ArcIndexType >
void util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::Build ( std::vector< ArcIndexType > *  permutation)

Computes incoming degree of each nodes.

Computes the reverse arcs of the forward arcs.

Note
this sort the reverse arcs with the same tail by head.
Todo:
(user): the 0 is wasted here, but minor optimisation.

Computes in reverse_start_ the start index of the reverse arcs.

Fill reverse arc information.

Definition at line 1759 of file graph.h.

◆ BuildStartAndForwardHead()

void util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::BuildStartAndForwardHead ( SVector< NodeIndexType > *  head,
std::vector< ArcIndexType > *  start,
std::vector< ArcIndexType > *  permutation 
)
protectedinherited

Given the tail of arc #i in (*head)[i] and the head of arc #i in (*head)[~i].

  • Reorder the arc by increasing tail.
  • Put the head of the new arc #i in (*head)[i].
  • Put in start[i] the index of the first arc with tail >= i.
  • Update "permutation" to reflect the change, unless it is NULL.

Computes the outgoing degree of each nodes and check if we need to permute something or not. Note that the tails are currently stored in the positive range of the SVector head.

Abort early if we do not need the permutation: we only need to put the heads in the positive range.

Computes the forward arc permutation.

Note
this temporarily alters the start vector.

Restore in (*start)[i] the index of the first arc with tail >= i.

Permutes the head into their final position in head. We do not need the tails anymore at this point.

Definition at line 995 of file graph.h.

◆ ComputeCumulativeSum()

void util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::ComputeCumulativeSum ( std::vector< ArcIndexType > *  v)
protectedinherited

Functions commented when defined because they are implementation details.

Computes the cummulative sum of the entry in v.

We only use it with in/out degree distribution, hence the Check() at the end.

Definition at line 978 of file graph.h.

◆ FreezeCapacities()

void util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::FreezeCapacities ( )
inherited

FreezeCapacities() makes any future attempt to change the graph capacities crash in DEBUG mode.

Todo:
(user): Only define this in debug mode at the cost of having a lot of ifndef NDEBUG all over the place? remove the function completely ?

Definition at line 966 of file graph.h.

◆ GroupForwardArcsByFunctor()

void util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::GroupForwardArcsByFunctor ( const A &  a,
B *  b 
)
inlineinherited
Todo:
(user): remove the public functions below.

They are just here during the transition from the old ebert_graph api to this new graph api.

Definition at line 264 of file graph.h.

◆ Head()

template<typename NodeIndexType , typename ArcIndexType >
NodeIndexType util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::Head ( ArcIndexType  arc) const
Todo:
(user): support Head() and Tail() before Build(), like StaticGraph<>.

Definition at line 1714 of file graph.h.

◆ IncomingArcs()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<IncomingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::IncomingArcs ( NodeIndexType  node) const

◆ IncomingArcsStartingFrom()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<IncomingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::IncomingArcsStartingFrom ( NodeIndexType  node,
ArcIndexType  from 
) const

◆ InDegree()

template<typename NodeIndexType , typename ArcIndexType >
ArcIndexType util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::InDegree ( NodeIndexType  node) const

Definition at line 1692 of file graph.h.

◆ IsArcValid()

bool util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::IsArcValid ( ArcIndexType  arc) const
inlineinherited

Returns true if the given arc is a valid arc of the graph.

Note
the arc validity range changes for graph with reverse arcs.

Definition at line 219 of file graph.h.

◆ IsNodeValid()

bool util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::IsNodeValid ( NodeIndexType  node) const
inlineinherited

Returns true if the given node is a valid node of the graph.

Definition at line 213 of file graph.h.

◆ max_end_arc_index()

ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::max_end_arc_index ( ) const
inlineinherited

Definition at line 267 of file graph.h.

◆ node_capacity()

NodeIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::node_capacity ( ) const
inherited

Capacity reserved for future nodes, always >= num_nodes_.

Todo:
(user): Is it needed? remove completely? return the real capacities at the cost of having a different implementation for each graphs?

Definition at line 951 of file graph.h.

◆ num_arcs()

ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::num_arcs ( ) const
inlineinherited

Returns the number of valid arcs in the graph.

Definition at line 204 of file graph.h.

◆ num_nodes()

NodeIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::num_nodes ( ) const
inlineinherited

Returns the number of valid nodes in the graph.

Definition at line 201 of file graph.h.

◆ operator[]()

template<typename NodeIndexType , typename ArcIndexType >
BeginEndWrapper< NodeIndexType const * > util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::operator[] ( NodeIndexType  node) const

This loops over the heads of the OutgoingArcs(node).

It is just a more convenient way to achieve this. Moreover this interface is used by some graph algorithms.

Definition at line 1699 of file graph.h.

◆ OppositeArc()

template<typename NodeIndexType , typename ArcIndexType >
ArcIndexType util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OppositeArc ( ArcIndexType  arc) const

Definition at line 1706 of file graph.h.

◆ OppositeIncomingArcs()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<OppositeIncomingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OppositeIncomingArcs ( NodeIndexType  node) const

◆ OppositeIncomingArcsStartingFrom()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<OppositeIncomingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OppositeIncomingArcsStartingFrom ( NodeIndexType  node,
ArcIndexType  from 
) const

◆ OutDegree()

template<typename NodeIndexType , typename ArcIndexType >
ArcIndexType util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutDegree ( NodeIndexType  node) const

ReverseArcStaticGraph<>::OutDegree() and ::InDegree() work in O(1).

Definition at line 1686 of file graph.h.

◆ OutgoingArcs()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<OutgoingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutgoingArcs ( NodeIndexType  node) const

◆ OutgoingArcsStartingFrom()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<OutgoingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutgoingArcsStartingFrom ( NodeIndexType  node,
ArcIndexType  from 
) const

◆ OutgoingOrOppositeIncomingArcs()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<OutgoingOrOppositeIncomingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutgoingOrOppositeIncomingArcs ( NodeIndexType  node) const

◆ OutgoingOrOppositeIncomingArcsStartingFrom()

template<typename NodeIndexType = int32, typename ArcIndexType = int32>
BeginEndWrapper<OutgoingOrOppositeIncomingArcIterator> util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutgoingOrOppositeIncomingArcsStartingFrom ( NodeIndexType  node,
ArcIndexType  from 
) const

◆ Reserve()

void util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::Reserve ( NodeIndexType  node_capacity,
ArcIndexType  arc_capacity 
)
inlineinherited

Definition at line 247 of file graph.h.

◆ ReserveArcs()

template<typename NodeIndexType , typename ArcIndexType >
void util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::ReserveArcs ( ArcIndexType  bound)
overridevirtual

Reimplemented from util::BaseGraph< NodeIndexType, ArcIndexType, true >.

Definition at line 1729 of file graph.h.

◆ ReserveNodes()

virtual void util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::ReserveNodes ( NodeIndexType  bound)
inlinevirtualinherited

Changes the graph capacities.

The functions will fail in debug mode if:

  • const_capacities_ is true.
  • A valid node does not fall into the new node range.
  • A valid arc does not fall into the new arc range. In non-debug mode, const_capacities_ is ignored and nothing will happen if the new capacity value for the arcs or the nodes is too small.

Reimplemented in util::ReverseArcListGraph< NodeIndexType, ArcIndexType >.

Definition at line 235 of file graph.h.

◆ Tail()

template<typename NodeIndexType , typename ArcIndexType >
NodeIndexType util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::Tail ( ArcIndexType  arc) const

Definition at line 1722 of file graph.h.

Member Data Documentation

◆ arc_capacity_

ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::arc_capacity_
protectedinherited

Definition at line 279 of file graph.h.

◆ const_capacities_

bool util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::const_capacities_
protectedinherited

Definition at line 280 of file graph.h.

◆ kNilArc

const ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::kNilArc
staticinherited

Definition at line 259 of file graph.h.

◆ kNilNode

const NodeIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::kNilNode
staticinherited

Constants that will never be a valid node or arc.

They are the maximum possible node and arc capacity.

Definition at line 258 of file graph.h.

◆ node_capacity_

NodeIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::node_capacity_
protectedinherited

Definition at line 277 of file graph.h.

◆ num_arcs_

ArcIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::num_arcs_
protectedinherited

Definition at line 278 of file graph.h.

◆ num_nodes_

NodeIndexType util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >::num_nodes_
protectedinherited

Definition at line 276 of file graph.h.


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