graph.h File Reference
#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <limits>
#include <new>
#include <vector>
#include "ortools/base/integral_types.h"
#include "ortools/base/logging.h"
#include "ortools/base/macros.h"
#include "ortools/graph/iterators.h"

Go to the source code of this file.

Classes

class  util::SVector< T >
 Forward declaration. More...
 
class  util::BaseGraph< NodeIndexType, ArcIndexType, HasReverseArcs >
 Base class of all Graphs implemented here. More...
 
class  util::ListGraph< NodeIndexType, ArcIndexType >
 Basic graph implementation without reverse arc. More...
 
class  util::StaticGraph< NodeIndexType, ArcIndexType >
 Most efficient implementation of a graph without reverse arcs: More...
 
class  util::ReverseArcListGraph< NodeIndexType, ArcIndexType >
 Extends the ListGraph by also storing the reverse arcs. More...
 
class  util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >
 StaticGraph with reverse arc. More...
 
class  util::ReverseArcMixedGraph< NodeIndexType, ArcIndexType >
 This graph is a mix between the ReverseArcListGraph and the ReverseArcStaticGraph. More...
 
class  util::SVector< T >
 Forward declaration. More...
 
class  util::ListGraph< NodeIndexType, ArcIndexType >::OutgoingArcIterator
 
class  util::ListGraph< NodeIndexType, ArcIndexType >::OutgoingHeadIterator
 
class  util::StaticGraph< NodeIndexType, ArcIndexType >::OutgoingArcIterator
 
class  util::ReverseArcListGraph< NodeIndexType, ArcIndexType >::OutgoingArcIterator
 
class  util::ReverseArcListGraph< NodeIndexType, ArcIndexType >::OppositeIncomingArcIterator
 
class  util::ReverseArcListGraph< NodeIndexType, ArcIndexType >::IncomingArcIterator
 
class  util::ReverseArcListGraph< NodeIndexType, ArcIndexType >::OutgoingOrOppositeIncomingArcIterator
 
class  util::ReverseArcListGraph< NodeIndexType, ArcIndexType >::OutgoingHeadIterator
 
class  util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutgoingArcIterator
 
class  util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OppositeIncomingArcIterator
 
class  util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::IncomingArcIterator
 
class  util::ReverseArcStaticGraph< NodeIndexType, ArcIndexType >::OutgoingOrOppositeIncomingArcIterator
 
class  util::ReverseArcMixedGraph< NodeIndexType, ArcIndexType >::OutgoingArcIterator
 
class  util::ReverseArcMixedGraph< NodeIndexType, ArcIndexType >::OppositeIncomingArcIterator
 
class  util::ReverseArcMixedGraph< NodeIndexType, ArcIndexType >::IncomingArcIterator
 
class  util::ReverseArcMixedGraph< NodeIndexType, ArcIndexType >::OutgoingOrOppositeIncomingArcIterator
 
class  util::CompleteGraph< NodeIndexType, ArcIndexType >
 CompleteGraph implementation ---------------------------------------------— Nodes and arcs are implicit and not stored. More...
 
class  util::CompleteBipartiteGraph< NodeIndexType, ArcIndexType >
 CompleteBipartiteGraph implementation ------------------------------------— Nodes and arcs are implicit and not stored. More...
 
class  util::CompleteBipartiteGraph< NodeIndexType, ArcIndexType >::OutgoingArcIterator
 

Namespaces

 util
 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
 

Macros

#define DEFINE_RANGE_BASED_ARC_ITERATION(c, t, e)
 Macros to wrap old style iteration into the new range-based for loop style. More...
 
#define DEFINE_STL_ITERATOR_FUNCTIONS(iterator_class_name)
 Adapt our old iteration style to support range-based for loops. More...
 

Typedefs

typedef ListGraph util::Graph
 Defining the simplest Graph interface as Graph for convenience. More...
 

Functions

template<class IntVector , class Array , class ElementType >
void util::PermuteWithExplicitElementType (const IntVector &permutation, Array *array_to_permute, ElementType unused)
 Permutes the elements of array_to_permute: element #i will be moved to position permutation[i]. More...
 
template<class IntVector , class Array >
void util::Permute (const IntVector &permutation, Array *array_to_permute)
 
template<class IntVector >
void util::Permute (const IntVector &permutation, std::vector< bool > *array_to_permute)
 We need a specialization for std::vector<bool>, because the default code uses (*array_to_permute)[0] as ElementType, which isn't 'bool' in that case. More...
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ListGraph, Outgoing, Base::kNilArc)
 ListGraph implementation -------------------------------------------------—. More...
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (StaticGraph, Outgoing, DirectArcLimit(node))
 StaticGraph implementation -----------------------------------------------—. More...
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcListGraph, Outgoing, Base::kNilArc)
 ReverseArcListGraph implementation ---------------------------------------—. More...
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcListGraph, Incoming, Base::kNilArc)
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcListGraph, OutgoingOrOppositeIncoming, Base::kNilArc)
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcListGraph, OppositeIncoming, Base::kNilArc)
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcStaticGraph, Outgoing, DirectArcLimit(node))
 ReverseArcStaticGraph implementation -------------------------------------—. More...
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcStaticGraph, Incoming, ReverseArcLimit(node))
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcStaticGraph, OutgoingOrOppositeIncoming, DirectArcLimit(node))
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcStaticGraph, OppositeIncoming, ReverseArcLimit(node))
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcMixedGraph, Outgoing, DirectArcLimit(node))
 ReverseArcMixedGraph implementation --------------------------------------—. More...
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcMixedGraph, Incoming, Base::kNilArc)
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcMixedGraph, OutgoingOrOppositeIncoming, DirectArcLimit(node))
 
 util::DEFINE_RANGE_BASED_ARC_ITERATION (ReverseArcMixedGraph, OppositeIncoming, Base::kNilArc)
 

Macro Definition Documentation

◆ DEFINE_RANGE_BASED_ARC_ITERATION

#define DEFINE_RANGE_BASED_ARC_ITERATION (   c,
  t,
 
)
Value:
template <typename NodeIndexType, typename ArcIndexType> \
BeginEndWrapper<typename c<NodeIndexType, ArcIndexType>::t##ArcIterator> \
c<NodeIndexType, ArcIndexType>::t##Arcs(NodeIndexType node) const { \
return BeginEndWrapper<t##ArcIterator>(t##ArcIterator(*this, node), \
t##ArcIterator(*this, node, e)); \
} \
template <typename NodeIndexType, typename ArcIndexType> \
BeginEndWrapper<typename c<NodeIndexType, ArcIndexType>::t##ArcIterator> \
c<NodeIndexType, ArcIndexType>::t##ArcsStartingFrom( \
NodeIndexType node, ArcIndexType from) const { \
return BeginEndWrapper<t##ArcIterator>(t##ArcIterator(*this, node, from), \
t##ArcIterator(*this, node, e)); \
}

Macros to wrap old style iteration into the new range-based for loop style.

The parameters are:

  • c: the class name.
  • t: the iteration type (Outgoing, Incoming, OutgoingOrOppositeIncoming or OppositeIncoming).
  • e: the "end" ArcIndexType.

Definition at line 1060 of file graph.h.

◆ DEFINE_STL_ITERATOR_FUNCTIONS

#define DEFINE_STL_ITERATOR_FUNCTIONS (   iterator_class_name)
Value:
using iterator_category = std::input_iterator_tag; \
using difference_type = ptrdiff_t; \
using pointer = const ArcIndexType*; \
using reference = const ArcIndexType&; \
using value_type = ArcIndexType; \
bool operator!=(const iterator_class_name& other) const { \
return this->index_ != other.index_; \
} \
bool operator==(const iterator_class_name& other) const { \
return this->index_ == other.index_; \
} \
ArcIndexType operator*() const { return this->Index(); } \
void operator++() { this->Next(); }
bool Next()
typename std::iterator_traits< Iterator >::value_type value_type
Definition: iterators.h:41

Adapt our old iteration style to support range-based for loops.

Add typedefs required by std::iterator_traits.

Definition at line 1077 of file graph.h.