Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <graph.h>
Classes | |
class | OutgoingArcIterator |
Public Member Functions | |
StaticGraph () | |
StaticGraph (NodeIndexType num_nodes, ArcIndexType arc_capacity) | |
NodeIndexType | Head (ArcIndexType arc) const |
NodeIndexType | Tail (ArcIndexType arc) const |
ArcIndexType | OutDegree (NodeIndexType node) const |
BeginEndWrapper< OutgoingArcIterator > | OutgoingArcs (NodeIndexType node) const |
BeginEndWrapper< OutgoingArcIterator > | OutgoingArcsStartingFrom (NodeIndexType node, ArcIndexType from) const |
absl::Span< const NodeIndexType > | operator[] (NodeIndexType node) const |
void | ReserveNodes (NodeIndexType bound) override |
void | ReserveArcs (ArcIndexType bound) override |
void | AddNode (NodeIndexType node) |
ArcIndexType | AddArc (NodeIndexType tail, NodeIndexType head) |
void | Build () |
void | Build (std::vector< ArcIndexType > *permutation) |
template<class ArcContainer > | |
StaticGraph< NodeIndexType, ArcIndexType > | FromArcs (NodeIndexType num_nodes, const ArcContainer &arcs) |
StaticGraph implementation -----------------------------------------------—. | |
bool | IsArcValid (ArcIndexType arc) const |
Public Member Functions inherited from util::BaseGraph< int32_t, int32_t, false > | |
BaseGraph () | |
BaseGraph (const BaseGraph &)=default | |
BaseGraph & | operator= (const BaseGraph &)=default |
virtual | ~BaseGraph ()=default |
int32_t | num_nodes () const |
int32_t | size () const |
int32_t | num_arcs () const |
Returns the number of valid arcs in the graph. | |
IntegerRange< NodeIndex > | AllNodes () const |
BaseGraph implementation -------------------------------------------------—. | |
IntegerRange< ArcIndex > | AllForwardArcs () const |
bool | IsNodeValid (int32_t node) const |
Returns true if the given node is a valid node of the graph. | |
bool | IsArcValid (int32_t arc) const |
int32_t | node_capacity () const |
Capacity reserved for future nodes, always >= num_nodes_. | |
int32_t | arc_capacity () const |
Capacity reserved for future arcs, always >= num_arcs_. | |
virtual void | ReserveNodes (int32_t bound) |
virtual void | ReserveArcs (int32_t bound) |
void | Reserve (int32_t node_capacity, int32_t arc_capacity) |
void | FreezeCapacities () |
void | GroupForwardArcsByFunctor (const A &a, B *b) |
int32_t | max_end_arc_index () const |
Static Public Member Functions | |
template<class ArcContainer > | |
static StaticGraph | FromArcs (NodeIndexType num_nodes, const ArcContainer &arcs) |
Shortcut to directly create a finalized graph, i.e. Build() is called. | |
Additional Inherited Members | |
Public Types inherited from util::BaseGraph< int32_t, int32_t, false > | |
typedef int32_t | NodeIndex |
typedef int32_t | ArcIndex |
Static Public Attributes inherited from util::BaseGraph< int32_t, int32_t, false > | |
static const int32_t | kNilNode |
static const int32_t | kNilArc |
Protected Member Functions inherited from util::BaseGraph< int32_t, int32_t, false > | |
void | ComputeCumulativeSum (std::vector< int32_t > *v) |
Functions commented when defined because they are implementation details. | |
void | BuildStartAndForwardHead (SVector< int32_t > *head, std::vector< int32_t > *start, std::vector< int32_t > *permutation) |
Protected Attributes inherited from util::BaseGraph< int32_t, int32_t, false > | |
int32_t | num_nodes_ |
int32_t | node_capacity_ |
int32_t | num_arcs_ |
int32_t | arc_capacity_ |
bool | const_capacities_ |
Most efficient implementation of a graph without reverse arcs:
NOTE(user): if the need arises for very-well compressed graphs, we could shave NodeIndexType * arc_capacity() off the permanent memory requirement with a similar class that doesn't support Tail(), i.e. StaticGraphWithoutTail<>. This almost corresponds to a past implementation of StaticGraph<> @CL 116144340.
|
inline |
|
inline |
ArcIndexType util::StaticGraph< NodeIndexType, ArcIndexType >::AddArc | ( | NodeIndexType | tail, |
NodeIndexType | head ) |
void util::StaticGraph< NodeIndexType, ArcIndexType >::AddNode | ( | NodeIndexType | node | ) |
|
inline |
void util::StaticGraph< NodeIndexType, ArcIndexType >::Build | ( | std::vector< ArcIndexType > * | permutation | ) |
Implementation details: A reader may be surprised that we do many passes into the data where things could be done in one pass. For instance, during construction, we store the edges first, and then do a second pass at the end to compute the degree distribution.
This is because it is a lot more efficient cache-wise to do it this way. This was determined by various experiments, but can also be understood:
If Arc are in order, start_ already contains the degree distribution.
Computes outgoing degree of each nodes. We have to clear start_, since at least the first arc was processed with arc_in_order_ == true.
Computes the forward arc permutation.
We use "tail_" (which now contains rubbish) to permute "head_" faster.
Restore in start_[i] the index of the first arc with tail >= i.
Recompute the correct tail_ vector
|
static |
Shortcut to directly create a finalized graph, i.e. Build() is called.
StaticGraph< NodeIndexType, ArcIndexType > util::StaticGraph< NodeIndexType, ArcIndexType >::FromArcs | ( | NodeIndexType | num_nodes, |
const ArcContainer & | arcs ) |
StaticGraph implementation -----------------------------------------------—.
NodeIndexType util::StaticGraph< NodeIndexType, ArcIndexType >::Head | ( | ArcIndexType | arc | ) | const |
|
inline |
absl::Span< const NodeIndexType > util::StaticGraph< NodeIndexType, ArcIndexType >::operator[] | ( | NodeIndexType | node | ) | const |
ArcIndexType util::StaticGraph< NodeIndexType, ArcIndexType >::OutDegree | ( | NodeIndexType | node | ) | const |
BeginEndWrapper< OutgoingArcIterator > util::StaticGraph< NodeIndexType, ArcIndexType >::OutgoingArcs | ( | NodeIndexType | node | ) | const |
BeginEndWrapper< OutgoingArcIterator > util::StaticGraph< NodeIndexType, ArcIndexType >::OutgoingArcsStartingFrom | ( | NodeIndexType | node, |
ArcIndexType | from ) const |
|
override |
|
override |
NodeIndexType util::StaticGraph< NodeIndexType, ArcIndexType >::Tail | ( | ArcIndexType | arc | ) | const |