operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType > Class Template Reference

Detailed Description

template<typename NodeIndexType, typename ArcIndexType>
class operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >

Definition at line 192 of file ebert_graph.h.

Classes

class  CycleHandlerForAnnotatedArcs
 

Public Types

typedef NodeIndexType NodeIndex
 
typedef ArcIndexType ArcIndex
 

Public Member Functions

 ForwardStaticGraph (const NodeIndexType num_nodes, const ArcIndexType num_arcs, const bool sort_arcs_by_head, std::vector< std::pair< NodeIndexType, NodeIndexType > > *client_input_arcs, operations_research::PermutationCycleHandler< ArcIndexType > *const client_cycle_handler)
 Constructor for use by GraphBuilderFromArcs instances and direct clients that want to materialize a graph in one step. More...
 
NodeIndexType Tail (const ArcIndexType arc) const
 Returns the tail or start-node of arc. More...
 
bool IsIncoming (ArcIndexType arc, NodeIndexType node) const
 Returns true if arc is incoming to node. More...
 
bool CheckArcBounds (const ArcIndexType arc) const
 Utility function to check that an arc index is within the bounds. More...
 
bool CheckArcValidity (const ArcIndexType arc) const
 Utility function to check that an arc index is within the bounds AND different from kNilArc. More...
 
bool CheckTailIndexValidity (const ArcIndexType arc) const
 Returns true if arc is a valid index into the (*tail_) array. More...
 
ArcIndexType NextOutgoingArc (const NodeIndexType node, ArcIndexType arc) const
 
std::string DebugString () const
 Returns a debug std::string containing all the information contained in the data structure in raw form. More...
 
bool BuildTailArray ()
 
void ReleaseTailArray ()
 
bool TailArrayComplete () const
 To be used in a DCHECK(). More...
 
NodeIndexType num_nodes () const
 Returns the number of nodes in the graph. More...
 
ArcIndexType num_arcs () const
 Returns the number of original arcs in the graph (The ones with positive indices.) More...
 
NodeIndexType end_node_index () const
 Returns one more than the largest index of an extant node, meaning a node that is mentioned as the head or tail of some arc in the graph. More...
 
ArcIndexType end_arc_index () const
 Returns one more than the largest index of an extant direct arc. More...
 
NodeIndexType max_num_nodes () const
 Returns the maximum possible number of nodes in the graph. More...
 
ArcIndexType max_num_arcs () const
 Returns the maximum possible number of original arcs in the graph. More...
 
NodeIndexType max_end_node_index () const
 Returns one more than the largest valid index of a node. More...
 
ArcIndexType max_end_arc_index () const
 Returns one more than the largest valid index of a direct arc. More...
 
bool IsNodeValid (NodeIndexType node) const
 Utility function to check that a node index is within the bounds AND different from kNilNode. More...
 
ArcIndexType LookUpArc (const NodeIndexType tail, const NodeIndexType head) const
 Returns the first arc going from tail to head, if it exists, or kNilArc if such an arc does not exist. More...
 
NodeIndexType Head (const ArcIndexType arc) const
 Returns the head or end-node of arc. More...
 
std::string NodeDebugString (const NodeIndexType node) const
 
std::string ArcDebugString (const ArcIndexType arc) const
 

Static Public Attributes

static const NodeIndexType kNilNode
 The index of the 'nil' node in the graph. More...
 
static const ArcIndexType kNilArc
 The index of the 'nil' arc in the graph. More...
 
static const NodeIndexType kFirstNode
 The index of the first node in the graph. More...
 
static const ArcIndexType kFirstArc
 The index of the first arc in the graph. More...
 
static const NodeIndexType kMaxNumNodes
 The maximum possible number of nodes in the graph. More...
 
static const ArcIndexType kMaxNumArcs
 The maximum possible number of arcs in the graph. More...
 

Protected Member Functions

NodeIndexType StartNode (NodeIndexType node) const
 Returns kNilNode if the graph has no nodes or node if it has at least one node. More...
 
ArcIndexType StartArc (ArcIndexType arc) const
 Returns kNilArc if the graph has no arcs arc if it has at least one arc. More...
 
NodeIndexType NextNode (const NodeIndexType node) const
 Returns the node following the argument in the graph. More...
 
ArcIndexType NextArc (const ArcIndexType arc) const
 Returns the arc following the argument in the graph. More...
 
ArcIndexType FirstOutgoingArc (const NodeIndexType node) const
 Returns the first outgoing arc for node. More...
 

Protected Attributes

NodeIndexType max_num_nodes_
 The maximum number of nodes that the graph can hold. More...
 
ArcIndexType max_num_arcs_
 The maximum number of arcs that the graph can hold. More...
 
NodeIndexType num_nodes_
 The maximum index of the node currently held by the graph. More...
 
ArcIndexType num_arcs_
 The current number of arcs held by the graph. More...
 
ZVector< NodeIndexType > head_
 Array of node indices. head_[i] contains the head node of arc i. More...
 
ZVector< ArcIndexType > first_incident_arc_
 Array of arc indices. More...
 

Friends

class StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >
 

Member Typedef Documentation

◆ ArcIndex

template<typename NodeIndexType , typename ArcIndexType >
typedef ArcIndexType operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::ArcIndex

Definition at line 565 of file ebert_graph.h.

◆ NodeIndex

template<typename NodeIndexType , typename ArcIndexType >
typedef NodeIndexType operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::NodeIndex

Definition at line 564 of file ebert_graph.h.

Constructor & Destructor Documentation

◆ ForwardStaticGraph()

template<typename NodeIndexType , typename ArcIndexType >
operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::ForwardStaticGraph ( const NodeIndexType  num_nodes,
const ArcIndexType  num_arcs,
const bool  sort_arcs_by_head,
std::vector< std::pair< NodeIndexType, NodeIndexType > > *  client_input_arcs,
operations_research::PermutationCycleHandler< ArcIndexType > *const  client_cycle_handler 
)
inline

Constructor for use by GraphBuilderFromArcs instances and direct clients that want to materialize a graph in one step.

Materializing all at once is the only choice available with a static graph.

Args: sort_arcs_by_head: determines whether arcs incident to each tail node are sorted by head node. client_cycle_handler: if non-NULL, mediates the permutation of arbitrary annotation data belonging to the client according to the permutation applied to the arcs in forming the graph. Two permutations may be composed to form the final one that affects the arcs. First, the arcs are always permuted to group them by tail node because ForwardStaticGraph requires this. Second, if each node's outgoing arcs are sorted by head node (according to sort_arcs_by_head), that sorting implies an additional permutation on the arcs.

A more convenient name for a parameter required by style to be a pointer, because we modify its referent.

We coopt the first_incident_arc_ array as a node-indexed vector used for two purposes related to degree before setting up its final values. First, it counts the out-degree of each node. Second, it is reused to count the number of arcs outgoing from each node that have already been put in place from the given input_arcs. We reserve an extra entry as a sentinel at the end.

Take this opportunity to see how many nodes are really mentioned in the arc list.

The head_ entry will get permuted into the right place later.

We reuse the input_arcs[].first entries to hold our mapping to the head_ array. This allows us to spread out cache badness.

We cannot reuse the input_arcs[].first entries so we map to the head_ array in a single loop.

Shift the entries in first_incident_arc_ to compensate for the counting each one has done through its incident arcs. Note that there is a special sentry element at the end of first_incident_arc_.

The second argument in the following has a strange index expression because ZVector claims that no index is valid unless it refers to an element in the vector. In particular an index one past the end is invalid.

Apply the computed permutation if we haven't already.

We use a permutation cycle handler to place the head array indices and permute the client's arc annotation data along with them.

Parameters
client_cycle_handler
Todo:
(user): For some reason, SWIG breaks if the operations_research namespace is not explicit in the following argument declaration.

Definition at line 621 of file ebert_graph.h.

Member Function Documentation

◆ ArcDebugString()

std::string operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::ArcDebugString ( const ArcIndexType  arc) const
inlineinherited

Definition at line 310 of file ebert_graph.h.

◆ BuildTailArray()

template<typename NodeIndexType , typename ArcIndexType >
bool operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::BuildTailArray ( )
inline

If (*tail_) is already allocated, we have the invariant that its contents are canonical, so we do not need to do anything here in that case except return true.

We have been asked to build the (*tail_) array, but we have no valid information from which to build it. The graph is in an unrecoverable, inconsistent state.

Reallocate (*tail_) and rebuild its contents from the adjacency lists.

Definition at line 816 of file ebert_graph.h.

◆ CheckArcBounds()

template<typename NodeIndexType , typename ArcIndexType >
bool operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::CheckArcBounds ( const ArcIndexType  arc) const
inline

Utility function to check that an arc index is within the bounds.

It is exported so that users of the ForwardStaticGraph class can use it. To be used in a DCHECK.

Definition at line 770 of file ebert_graph.h.

◆ CheckArcValidity()

template<typename NodeIndexType , typename ArcIndexType >
bool operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::CheckArcValidity ( const ArcIndexType  arc) const
inline

Utility function to check that an arc index is within the bounds AND different from kNilArc.

It is exported so that users of the ForwardStaticGraph class can use it. To be used in a DCHECK.

Definition at line 778 of file ebert_graph.h.

◆ CheckTailIndexValidity()

template<typename NodeIndexType , typename ArcIndexType >
bool operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::CheckTailIndexValidity ( const ArcIndexType  arc) const
inline

Returns true if arc is a valid index into the (*tail_) array.

Definition at line 783 of file ebert_graph.h.

◆ DebugString()

template<typename NodeIndexType , typename ArcIndexType >
std::string operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::DebugString ( ) const
inline

Returns a debug std::string containing all the information contained in the data structure in raw form.

Definition at line 802 of file ebert_graph.h.

◆ end_arc_index()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::end_arc_index ( ) const
inlineinherited

Returns one more than the largest index of an extant direct arc.

To be used as a helper when clients need to dimension or iterate over arrays of arc annotation information.

Definition at line 252 of file ebert_graph.h.

◆ end_node_index()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::end_node_index ( ) const
inlineinherited

Returns one more than the largest index of an extant node, meaning a node that is mentioned as the head or tail of some arc in the graph.

To be used as a helper when clients need to dimension or iterate over arrays of node annotation information.

Definition at line 247 of file ebert_graph.h.

◆ FirstOutgoingArc()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::FirstOutgoingArc ( const NodeIndexType  node) const
inlineprotectedinherited

Returns the first outgoing arc for node.

Definition at line 479 of file ebert_graph.h.

◆ Head()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::Head ( const ArcIndexType  arc) const
inlineinherited

Returns the head or end-node of arc.

Definition at line 297 of file ebert_graph.h.

◆ IsIncoming()

template<typename NodeIndexType , typename ArcIndexType >
bool operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::IsIncoming ( ArcIndexType  arc,
NodeIndexType  node 
) const
inline

Returns true if arc is incoming to node.

Definition at line 763 of file ebert_graph.h.

◆ IsNodeValid()

bool operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::IsNodeValid ( NodeIndexType  node) const
inlineinherited

Utility function to check that a node index is within the bounds AND different from kNilNode.

Returns true if node is in the range [kFirstNode .. max_num_nodes_). It is exported so that users of the DerivedGraph class can use it. To be used in a DCHECK; also used internally to validate arguments passed to our methods from clients (e.g., AddArc()).

Definition at line 279 of file ebert_graph.h.

◆ LookUpArc()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::LookUpArc ( const NodeIndexType  tail,
const NodeIndexType  head 
) const
inlineinherited

Returns the first arc going from tail to head, if it exists, or kNilArc if such an arc does not exist.

Definition at line 285 of file ebert_graph.h.

◆ max_end_arc_index()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::max_end_arc_index ( ) const
inlineinherited

Returns one more than the largest valid index of a direct arc.

To be used as a helper when clients need to dimension or iterate over arrays of arc annotation information.

Definition at line 271 of file ebert_graph.h.

◆ max_end_node_index()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::max_end_node_index ( ) const
inlineinherited

Returns one more than the largest valid index of a node.

To be used as a helper when clients need to dimension or iterate over arrays of node annotation information.

Definition at line 264 of file ebert_graph.h.

◆ max_num_arcs()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::max_num_arcs ( ) const
inlineinherited

Returns the maximum possible number of original arcs in the graph.

(The ones with positive indices.)

Definition at line 259 of file ebert_graph.h.

◆ max_num_nodes()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::max_num_nodes ( ) const
inlineinherited

Returns the maximum possible number of nodes in the graph.

Definition at line 255 of file ebert_graph.h.

◆ NextArc()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::NextArc ( const ArcIndexType  arc) const
inlineprotectedinherited

Returns the arc following the argument in the graph.

Returns kNilArc (= end) if the range of arcs has been exhausted. It is called by ArcIterator::Next() and as such does not expect to be passed an argument equal to kNilArc. This is why the return line is simplified from return ( arc == kNilArc || next_arc >= num_arcs_) ? kNilArc : next_arc; to return next_arc < num_arcs_ ? next_arc : kNilArc;

Definition at line 472 of file ebert_graph.h.

◆ NextNode()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::NextNode ( const NodeIndexType  node) const
inlineprotectedinherited

Returns the node following the argument in the graph.

Returns kNilNode (= end) if the range of nodes has been exhausted. It is called by NodeIterator::Next() and as such does not expect to be passed an argument equal to kNilNode. This is why the return line is simplified from return (node == kNilNode || next_node >= num_nodes_) ? kNilNode : next_node; to return next_node < num_nodes_ ? next_node : kNilNode;

Definition at line 458 of file ebert_graph.h.

◆ NextOutgoingArc()

template<typename NodeIndexType , typename ArcIndexType >
ArcIndexType operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::NextOutgoingArc ( const NodeIndexType  node,
ArcIndexType  arc 
) const
inline

Definition at line 788 of file ebert_graph.h.

◆ NodeDebugString()

std::string operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::NodeDebugString ( const NodeIndexType  node) const
inlineinherited

Definition at line 302 of file ebert_graph.h.

◆ num_arcs()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::num_arcs ( ) const
inlineinherited

Returns the number of original arcs in the graph (The ones with positive indices.)

Definition at line 241 of file ebert_graph.h.

◆ num_nodes()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::num_nodes ( ) const
inlineinherited

Returns the number of nodes in the graph.

Definition at line 237 of file ebert_graph.h.

◆ ReleaseTailArray()

template<typename NodeIndexType , typename ArcIndexType >
void operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::ReleaseTailArray ( )
inline

Definition at line 844 of file ebert_graph.h.

◆ StartArc()

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::StartArc ( ArcIndexType  arc) const
inlineprotectedinherited

Returns kNilArc if the graph has no arcs arc if it has at least one arc.

Useful for initializing iterators correctly in the case of empty graphs.

Definition at line 445 of file ebert_graph.h.

◆ StartNode()

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::StartNode ( NodeIndexType  node) const
inlineprotectedinherited

Returns kNilNode if the graph has no nodes or node if it has at least one node.

Useful for initializing iterators correctly in the case of empty graphs.

Definition at line 439 of file ebert_graph.h.

◆ Tail()

template<typename NodeIndexType , typename ArcIndexType >
NodeIndexType operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::Tail ( const ArcIndexType  arc) const
inline

Returns the tail or start-node of arc.

Definition at line 756 of file ebert_graph.h.

◆ TailArrayComplete()

template<typename NodeIndexType , typename ArcIndexType >
bool operations_research::ForwardStaticGraph< NodeIndexType, ArcIndexType >::TailArrayComplete ( ) const
inline

To be used in a DCHECK().

Definition at line 847 of file ebert_graph.h.

Friends And Related Function Documentation

◆ StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >

template<typename NodeIndexType , typename ArcIndexType >
friend class StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >
friend

Definition at line 541 of file ebert_graph.h.

Member Data Documentation

◆ first_incident_arc_

ZVector<ArcIndexType> operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::first_incident_arc_
protectedinherited

Array of arc indices.

first_incident_arc_[i] contains the first arc incident to node i.

Definition at line 502 of file ebert_graph.h.

◆ head_

ZVector<NodeIndexType> operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::head_
protectedinherited

Array of node indices. head_[i] contains the head node of arc i.

Definition at line 498 of file ebert_graph.h.

◆ kFirstArc

const ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::kFirstArc
staticinherited

The index of the first arc in the graph.

Definition at line 225 of file ebert_graph.h.

◆ kFirstNode

const NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::kFirstNode
staticinherited

The index of the first node in the graph.

Definition at line 222 of file ebert_graph.h.

◆ kMaxNumArcs

const ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::kMaxNumArcs
staticinherited

The maximum possible number of arcs in the graph.

(The maximum index is kMaxNumArcs-1, since indices start at 0. Unfortunately we waste a value representing this and the max_num_arcs_ member.)

(The maximum index is kMaxNumArcs-1, since indices start at 0.)

Definition at line 235 of file ebert_graph.h.

◆ kMaxNumNodes

const NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::kMaxNumNodes
staticinherited

The maximum possible number of nodes in the graph.

The maximum possible node index in the graph.

(The maximum index is kMaxNumNodes-1, since indices start at 0. Unfortunately we waste a value representing this and the max_num_nodes_ member.)

Definition at line 230 of file ebert_graph.h.

◆ kNilArc

const ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::kNilArc
staticinherited

The index of the 'nil' arc in the graph.

Definition at line 219 of file ebert_graph.h.

◆ kNilNode

const NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::kNilNode
staticinherited

The index of the 'nil' node in the graph.

Definition at line 216 of file ebert_graph.h.

◆ max_num_arcs_

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::max_num_arcs_
protectedinherited

The maximum number of arcs that the graph can hold.

Definition at line 489 of file ebert_graph.h.

◆ max_num_nodes_

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::max_num_nodes_
protectedinherited

The maximum number of nodes that the graph can hold.

Definition at line 486 of file ebert_graph.h.

◆ num_arcs_

ArcIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::num_arcs_
protectedinherited

The current number of arcs held by the graph.

Definition at line 495 of file ebert_graph.h.

◆ num_nodes_

NodeIndexType operations_research::StarGraphBase< NodeIndexType, ArcIndexType, ForwardStaticGraph< NodeIndexType, ArcIndexType > >::num_nodes_
protectedinherited

The maximum index of the node currently held by the graph.

Definition at line 492 of file ebert_graph.h.


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