25 # ifndef GRAPHUTILITIES_H 26 # define GRAPHUTILITIES_H 80 template <
class GT>
using NodeIt =
typename GT::NodeIterator;
81 template <
class GT>
using ArcIt =
typename GT::ArcIterator;
82 template <
class GT>
using AdArcIt =
typename GT::AdjacentArcIterator;
86 if (x->
cookie() ==
nullptr)
98 template <
class SG,
class TG = SG>
104 template <
class SG,
class TG = SG>
110 template <
class SG,
class TG = SG>
113 return reinterpret_cast<Node<TG> *
>(p->cookie());
116 template <
class SG,
class TG = SG>
119 return reinterpret_cast<Arc<TG> *
>(a->cookie());
136 : node(_node), arc(_arc)
144 GT * ptr_owner_graph;
147 void test_for_graph()
const 149 if (ptr_owner_graph ==
nullptr)
150 throw std::logic_error(
"Graph has not been specified");
155 : ptr_owner_graph(nullptr), list()
161 : ptr_owner_graph(const_cast<GT *>(&graph)), list()
167 : ptr_owner_graph(graph_ptr), list()
173 : ptr_owner_graph(path.ptr_owner_graph), list(path.list)
179 : ptr_owner_graph(nullptr), list()
181 std::swap(ptr_owner_graph, path.ptr_owner_graph);
182 std::swap(list, path.list);
188 return *ptr_owner_graph;
195 list.
append(PathDesc(start));
198 void set(GT & graph,
NodeType * ptr_start =
nullptr)
202 ptr_owner_graph = &graph;
204 if (ptr_start !=
nullptr)
218 throw std::domain_error(
"Path is empty");
222 NodeType * prev_node = arc->get_connected_node(first.node);
224 list.
insert(PathDesc(prev_node, arc));
239 ArcType * ptr_arc = ptr_owner_graph->search_arc(s, first.node);
241 if (ptr_arc ==
nullptr)
242 throw std::logic_error(
"There is not arc between last and current node");
244 list.
insert(PathDesc(s, ptr_arc));
252 throw std::domain_error(
"Path is empty");
258 NodeType * next_node = arc->get_connected_node(last.node);
260 list.
append(PathDesc(next_node));
275 ArcType * ptr_arc = ptr_owner_graph->search_arc(last.node, t);
277 if (ptr_arc ==
nullptr)
278 throw std::logic_error(
"There is not arc between last and current node");
290 throw std::underflow_error(
"Path is empty");
303 throw std::overflow_error(
"Path is empty");
313 throw std::overflow_error(
"Path is empty");
321 throw std::underflow_error(
"Path is empty");
329 throw std::underflow_error(
"Path is empty");
337 throw std::overflow_error(
"Path is empty");
339 if (list.
size() == 1)
340 throw std::overflow_error(
"Path has only one node (without arcs)");
348 throw std::overflow_error(
"Path is empty");
350 if (list.
size() == 1)
351 throw std::overflow_error(
"Path has only one node (without arcs)");
360 throw std::underflow_error(
"Path is empty");
363 throw std::underflow_error(
"Path has only one node (without arcs)");
371 throw std::underflow_error(
"Path is empty");
374 throw std::underflow_error(
"Path has only one node (without arcs)");
382 for (
const PathDesc & path_desc : list)
383 op(path_desc.node, path_desc.arc);
395 for (PathDesc & path_desc : list)
396 op(path_desc.node, path_desc.arc);
410 ptr_owner_graph = path.ptr_owner_graph;
426 return list.template map_if<Arc<GT> *>
433 return pd.arc !=
nullptr;
439 std::swap(ptr_owner_graph, path.ptr_owner_graph);
440 std::swap(list, path.list);
466 return (
lint_t &) p->cookie();
471 template <
class GT,
class Distance>
479 : tree_node(nullptr), accumulated_distance(Distance::
ZERO)
485 template <
class GT,
class Distance>
494 : tree_arc(nullptr), potential(Distance::
ZERO), is_in_queue(false)
500 template <
class GT,
class Distance>
506 template <
class GT,
class Distance>
509 return NI<GT, Distance>(p)->tree_node;
512 template <
class GT,
class Distance>
515 return NI<GT, Distance>(p)->accumulated_distance;
518 template <
class GT,
class Distance>
524 template <
class GT,
class Distance>
527 return AI<GT, Distance>(a)->tree_arc;
530 template <
class GT,
class Distance>
533 return AI<GT, Distance>(a)->potential;
536 template <
class GT,
class Distance>
539 return AI<GT, Distance>(a)->is_in_queue;
542 template <
class GT,
class Distance>
551 template <
class GT,
class Distance>
554 g.for_each_arc([] (
Arc<GT> * arc)
560 template <
class GT,
class Distance>
563 g.for_each_node([] (
Node<GT> * node)
565 auto to_destroy = NI<GT, Distance>(node);
566 auto ptr_tree_node = TREE_NODE<GT, Distance>(node);
568 if (ptr_tree_node ==
nullptr)
569 node->cookie() =
nullptr;
572 node->cookie() = ptr_tree_node;
573 ptr_tree_node->cookie() = node;
580 template <
class GT,
class Distance>
583 g.for_each_arc([&] (
Arc<GT> * arc)
585 auto to_destroy = AI<GT, Distance>(arc);
586 auto ptr_tree_arc = TREE_ARC<GT, Distance>(arc);
588 if (ptr_tree_arc ==
nullptr)
589 arc->cookie() =
nullptr;
592 arc->cookie() = ptr_tree_arc;
593 ptr_tree_arc->cookie() = arc;
600 template <
class GT,
class Distance,
class Heap>
603 if (IS_IN_QUEUE<GT, Distance>(a))
606 IS_IN_QUEUE<GT, Distance>(a) =
true;
610 template <
class GT,
class Distance,
class Heap>
613 Arc<GT> * ret_val = h.get_min_arc();
614 IS_IN_QUEUE<GT, Distance>(ret_val) =
false;
618 template <
class GT,
class Distance>
622 typename Distance::Type operator () (
Arc<GT> * a)
624 return POT<GT, Distance>(a);
672 void operator () (std::ostream & out,
const Node<GT> * p)
674 out << p->get_info();
677 void operator () (std::ofstream & out,
const Node<GT> * p)
679 out.write(reinterpret_cast<const char *>(&p->get_info()),
680 sizeof(
typename GT::NodeInfoType));
688 void operator () (std::ostream & out,
const Arc<GT> * a)
690 out << a->get_info();
693 void operator () (std::ofstream & out,
const Arc<GT> * a)
695 out.write(reinterpret_cast<const char *>(&a->get_info()),
696 sizeof(
typename GT::ArcInfoType));
704 void operator () (std::ostream & out,
const GT & g)
709 void operator () (std::ofstream & out,
const GT & g)
711 out.write(reinterpret_cast<const char *>(&g.get_info()),
712 sizeof(
typename GT::GraphInfoType));
725 void operator () (std::ifstream & in,
Node<GT> * p)
727 in.read(reinterpret_cast<char *>(&p->get_info()),
728 sizeof(
typename GT::NodeInfoType));
736 void operator () (std::istream & in,
Arc<GT> * a)
741 void operator () (std::ifstream & in,
Arc<GT> * a)
743 in.read(reinterpret_cast<char *>(&a->get_info()),
744 sizeof(
typename GT::ArcInfoType));
752 void operator () (std::istream & in, GT & g)
757 void operator () (std::ifstream & in, GT & g)
759 in.read(reinterpret_cast<char *>(&g.get_info()),
760 sizeof(
typename GT::GraphInfoType));
771 s <<
"label = \"" << p->get_info() <<
"\"";
783 s <<
"label = \"" << a->get_info() <<
"\"";
792 std::string operator () (
const GT &)
794 return " // Without graph attributes";
800 # endif // GRAPHUTILITIES_H
Definition: graphutilities.H:619
void clear()
Definition: list.H:652
Path()
Definition: graphutilities.H:154
void map_arcs(Arc< SG > *a, Arc< TG > *b)
Definition: graphutilities.H:105
void for_each(Op &op)
Definition: graphutilities.H:393
void allocate_arc_info(const GT &g)
Definition: graphutilities.H:552
Arc< GT > * tree_arc
Definition: graphutilities.H:489
void init(NodeType *start)
Definition: graphutilities.H:191
Node< GT > * tree_node
Definition: graphutilities.H:475
NodeType * get_first_node()
Definition: graphutilities.H:318
Definition: graphutilities.H:659
NodeType * get_first_node() const
Definition: graphutilities.H:326
typename GT::ArcIterator ArcIt
Definition: graphutilities.H:81
bool is_empty() const
Definition: nodesdef.H:153
lint_t & df(Node< GT > *p)
Definition: graphutilities.H:458
void insert(ArcType *arc)
Definition: graphutilities.H:213
void clear()
Definition: graphutilities.H:208
void remove_last_node()
Definition: graphutilities.H:285
Path(const Path &path)
Definition: graphutilities.H:172
ArcType * get_first_arc() const
Definition: graphutilities.H:368
T remove_last()
Definition: list.H:739
void insert(NodeType *s)
Definition: graphutilities.H:227
Definition: graphutilities.H:629
MinPathNodeInfo< GT, Distance > *& NI(Node< GT > *p)
Definition: graphutilities.H:501
T & get_first()
Definition: list.H:695
Definition: graphutilities.H:685
NodeType * get_last_node()
Definition: graphutilities.H:298
lint_t & low(Node< GT > *p)
Definition: graphutilities.H:464
Arc< GT > * get_from_heap(Heap &h)
Definition: graphutilities.H:611
MinPathNodeInfo()
Definition: graphutilities.H:478
T & get_last()
Definition: list.H:711
void map_graph_item(CommonNodeArc *x, CommonNodeArc *y)
Definition: graphutilities.H:84
void append(ArcType *arc)
Definition: graphutilities.H:247
Definition: graphutilities.H:649
SLList< Node< GT > * > nodes() const
Definition: graphutilities.H:416
SLList< Arc< GT > * > arcs() const
Definition: graphutilities.H:424
nat_t size() const
Definition: graphutilities.H:450
bool is_empty() const
Definition: graphutilities.H:445
void map_nodes(Node< SG > *p, Node< TG > *q)
Definition: graphutilities.H:99
void for_each(Op &&op=Op())
Definition: graphutilities.H:400
typename GT::AdjacentArcIterator AdArcIt
Definition: graphutilities.H:82
void for_each(Op &op) const
Definition: graphutilities.H:380
bool is_unitarian() const
Definition: nodesdef.H:163
Arc< GT > *& TREE_ARC(Arc< GT > *a)
Definition: graphutilities.H:525
MinPathArcInfo< GT, Distance > *& AI(Arc< GT > *a)
Definition: graphutilities.H:519
void for_each(Op &&op=Op()) const
Definition: graphutilities.H:387
void destroy_arc_info(const GT &g)
Definition: graphutilities.H:581
Path(Path &&path)
Definition: graphutilities.H:178
void allocate_node_info(const GT &g)
Definition: graphutilities.H:543
typename GT::Node Node
Definition: graphutilities.H:78
Node< GT > *& TREE_NODE(Node< GT > *p)
Definition: graphutilities.H:507
Definition: graphutilities.H:669
long long lint_t
Definition: types.H:49
T & insert(const T &item)
Definition: list.H:663
void put_in_heap(Arc< GT > *a, Node< GT > *t, Heap &h)
Definition: graphutilities.H:601
Definition: italgorithms.H:33
GT & get_graph()
Definition: graphutilities.H:185
Definition: graphutilities.H:777
bool is_in_queue
Definition: graphutilities.H:491
ArcType * get_last_arc()
Definition: graphutilities.H:334
Definition: graphutilities.H:639
T & append(const T &item)
Definition: list.H:679
Definition: graphutilities.H:486
ArcType * get_first_arc()
Definition: graphutilities.H:357
Definition: graphutilities.H:472
void append(NodeType *t)
Definition: graphutilities.H:263
Definition: graphutilities.H:54
NodeType * get_last_node() const
Definition: graphutilities.H:308
Definition: graphutilities.H:765
Definition: graphutilities.H:789
Definition: graphutilities.H:123
Path(GT *graph_ptr)
Definition: graphutilities.H:166
void destroy_node_info(const GT &g)
Definition: graphutilities.H:561
Distance::Type potential
Definition: graphutilities.H:490
unsigned long int nat_t
Definition: types.H:50
bool & IS_IN_QUEUE(Arc< GT > *a)
Definition: graphutilities.H:537
typename GT::NodeIterator NodeIt
Definition: graphutilities.H:80
nat_t size() const
Definition: list.H:647
Node< GT > NodeType
Definition: graphutilities.H:126
Distance::Type & ACC(Node< GT > *p)
Definition: graphutilities.H:513
TG::Node * mapped_node(Node< SG > *p)
Definition: graphutilities.H:111
Distance::Type & POT(Arc< GT > *a)
Definition: graphutilities.H:531
GraphTag
Definition: graphutilities.H:37
Path(const GT &graph)
Definition: graphutilities.H:160
typename GT::Arc Arc
Definition: graphutilities.H:79
MinPathArcInfo()
Definition: graphutilities.H:493
Definition: graphutilities.H:701
ArcType * get_last_arc() const
Definition: graphutilities.H:345
Arc< GT > ArcType
Definition: graphutilities.H:127
TG::Arc * mapped_arc(Arc< SG > *a)
Definition: graphutilities.H:117
Distance::Type accumulated_distance
Definition: graphutilities.H:476