16 #include "../gl_base.hpp"
21 #include "../algorithms/HavelHakimi.hpp"
38 template <
class SCALAR =
int,
class STORAGE_KIND = gl::List,
class DIRECTION = gl::Undirected>
51 template <
class info_t>
64 template <
bool IsConst = true>
69 using reference = std::conditional_t<IsConst, const Edge &, Edge &>;
70 using pointer = std::conditional_t<IsConst, const Edge *, Edge *>;
75 using matrix_iterator_t = std::conditional_t<IsConst, typename matrix_t::const_iterator, typename matrix_t::iterator>;
76 using rootList_iterator_t = std::conditional_t<IsConst, typename rootList_t::const_iterator, typename rootList_t::iterator>;
77 using list_iterator_t = std::conditional_t<IsConst, typename nodeList_t::const_iterator, typename nodeList_t::iterator>;
89 #ifndef DOXYGEN_SHOULD_SKIP_THIS
101 #ifndef DOXYGEN_SHOULD_SKIP_THIS
112 #ifndef DOXYGEN_SHOULD_SKIP_THIS
128 #ifndef DOXYGEN_SHOULD_SKIP_THIS
141 #ifndef DOXYGEN_SHOULD_SKIP_THIS
178 #ifndef DOXYGEN_SHOULD_SKIP_THIS
179 template <
bool _IsConst = IsConst>
180 std::enable_if_t<_IsConst, reference>
190 #ifndef DOXYGEN_SHOULD_SKIP_THIS
191 template <
bool _IsConst = IsConst>
192 std::enable_if_t<!_IsConst, reference>
202 #ifndef DOXYGEN_SHOULD_SKIP_THIS
203 template <
bool _IsConst = IsConst>
204 std::enable_if_t<_IsConst, pointer>
214 #ifndef DOXYGEN_SHOULD_SKIP_THIS
215 template <
bool _IsConst = IsConst>
216 std::enable_if_t<!_IsConst, pointer>
281 Graph(
const std::string °reeSeq,
const std::string &label =
"Simple Undirected Graph")
283 std::stringstream iss(degreeSeq);
286 while (iss >> degree)
287 degrees.push_back(degree);
300 if (degrees[i] > 0 && degrees[j] > 0)
329 #ifndef DOXYGEN_SHOULD_SKIP_THIS
330 GL_ENABLE_IF_LIST_DIRECTED
335 for (
idx_t start = 0; start <
edges_.size(); ++start)
337 for (
auto &end :
edges_[start])
339 out.
setEdge(start, end.dest(), end.weight(), end.color());
344 #ifndef DOXYGEN_SHOULD_SKIP_THIS
348 GL_ENABLE_IF_LIST_UNDIRECTED
352 for (
idx_t start = 0; start <
edges_.size(); ++start)
354 for (
auto &end :
edges_[start])
356 if (!out.hasEdge(start, end.dest()))
357 out.setEdge(start, end.dest(), end.weight(), end.color());
368 #ifndef DOXYGEN_SHOULD_SKIP_THIS
376 out.
setEdge(edge->source(), edge->dest(), edge->weight(), edge->color());
419 #ifndef DOXYGEN_SHOULD_SKIP_THIS
420 GL_ENABLE_IF_UNDIRECTED
430 #ifndef DOXYGEN_SHOULD_SKIP_THIS
434 GL_ENABLE_IF_DIRECTED
440 #ifndef DOXYGEN_SHOULD_SKIP_THIS
441 GL_ENABLE_IF_UNDIRECTED
451 #ifndef DOXYGEN_SHOULD_SKIP_THIS
455 GL_ENABLE_IF_DIRECTED
469 std::deque<std::pair<idx_t, idx_t>> queue;
472 queue.push_front(std::make_pair(v, parent));
475 while (!queue.empty())
477 v = queue.front().first;
478 parent = queue.front().second;
482 for (
auto elem : tempList)
486 queue.push_front(std::make_pair(elem, v));
487 visited[elem] =
true;
489 else if (elem != parent)
507 #ifndef DOXYGEN_SHOULD_SKIP_THIS
508 GL_ENABLE_IF_LIST_DIRECTED
512 GL_ASSERT((!
hasEdge(start, end)), std::string(
"There is already an edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
514 edges_[start].push_back(
Edge(start, end, weight, color,
true));
516 nodes_[start].outDegreeIncrement();
517 nodes_[end].inDegreeIncrement();
520 #ifndef DOXYGEN_SHOULD_SKIP_THIS
524 GL_ENABLE_IF_LIST_UNDIRECTED
527 GL_ASSERT((!
hasEdge(start, end)), std::string(
"There is already an edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
528 edges_[start].push_back(
Edge(start, end, weight, color,
true));
530 nodes_[start].outDegreeIncrement();
531 nodes_[end].inDegreeIncrement();
534 edges_[end].push_back(
Edge(end, start, weight, color,
true));
535 nodes_[start].inDegreeIncrement();
536 nodes_[end].outDegreeIncrement();
543 GL_ENABLE_IF_MATRIX_DIRECTED
546 GL_ASSERT((!
hasEdge(start, end)), std::string(
"There is already an edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
551 nodes_[start].outDegreeIncrement();
552 nodes_[end].inDegreeIncrement();
558 GL_ENABLE_IF_MATRIX_UNDIRECTED
562 std::swap(end, start);
563 GL_ASSERT((!
hasEdge(start, end)), std::string(
"There is already an edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
570 nodes_[start].inDegreeIncrement();
571 nodes_[start].outDegreeIncrement();
572 nodes_[end].inDegreeIncrement();
573 nodes_[end].outDegreeIncrement();
600 is.open(inFile, std::ios::in);
601 GL_ASSERT(is.is_open(),std::string(std::string(
"Error: failed to open ")+inFile))
606 if (is >> start >> end >> weight)
628 is.open(inFile, std::ios::in);
629 GL_ASSERT(is.is_open(),std::string(std::string(
"Error: failed to open ")+inFile))
635 while (std::getline(is,line))
637 std::stringstream ss(line);
638 while (std::getline(ss,field,
','))
640 std::stringstream fs(field);
642 if (!(fs >> weight)) {
668 #ifdef DOXYGEN_SHOULD_SKIP_THIS
671 #ifndef DOXYGEN_SHOULD_SKIP_THIS
672 template <
typename ... Args,
typename STORAGE = STORAGE_KIND,
typename DIR = DIRECTION, GL_ENABLE_IF_LIST_DIRECTED_T>
675 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
676 auto it = std::find_if(
edges_[start].begin(),
edges_[start].end(),
677 [&end](
const Edge &node) {
return node.
dest() == end; });
678 updateEdgeInternal(it, args...);
680 template <
typename ... Args,
typename STORAGE = STORAGE_KIND,
typename DIR = DIRECTION, GL_ENABLE_IF_LIST_UNDIRECTED_T>
683 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
684 auto it = std::find_if(
edges_[start].begin(),
edges_[start].end(),
685 [&end](
const Edge &node) {
return node.dest() == end; });
686 updateEdgeInternal(it, args...);
687 it = std::find_if(
edges_[end].begin(),
edges_[end].end(),
688 [&start](
const Edge &node) {
return node.dest() == start; });
689 updateEdgeInternal(it, args...);
691 template <
typename ... Args,
typename STORAGE = STORAGE_KIND,
typename DIR = DIRECTION, GL_ENABLE_IF_MATRIX_DIRECTED_T>
694 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
695 updateEdgeInternal(
edges_.data()+start *
numNodes() + end, args...);
697 template <
typename ... Args,
typename STORAGE = STORAGE_KIND,
typename DIR = DIRECTION, GL_ENABLE_IF_MATRIX_UNDIRECTED_T>
700 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
701 updateEdgeInternal(
edges_.data()+start *
numNodes() + end, args...);
702 updateEdgeInternal(
edges_.data()+end *
numNodes() + start, args...);
705 template <
typename Target,
typename First,
typename ... OtherArgs>
706 inline void updateEdgeInternal (
const Target& it, First arg,
const OtherArgs&... rest)
708 throw std::runtime_error( std::string(__FILE__)
710 + std::to_string(__LINE__)
711 + std::string(
" in ")
712 + std::string(__PRETTY_FUNCTION__)
713 + std::string(
": Unknown argument type."));
715 template <
typename Target,
typename ... OtherArgs>
716 inline void updateEdgeInternal (
const Target& it,
const val_t& arg,
const OtherArgs&... rest)
719 updateEdgeInternal(it,rest...);
721 template <
typename Target,
typename ... OtherArgs>
722 inline void updateEdgeInternal (
const Target& it,
const gl::Color& arg,
const OtherArgs&... rest)
725 updateEdgeInternal(it,rest...);
727 template <
typename Target>
728 inline void updateEdgeInternal (
const Target& it)
738 #ifndef DOXYGEN_SHOULD_SKIP_THIS
739 GL_ENABLE_IF_LIST_DIRECTED
743 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
744 auto it = std::find_if(
edges_[start].begin(),
edges_[start].end(),
745 [&end](
const Edge &node) {
return node.
dest() == end; });
748 nodes_[start].outDegreeDecrement();
749 nodes_[end].inDegreeDecrement();
751 #ifndef DOXYGEN_SHOULD_SKIP_THIS
755 GL_ENABLE_IF_LIST_UNDIRECTED
758 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
759 auto it = std::find_if(
edges_[start].begin(),
edges_[start].end(),
760 [&end](
const Edge &node) {
return node.
dest() == end; });
763 nodes_[start].inDegreeDecrement();
764 nodes_[start].outDegreeDecrement();
767 it = std::find_if(
edges_[end].begin(),
edges_[end].end(),
768 [&start](
const Edge &node) {
return node.dest() == start; });
770 nodes_[end].inDegreeDecrement();
771 nodes_[end].outDegreeDecrement();
778 GL_ENABLE_IF_MATRIX_DIRECTED
781 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
786 nodes_[start].outDegreeDecrement();
787 nodes_[end].inDegreeDecrement();
793 GL_ENABLE_IF_MATRIX_UNDIRECTED
796 GL_ASSERT((
hasEdge(start, end)), std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end));
798 std::swap(end, start);
802 nodes_[start].inDegreeDecrement();
803 nodes_[start].outDegreeDecrement();
804 nodes_[end].inDegreeDecrement();
805 nodes_[end].outDegreeDecrement();
815 #ifndef DOXYGEN_SHOULD_SKIP_THIS
821 auto it = std::find_if(
edges_[start].begin(),
edges_[start].end(),
822 [&end](
const Edge &node) {
return node.
dest() == end; });
823 return it !=
edges_[start].end();
825 #ifndef DOXYGEN_SHOULD_SKIP_THIS
829 GL_ENABLE_IF_MATRIX_DIRECTED
839 GL_ENABLE_IF_MATRIX_UNDIRECTED
844 std::swap(end, start);
855 #ifndef DOXYGEN_SHOULD_SKIP_THIS
860 GL_ASSERT(
hasEdge(start, end), (std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end)))
861 auto it = std::find_if(
edges_[start].begin(),
edges_[start].end(),
862 [&end](
const Edge &node) {
return node.
dest() == end; });
863 return (*it).weight();
865 #ifndef DOXYGEN_SHOULD_SKIP_THIS
869 GL_ENABLE_IF_MATRIX_DIRECTED
872 GL_ASSERT(
hasEdge(start, end), (std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end)))
879 GL_ENABLE_IF_MATRIX_UNDIRECTED
883 std::swap(end, start);
884 GL_ASSERT(
hasEdge(start, end), (std::string(
"No edge from ") + std::to_string(start) + std::string(
" to ") + std::to_string(end)))
894 #ifndef DOXYGEN_SHOULD_SKIP_THIS
898 GL_ENABLE_IF_MATRIX_DIRECTED
904 #ifndef DOXYGEN_SHOULD_SKIP_THIS
908 GL_ENABLE_IF_MATRIX_UNDIRECTED
912 std::swap(src, dest);
921 auto it = std::find_if(
edges_[src].begin(),
edges_[src].end(),
922 [&dest](
const Edge &node) {
return node.dest() == dest; });
923 return (*it).color();
931 #ifndef DOXYGEN_SHOULD_SKIP_THIS
936 auto ptr =
edges_.begin();
938 while (!ptr->exists())
953 #ifndef DOXYGEN_SHOULD_SKIP_THIS
964 #ifndef DOXYGEN_SHOULD_SKIP_THIS
969 auto ptr =
edges_.cbegin();
971 while (!ptr->exists())
986 #ifndef DOXYGEN_SHOULD_SKIP_THIS
993 #ifndef DOXYGEN_SHOULD_SKIP_THIS
997 auto ptr =
edges_[0].begin();
998 auto data1 =
edges_.begin();
1000 while (data1->size() == 0)
1008 ptr =
edges_.back().end();
1011 return Edge_Iterator<false>(ptr, data1,
this);
1016 return Edge_Iterator<false>(
edges_.back().end(),
edges_.end()-1,
this);
1022 auto ptr =
edges_[0].cbegin();
1023 auto data1 =
edges_.cbegin();
1025 while (data1->size() == 0)
1033 ptr =
edges_.back().cend();
1036 return Edge_Iterator<true>(ptr, data1,
this);
1041 return Edge_Iterator<true>(
edges_.back().cend(),
edges_.cend()-1,
this);
1055 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1070 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1093 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1101 if (
hasEdge(node, end) && !visited[end])
1106 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1116 if (
hasEdge(node, end) && !visited[end])
1128 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1134 for (
const auto &edge :
edges_[node])
1136 out.push_back(std::make_pair(edge.dest(), edge.weight()));
1140 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1151 out.push_back(std::make_pair(end,
getEdgeWeight(node, end)));
1162 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1170 if (
hasEdge(node, end) && !visited[end])
1171 out.push_back(std::make_pair(end,
getEdgeWeight(node, end)));
1175 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1185 if (
hasEdge(node, end) && !visited[end])
1186 out.push_back(std::make_pair(end,
getEdgeWeight(node, end)));
1199 #ifdef DOXYGEN_SHOULD_SKIP_THIS
1202 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1204 template <
typename First,
typename ... OtherArgs>
1205 inline void updateNode (
const idx_t&
id, First arg,
const OtherArgs&... rest)
1208 throw std::runtime_error( std::string(__FILE__)
1210 + std::to_string(__LINE__)
1211 + std::string(
" in ")
1212 + std::string(__PRETTY_FUNCTION__)
1213 + std::string(
": Unknown argument type."));
1215 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1216 template <
typename ... OtherArgs>
1217 inline void updateNode (
const idx_t&
id,
const std::string& arg,
const OtherArgs&... rest)
1221 }
template <
typename ... OtherArgs>
1222 inline void updateNode (
const idx_t&
id,
const char* arg,
const OtherArgs&... rest)
1227 template <
typename ... OtherArgs>
1230 nodes_[id].capacity(arg);
1233 template <
typename ... OtherArgs>
1239 template <
typename ... OtherArgs>
1240 inline void updateNode (
const idx_t&
id,
const std::pair<float,float>& arg,
const OtherArgs&... rest)
1242 nodes_[id].position(arg);
1257 return nodes_[id].label();
1266 return nodes_[id].capacity();
1275 return nodes_[id].position();
1282 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1283 GL_ENABLE_IF_LIST_UNDIRECTED
1287 return edges_[id].size();
1289 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1293 GL_ENABLE_IF_MATRIX_UNDIRECTED
1311 return nodes_[id].inDegree();
1318 return nodes_[id].outDegree();
1327 return nodes_[id].color();
1336 is.open(inFile, std::ios::in);
1337 GL_ASSERT(is.is_open(),std::string(std::string(
"Error: failed to open ")+inFile))
1341 while (is >> node >> x >> y)
1391 GL_ASSERT((0 <= idx1), (std::string(
"Negative index: ") + std::to_string(idx1) + std::string(
" < 0")))
1392 GL_ASSERT((idx1 <
numNodes()), (
"Index " + std::to_string(idx1) +
" is larger than the max: " + std::to_string(
numNodes() - 1)))
1406 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1415 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1425 if (
edges_[i].size() != rhs.
edges_[i].size())
return false;
1429 auto rhs_it = std::find_if(rhs.
edges_[lhs_it->source()].begin(), rhs.
edges_[lhs_it->source()].end(),
1430 [&lhs_it](
const Edge &node) {
1431 return node.dest() == lhs_it->dest()
1432 && node.weight() == lhs_it->weight()
1433 && node.color() == lhs_it->color();
1435 if (rhs_it == rhs.
edges_[lhs_it->source()].end())
1454 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1465 matrix[i *
numNodes() + j].source(i);
1466 matrix[i *
numNodes() + j].dest(j);
1470 std::vector<Node> nodes();
1477 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1486 std::vector<Node> nodes();
Graph(const idx_t &numNodes=0, const std::string &label="Graph")
Construct Graph from node count and label.
Definition: Graph.hpp:272
void setEdge(const Edge &edge)
Adds an edge directly from an Edge object.
Definition: Graph.hpp:581
operator*() const
Const dereference iterator.
Definition: Graph.hpp:182
self_t operator++()
Move Iterator to next edge (pre-increment)
Definition: Graph.hpp:115
SCALAR val_t
Value type.
Definition: Graph.hpp:43
ConstEdgeIterator edge_cbegin() const
ConstEdgeIterator to the first edge.
Definition: Graph.hpp:967
bool operator==(const Graph< SCALAR, gl::Matrix, DIRECTION > &rhs)
Definition: Graph.hpp:1409
operator*()
Non-const dereference iterator.
Definition: Graph.hpp:194
idx_t numNodes() const
Gets the number of nodes in the graph.
std::string label() const
Gets the label of the graph.
Stores an RGBA Color.
Definition: Color.hpp:21
std::deque< info_t > BFS_queue_t
BFS type.
Definition: Graph.hpp:52
void updateEdge(const idx_t &start, const idx_t &end, const val_t &weight, const gl::Color &color)
Updates edge properties. Parameters "start" & "end" mandatory, the rest optional. ...
Definition: Graph.hpp:669
dest_vec_t getNeighbourWeights(const idx_t &node) const
Returns a list of endpoints + edge weights of outgoing edges from start.
Definition: Graph.hpp:1131
bool hasCycle() const
Checks whether the given undirected graph containes cycles using an iterative BFS approach...
Definition: Graph.hpp:465
Color getEdgeColor(const idx_t &src, const idx_t &dest) const
Returns the color of the edge from src to dest.
Definition: Graph.hpp:900
operator->() const
Get underlying edge.
Definition: Graph.hpp:206
std::conditional_t< std::is_same_v< STORAGE_KIND, Matrix >, matrix_iterator_t, rootList_iterator_t > data1_
[Matrix] Iterator to first element, [List] Iterator over the rootList
Definition: Graph.hpp:246
self_t operator=(const self_t &rhs)
Construct from Assignment.
Definition: Graph.hpp:237
std::vector< idx_t > idx_list_t
Index List type.
Definition: Graph.hpp:48
gl::index_type idx_t
Index type.
Definition: Graph.hpp:44
idx_list_t getNeighbours(const idx_t &node) const
Returns a list of all endpoints of outgoing edges from start.
Definition: Graph.hpp:1058
Represents a Node in a Graph.
Definition: Node.hpp:18
Color color() const
Gets the edge's color.
Definition: Edge.hpp:208
void setEdge(const idx_t &start, const idx_t &end, const val_t &weight=1, const Color &color=Color())
Sets an edge including start/end points and weight.
Definition: Graph.hpp:510
Property property_
Stores various properties of the Graph.
Definition: Graph.hpp:257
val_t getNodeCapacity(const idx_t &id) const
Finds the flow capacity of the given node.
Definition: Graph.hpp:1264
bool operator!=(const self_t &rhs)
Check if not equal.
Definition: Graph.hpp:231
Stores and implements a Graph.
Definition: Graph.hpp:39
std::forward_iterator_tag iterator_category
Iterator category.
Definition: Graph.hpp:71
idx_t getNodeOutDegree(const idx_t &id) const
Gets the in-degree of a node (i.e. count of all outgoing edges).
Definition: Graph.hpp:1316
gl::Graph< SCALAR, gl::List, DIRECTION > toList() const
Outputs a graph in Adjacency List storage format with the same edges as this. This function only exis...
Definition: Graph.hpp:371
std::ptrdiff_t difference_type
Pointer Difference type.
Definition: Graph.hpp:72
bool hasEdge(const idx_t &start, const idx_t &end) const
Checks whether an edge exists from start to end.
Definition: Graph.hpp:818
ConstNodeIterator node_cbegin() const
ConstNodeIterator to the first node.
Definition: Graph.hpp:1367
std::conditional_t< IsConst, const Edge &, Edge & > reference
Edge reference type.
Definition: Graph.hpp:69
gl::Graph< SCALAR, gl::Matrix, DIRECTION > toMatrix() const
Outputs a graph in Adjacency Matrix storage format with the same edges as this. This function only ex...
Definition: Graph.hpp:332
Edge_Iterator< false > EdgeIterator
Edge iterator type.
Definition: Graph.hpp:251
std::conditional_t< IsConst, typename rootList_t::const_iterator, typename rootList_t::iterator > rootList_iterator_t
Definition: Graph.hpp:76
typename std::vector< Node >::const_iterator ConstNodeIterator
Node const_iterator type.
Definition: Graph.hpp:254
container_pointer_t data2_
Pointer to owner Graph.
Definition: Graph.hpp:247
ConstEdgeIterator edge_cend() const
ConstEdgeIterator to the last edge.
Definition: Graph.hpp:989
bool operator==(const self_t &rhs)
Check if equal.
Definition: Graph.hpp:226
idx_t numEdges() const
Returns the number of edges currently in the graph.
Definition: Graph.hpp:415
std::string getGraphLabel() const
Returns the label of the graph.
Definition: Graph.hpp:390
bool isDirected() const
Returns true if the graph is directed, false if not.
Definition: Graph.hpp:426
#define GL_ASSERT(EXPR, ERROR_MSG)
Custom assert that supports attaching a message.
Definition: gl_assert.hpp:14
std::conditional_t< IsConst, typename nodeList_t::const_iterator, typename nodeList_t::iterator > list_iterator_t
Definition: Graph.hpp:77
void setGraphLabel(const std::string &label)
Changes the label of the graph.
Definition: Graph.hpp:398
idx_t getNodeInDegree(const idx_t &id) const
Gets the in-degree of a node (i.e. count of all incoming edges).
Definition: Graph.hpp:1309
Graph::idx_list_t degrees(const Graph &graph)
Computes the out-degrees of all nodes in a graph.
Definition: Degrees.hpp:16
idx_t numNodes() const
Returns the number of nodes currently in the graph.
Definition: Graph.hpp:406
Edge_Iterator(matrix_iterator_t ptr, matrix_iterator_t data1, container_pointer_t data2)
Construct EdgeIterator, only used with Matrix Representation.
Definition: Graph.hpp:92
self_t operator++(int dummy)
Move Iterator to next edge (post-increment)
Definition: Graph.hpp:131
std::conditional_t< IsConst, typename matrix_t::const_iterator, typename matrix_t::iterator > matrix_iterator_t
Definition: Graph.hpp:75
std::size_t index_type
Definition: gl_base.hpp:18
std::vector< Node > nodes_
Stores information about all nodes in the Graph.
Definition: Graph.hpp:258
void checkRange(const idx_t &idx1, const idx_t &idx2) const
Two indices ("edge") that get range checked.
Definition: Graph.hpp:1400
gl::Node< val_t > Node
Node type.
Definition: Graph.hpp:46
void delEdge(const idx_t &start, const idx_t &end)
Deletes the edge going from start to end.
Definition: Graph.hpp:741
std::list< Edge > nodeList_t
ListNode Representation type.
Definition: Graph.hpp:57
Edge_Iterator()
Default constructor.
Definition: Graph.hpp:82
Color getNodeColor(const idx_t &id) const
Returns the color of a node.
Definition: Graph.hpp:1325
Edge_Iterator(list_iterator_t ptr, rootList_iterator_t data1, container_pointer_t data2)
Construct EdgeIterator, only used with List Representation.
Definition: Graph.hpp:104
dest_vec_t getUnvisitedNeighbourWeights(const idx_t &node, const visit_list_t &visited) const
Returns a list of endpoints + edge weights of unvisited outgoing edges from start.
Definition: Graph.hpp:1165
void numEdgesIncrement(const idx_t &increment=1)
Increments the number of edges in the graph.
std::list< idx_t > ordered_list_t
Ordered List type.
Definition: Graph.hpp:49
idx_t source() const
Gets the index of the source of the edge.
Definition: Edge.hpp:175
gl::Edge< val_t > Edge
Edge type.
Definition: Graph.hpp:45
Represents an Edge in a Graph.
Definition: Edge.hpp:18
std::conditional_t< IsConst, const Edge *, Edge * > pointer
Edge pointer type.
Definition: Graph.hpp:70
operator->()
Get underlying edge.
Definition: Graph.hpp:218
EdgeIterator edge_end()
EdgeIterator to behind the last edge.
Definition: Graph.hpp:956
std::vector< nodeList_t > rootList_t
ListRoot Representation type.
Definition: Graph.hpp:58
ConstNodeIterator node_cend() const
ConstNodeIterator to behind the last node.
Definition: Graph.hpp:1375
std::string getNodeLabel(const idx_t &id) const
Finds the label of the given node.
Definition: Graph.hpp:1255
void readPositionsFromFile(const std::string &inFile)
Updates node positions in the format "<id> <x-coord> <y-coord>" found in inFile.
Definition: Graph.hpp:1333
Graph(const std::string °reeSeq, const std::string &label="Simple Undirected Graph")
Construct Graph from node count and label.
Definition: Graph.hpp:281
std::vector< bool > visit_list_t
Visited-List type.
Definition: Graph.hpp:50
void setEdgesFromMatrixFile(const std::string &inFile)
Adds edges found in inFile to the graph.
Definition: Graph.hpp:625
bool isUndirected() const
Returns true if the graph is undirected, false if not.
Definition: Graph.hpp:447
NodeIterator node_begin()
NodeIterator to the first node.
Definition: Graph.hpp:1351
idx_t dest() const
Gets the index of the destination of the edge.
Definition: Edge.hpp:186
void construct()
Auxiliary function. Creates an empty Graph using the deduced storage format.
Definition: Graph.hpp:1458
bool havelHakimi(std::deque< gl::index_type > degrees)
Uses the Havel-Hakimi algorithm to determine whether a given degree sequence is graphic.
Definition: HavelHakimi.hpp:16
void checkRange(const idx_t &idx1) const
Only one index that gets range checked.
Definition: Graph.hpp:1389
std::vector< std::pair< idx_t, val_t >> dest_vec_t
Destination-Vector type.
Definition: Graph.hpp:47
idx_t getNodeDegree(const idx_t &id) const
Finds the degree of the given node (i.e. count of all in- & outgoing edges).
Definition: Graph.hpp:1285
std::vector< Edge > matrix_t
Matrix Representation type.
Definition: Graph.hpp:56
idx_list_t getUnvisitedNeighbours(const idx_t &node, const std::vector< bool > &visited) const
Returns a list of endpoints + edge weights of outgoing edges from start.
Definition: Graph.hpp:1096
std::stack< idx_t > DFS_queue_t
DFS type.
Definition: Graph.hpp:53
Edge_Iterator class. Used to iterate over all Edges in the Graph
Definition: Graph.hpp:65
Edge_Iterator self_t
EdgeIterator type.
Definition: Graph.hpp:73
std::conditional_t< std::is_same_v< STORAGE_KIND, Matrix >, matrix_t, rootList_t > edges_
Stores information about all edges in the Graph.
Definition: Graph.hpp:259
bool operator!=(const Graph< SCALAR, STORAGE_KIND, DIRECTION > &rhs)
Definition: Graph.hpp:1440
idx_t numEdges() const
Gets the number of edges in the graph.
typename std::vector< Node >::iterator NodeIterator
Node iterator type.
Definition: Graph.hpp:253
EdgeIterator edge_begin()
EdgeIterator to the first edge.
Definition: Graph.hpp:934
~Graph()
Definition: Graph.hpp:317
std::pair< float, float > getNodePosition(const idx_t &id) const
Finds the position of the given node.
Definition: Graph.hpp:1273
void numEdgesDecrement(const idx_t &decrement=1)
Decrements the number of edges in the graph.
val_t getEdgeWeight(const idx_t &start, const idx_t &end) const
Finds the weight of the edge going from start to end.
Definition: Graph.hpp:858
Stores the properties of a Graph.
Definition: Property.hpp:14
NodeIterator node_end()
NodeIterator to behind the last node.
Definition: Graph.hpp:1359
std::conditional_t< IsConst, const Graph< SCALAR, STORAGE_KIND, DIRECTION > *, Graph< SCALAR, STORAGE_KIND, DIRECTION > * > container_pointer_t
Definition: Graph.hpp:78
Graph(const Property &property)
Construct Graph from property.
Definition: Graph.hpp:313
std::conditional_t< std::is_same_v< STORAGE_KIND, Matrix >, matrix_iterator_t, list_iterator_t > ptr_
[Matrix] Iterator to an element, [List] Iterator over the nodeLists
Definition: Graph.hpp:245
void updateNode(const idx_t &id, const std::string &label, const val_t &capacity, const gl::Color &color, const std::pair< float, float > &position)
Updates node properties. Parameter "id" mandatory, the rest optional.
Definition: Graph.hpp:1200
Edge_Iterator< true > ConstEdgeIterator
Edge const_iterator type.
Definition: Graph.hpp:252
val_t weight() const
Gets the weight of the edge.
Definition: Edge.hpp:197
void setEdgesFromListFile(const std::string &inFile)
Adds edges found in inFile to the graph.
Definition: Graph.hpp:597