Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
WeightedSquareGrid4.hpp
Go to the documentation of this file.
1
6// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved.
7
8#pragma once
9
10#include <alib/tuple>
12
13#include "SquareGrid.hpp"
14
15namespace grid {
16
17template<typename TCoordinate, typename TEdge>
18class WeightedSquareGrid4 final : public SquareGrid<TCoordinate, TEdge> {
19// ---------------------------------------------------------------------------------------------------------------------
20
21 public:
22 using coordinate_type = TCoordinate;
23 using edge_type = TEdge;
26
27// ---------------------------------------------------------------------------------------------------------------------
28 protected:
29 typename edge_type::weight_type m_unit;
30
31// =====================================================================================================================
32// Constructor, Destructor, Operators
33 public:
34 explicit WeightedSquareGrid4(TCoordinate height, TCoordinate width, typename edge_type::weight_type unit = 1);
35// ---------------------------------------------------------------------------------------------------------------------
36
37 typename edge_type::weight_type getUnit() const;
38
39 void setUnit(typename edge_type::weight_type unit);
40
41// ---------------------------------------------------------------------------------------------------------------------
42
43// =====================================================================================================================
44// GridBase interface
45 public:
46 auto operator <=> (const WeightedSquareGrid4 &other) const {
47 return std::tie(this->m_obstacles, this->m_height, this->m_width) <=> std::tie(other.getObstacleList(), other.getHeight(), other.getWidth());
48 }
49
50 bool operator == (const WeightedSquareGrid4 &other) const {
51 return std::tie(this->m_obstacles, this->m_height, this->m_width) == std::tie(other.getObstacleList(), other.getHeight(), other.getWidth());
52 }
53
54// =====================================================================================================================
55// GridInterface interface
56
57 public:
58
59 bool isValidDirection(direction_type direction) const override;
60
61// ---------------------------------------------------------------------------------------------------------------------
62
63 protected:
64 TEdge createEdge(const node_type &a, const node_type &b) const override;
65
66// ---------------------------------------------------------------------------------------------------------------------
67// =====================================================================================================================
68// GraphInterface interface
69
70 public:
71 std::string name() const override;
72
73// ---------------------------------------------------------------------------------------------------------------------
74
75};
76
77// =====================================================================================================================
78
79template<typename TCoordinate, typename TEdge>
80typename TEdge::weight_type WeightedSquareGrid4<TCoordinate, TEdge>::getUnit() const {
81 return m_unit;
82}
83
84template<typename TCoordinate, typename TEdge>
85void WeightedSquareGrid4<TCoordinate, TEdge>::setUnit(typename TEdge::weight_type unit) {
86 if (unit > 0) m_unit = unit;
87}
88
89// ---------------------------------------------------------------------------------------------------------------------
90
91template<typename TCoordinate, typename TEdge>
93 TCoordinate width,
94 typename TEdge::weight_type unit)
95 : SquareGrid<TCoordinate, TEdge>(height, width), m_unit(unit) {
96}
97
98// ---------------------------------------------------------------------------------------------------------------------
99
100template<typename TCoordinate, typename TEdge>
102 const WeightedSquareGrid4::node_type &b) const {
103 return TEdge(a, b, m_unit);
104}
105
106// ---------------------------------------------------------------------------------------------------------------------
107
108template<typename TCoordinate, typename TEdge>
110 switch (direction) {
111 case SquareGridDirections::north : return true;
112 case SquareGridDirections::south : return true;
113 case SquareGridDirections::east : return true;
114 case SquareGridDirections::west : return true;
115 default: return false;
116 }
117}
118
119// ---------------------------------------------------------------------------------------------------------------------
120
121template<typename TCoordinate, typename TEdge>
123 return "SqaureGrid4Weighted";
124}
125
126// ---------------------------------------------------------------------------------------------------------------------
127
128} // namespace grid
129
130// =====================================================================================================================
131
132namespace core {
133
140template<typename TCoordinate, typename TEdge>
141struct normalize < grid::WeightedSquareGrid4 < TCoordinate, TEdge > > {
143 grid::WeightedSquareGrid4<> grid(value.getHeight(), value.getWidth(), value.getUnit());
144
145 // Copy obstacles
146 for (auto &&i: ext::make_mover(std::move(value).getObstacleList())) {
148 obstacle = graph::GraphNormalize::normalizeObstacle(std::move(i));
149
150 grid.addObstacle(std::move(obstacle));
151 }
152
153 return grid;
154 }
155};
156
157} // namespace grid
158
159// =====================================================================================================================
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
static ext::pair< DefaultCoordinateType, DefaultCoordinateType > normalizeObstacle(ext::pair< TCoordinate, TCoordinate > &&obstacle)
Definition: Normalize.hpp:82
TCoordinate coordinate_type
Definition: GridInterface.hpp:23
TEdge edge_type
Definition: GridInterface.hpp:24
Definition: SquareGrid.hpp:29
TCoordinate getHeight() const
Definition: SquareGrid.hpp:155
TCoordinate getWidth() const
Definition: SquareGrid.hpp:160
TCoordinate m_height
Definition: SquareGrid.hpp:41
TCoordinate m_width
Definition: SquareGrid.hpp:42
ext::set< node_type > m_obstacles
Definition: SquareGrid.hpp:43
const ext::set< node_type > & getObstacleList() const &
Definition: SquareGrid.hpp:142
Definition: WeightedSquareGrid4.hpp:18
edge_type::weight_type getUnit() const
Definition: WeightedSquareGrid4.hpp:80
bool isValidDirection(direction_type direction) const override
Definition: WeightedSquareGrid4.hpp:109
SquareGridDirections direction_type
Definition: WeightedSquareGrid4.hpp:25
TEdge createEdge(const node_type &a, const node_type &b) const override
Definition: WeightedSquareGrid4.hpp:101
WeightedSquareGrid4(TCoordinate height, TCoordinate width, typename edge_type::weight_type unit=1)
Definition: WeightedSquareGrid4.hpp:92
void setUnit(typename edge_type::weight_type unit)
Definition: WeightedSquareGrid4.hpp:85
auto operator<=>(const WeightedSquareGrid4 &other) const
Definition: WeightedSquareGrid4.hpp:46
edge_type::weight_type m_unit
Definition: WeightedSquareGrid4.hpp:29
std::string name() const override
Definition: WeightedSquareGrid4.hpp:122
bool operator==(const WeightedSquareGrid4 &other) const
Definition: WeightedSquareGrid4.hpp:50
ext::pair< TCoordinate, TCoordinate > node_type
Definition: WeightedSquareGrid4.hpp:24
int i
Definition: AllEpsilonClosure.h:118
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
Definition: GridDirection.hpp:12
SquareGridDirections
Definition: GridDirection.hpp:16
static grid::WeightedSquareGrid4 eval(grid::WeightedSquareGrid4< TCoordinate, TEdge > &&value)
Definition: WeightedSquareGrid4.hpp:142
Definition: normalize.hpp:13