Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_euclidian_graph.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
80#ifndef TPL_EUCLIDIAN_GRAPH_H
81#define TPL_EUCLIDIAN_GRAPH_H
82
83#include <tpl_graph.H>
84#include <point.H>
85#include <ah-errors.H>
86
87namespace Aleph {
92template <typename Node_Info>
93class Euclidian_Node : public Graph_Node<Node_Info>
94{
95public:
97
99
101
102private:
104
105public:
107 {
108 /* Empty */
109 }
110
112 {
113 /* Empty */
114 }
115
117 {
118 /* Empty */
119 }
120
123 {
124 /* Empty */
125 }
126
128 {
129 /* Empty */
130 }
131
133 {
134 return position;
135 }
136
137 const Point &get_position() const
138 {
139 return position;
140 }
141}; // End class Euclidian_Node
142
143template <typename Arc_Info>
144class Euclidian_Arc : public Graph_Arc<Arc_Info>
145{
146public:
148
150
152
154 {
155 /* Empty */
156 }
157
159 {
160 /* Empty */
161 }
162
163 Euclidian_Arc(void *src, void *tgt, const Arc_Info &info) : Graph_Arc<Arc_Info>(src, tgt, info)
164 {
165 /* Empty */
166 }
167
168 Euclidian_Arc(void *src, void *tgt) : Graph_Arc<Arc_Info>(src, tgt)
169 {
170 /* Empty */
171 }
172}; // End class Euclidian_Arc
173
174template <class __Euclidian_Node, class __Euclidian_Arc>
175class Euclidian_Graph : public List_Graph<__Euclidian_Node, __Euclidian_Arc>
176{
177public:
179
181
183
184 typedef typename Node::Node_Type Node_Type;
185
186 typedef typename Arc::Arc_Type Arc_Type;
187
189 {
190 /* Empty */
191 }
192
197
198 Node *insert_node(Node *node) noexcept override
199 {
200 return Graph::insert_node(node);
201 }
202
204 {
205 return insert_node(new Node(info));
206 }
207
208 Node *insert_node(const Point &position)
209 {
210 return insert_node(new Node(position));
211 }
212
213 Node *insert_node(const Node_Type &info, const Point &position)
214 {
215 return insert_node(new Node(info, position));
216 }
217
219 {
220 const Point &src_point = this->get_src_node(arc)->get_position();
221 const Point &tgt_point = this->get_tgt_node(arc)->get_position();
223 }
224
226 {
227 if (this == &eg)
228 return *this;
229 copy_graph(*this, const_cast<Euclidian_Graph<Node, Arc> &>(eg), false);
230 return *this;
231 }
232
234 {
235 clear_graph(*this);
236 }
237
238 Node *search_node(const Point &);
239}; // End class Euclidian_Graph
240
241template <class __Euclidian_Node, class __Euclidian_Arc>
262
263template <class Node, class Arc>
265{
266 for (typename Euclidian_Graph<Node, Arc>::Node_Iterator it(*this); it.has_curr(); it.next_ne())
267 if (auto *curr = it.get_curr(); curr->get_position() == point)
268 return curr;
269 return nullptr;
270}
271
272template <class __Euclidian_Graph>
274{
279
281
284
287
288public:
290 : ptr_east_point(nullptr), ptr_north_point(nullptr), ptr_west_point(nullptr),
292 {
293 // Empty
294 }
295
297 : ptr_east_point(nullptr), ptr_north_point(nullptr), ptr_west_point(nullptr),
299 {
300 if (graph.get_num_nodes() < 1)
301 return;
302
303 typename __Euclidian_Graph::Node_Iterator itor(graph);
304 points.append(itor.get_curr()->get_position());
306
307 for (int i = 1; itor.has_curr(); itor.next_ne(), ++i)
308 {
309 const Point &p = itor.get_curr()->get_position();
310 points.append(p);
311 if (p.get_x() < ptr_west_point->get_x())
312 ptr_west_point = &points.access(i);
313 if (p.get_y() > ptr_north_point->get_y())
314 ptr_north_point = &points.access(i);
315 if (p.get_x() > ptr_east_point->get_x())
316 ptr_east_point = &points.access(i);
317 if (p.get_y() < ptr_south_point->get_y())
318 ptr_south_point = &points.access(i);
319 }
320 }
321
323 {
324 /* Empty */
325 }
326
327 Point &add_point(typename __Euclidian_Graph::Node *node)
328 {
329 ah_domain_error_if(node == nullptr) << "node is nullptr";
330 points.append(node->get_position());
331 Point &p = points.top();
332 if (points.size() == 1)
334 else
335 {
336 if (p.get_x() < ptr_west_point->get_x())
337 ptr_west_point = &p;
338 if (p.get_y() > ptr_north_point->get_y())
339 ptr_north_point = &p;
340 if (p.get_x() > ptr_east_point->get_x())
341 ptr_east_point = &p;
342 if (p.get_y() < ptr_south_point->get_y())
343 ptr_south_point = &p;
344 }
345 return p;
346 }
347
348 const Point &get_west_point() const
349 {
350 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
351 return *ptr_west_point;
352 }
353
354 const Point &get_north_point() const
355 {
356 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
357 return *ptr_north_point;
358 }
359
360 const Point &get_east_point() const
361 {
362 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
363 return *ptr_east_point;
364 }
365
366 const Point &get_south_point() const
367 {
368 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
369 return *ptr_south_point;
370 }
371
373 {
374 if (points.size() < 1)
375 return Geom_Number(0);
377 }
378
380 {
381 if (points.size() < 1)
382 return Geom_Number(0);
384 }
385
387 {
388 return x_node_ratio;
389 }
390
395
397 {
398 return y_node_ratio;
399 }
400
405
407 {
408 return x_scale;
409 }
410
412 {
414 }
415
417 {
418 return y_scale;
419 }
420
422 {
424 }
425}; // End class Abstract_Euclidian_Plane
426} // End namespace Aleph
427
428#endif // TPL_EUCLIDIAN_GRAPH_H
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:527
#define ah_logic_error_if(C)
Throws std::logic_error if condition holds.
Definition ah-errors.H:330
WeightedDigraph::Node Node
const Geom_Number & get_x_node_ratio() const
Point & add_point(typename __Euclidian_Graph::Node *node)
void set_y_node_ratio(const Geom_Number &_y_node_ratio)
const Geom_Number & get_y_node_ratio() const
void set_x_scale(const Geom_Number &_x_scale)
void set_x_node_ratio(const Geom_Number &_x_node_ratio)
const Geom_Number & get_y_scale() const
const Geom_Number & get_x_scale() const
void set_y_scale(const Geom_Number &_y_scale)
Abstract_Euclidian_Plane(__Euclidian_Graph &graph)
Euclidian_Arc(void *src, void *tgt, const Arc_Info &info)
Euclidian_Arc(void *src, void *tgt)
Euclidian_Arc(const Arc_Info &info)
Euclidian_Digraph(const Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc > &euclidian_digraph)
Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc > & operator=(Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc > &eg)
Euclidian_Graph(const Euclidian_Graph< Node, Arc > &euclidian_graph)
Node * insert_node(const Point &position)
Geom_Number get_distance(Arc *arc)
Node * insert_node(const Node_Type &info, const Point &position)
Node * insert_node(Node *node) noexcept override
Insertion of a node already allocated.
Euclidian_Graph< Node, Arc > & operator=(Euclidian_Graph< Node, Arc > &eg)
Node * search_node(const Point &)
List_Graph< Node, Arc > Graph
Node * insert_node(const Node_Type &info)
Euclidian_Node(const Point &_position)
const Point & get_position() const
Euclidian_Node(const Node_Info &info, const Point &_position)
Euclidian_Node(Euclidian_Node *node)
Euclidian_Node(const Node_Info &info)
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:429
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:525
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:221
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
Definition point.H:448
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Definition point.H:457
Geom_Number distance_to(const Point &p) const
Calculates the Euclidean distance to another point.
Definition point.H:1498
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:779
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:785
void clear_graph(GT &g) noexcept
Clean a graph: all its nodes and arcs are removed and freed.
Definition tpl_graph.H:3659
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
void copy_graph(GT &gtgt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Definition tpl_graph.H:3677
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
mpq_class Geom_Number
Numeric type used by the geometry module.
Definition point.H:113
2D point and geometric utilities.
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:223
Node belonging to a graph implemented with a double linked adjacency list.
Definition tpl_graph.H:122
Generic graph and digraph implementations.