Fawkes API Fawkes Development Version
static_list_edge_constraint.cpp
1/***************************************************************************
2 * static_list_edge_constraint.cpp - edge constraint that holds a static
3 * of edges to block
4 *
5 * Created: Sat Jul 12 16:48:23 2014
6 * Copyright 2014 Sebastian Reuter
7 * 2014 Tim Niemueller
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#include <navgraph/constraints/static_list_edge_constraint.h>
24
25#include <algorithm>
26
27namespace fawkes {
28
29/** @class NavGraphStaticListEdgeConstraint <navgraph/constraints/static_list_edge_constraint.h>
30 * Constraint that holds a list of edges to block.
31 * @author Sebastian Reuter
32 * @author Tim Niemueller
33 */
34
35/** Constructor.
36 * @param name name of edge constraint
37 */
40{
41 modified_ = false;
42}
43
44/** Constructor.
45 * @param name name of edge constraint
46 * @param edge_list list of edges to block
47 */
49 std::string name,
50 std::vector<fawkes::NavGraphEdge> &edge_list)
52{
53 edge_list_ = edge_list;
54 modified_ = false;
55}
56
57/** Virtual empty destructor. */
59{
60}
61
62bool
64{
65 if (modified_) {
66 modified_ = false;
67 return true;
68 } else {
69 return false;
70 }
71}
72
73/** Add a single edge to constraint list.
74 * @param edge edge to add to constraint list
75 */
76void
78{
79 if (!has_edge(edge)) {
80 modified_ = true;
81 edge_list_.push_back(edge);
82 }
83}
84
85/** Add multiple edges to constraint list.
86 * @param edges edges to add to constraint list
87 */
88void
89NavGraphStaticListEdgeConstraint::add_edges(const std::vector<fawkes::NavGraphEdge> &edges)
90{
91 for (const NavGraphEdge &n : edges) {
92 add_edge(n);
93 }
94}
95
96/** Remove a single edge from the constraint list.
97 * @param edge edge to remote
98 */
99void
101{
102 std::vector<NavGraphEdge>::iterator e = std::find(edge_list_.begin(), edge_list_.end(), edge);
103 if (e != edge_list_.end()) {
104 modified_ = true;
105 edge_list_.erase(e);
106 }
107}
108
109/** Check if constraint has a specific edge.
110 * @param edge edge to check
111 * @return true if edge is in list, false otherwise
112 */
113bool
115{
116 return (std::find(edge_list_.begin(), edge_list_.end(), edge) != edge_list_.end());
117}
118
119/** Get list of blocked edges.
120 * @return list of blocked edges
121 */
122const std::vector<fawkes::NavGraphEdge> &
124{
125 return edge_list_;
126}
127
128/** Remove all edges. */
129void
131{
132 if (!edge_list_.empty()) {
133 modified_ = true;
134 edge_list_.clear();
135 }
136}
137
138bool
140 const fawkes::NavGraphNode &to) noexcept
141{
142 for (NavGraphEdge &e : edge_list_) {
143 if ((e.from() == from.name() && e.to() == to.name())
144 || (e.from() == to.name() && e.to() == from.name())) {
145 return true;
146 }
147 }
148 return false;
149}
150
151} // end of namespace fawkes
Constraint that can be queried to check if an edge is blocked.
Topological graph edge.
Definition: navgraph_edge.h:38
Topological graph node.
Definition: navgraph_node.h:36
void add_edges(const std::vector< fawkes::NavGraphEdge > &edges)
Add multiple edges to constraint list.
void add_edge(const fawkes::NavGraphEdge &edge)
Add a single edge to constraint list.
NavGraphStaticListEdgeConstraint(std::string name)
Constructor.
virtual bool compute(void) noexcept
Perform compuations before graph search and to indicate re-planning.
void remove_edge(const fawkes::NavGraphEdge &edge)
Remove a single edge from the constraint list.
bool has_edge(const fawkes::NavGraphEdge &edge)
Check if constraint has a specific edge.
const std::vector< fawkes::NavGraphEdge > & edge_list() const
Get list of blocked edges.
virtual ~NavGraphStaticListEdgeConstraint()
Virtual empty destructor.
virtual bool blocks(const fawkes::NavGraphNode &from, const fawkes::NavGraphNode &to) noexcept
Check if constraint blocks an edge.
Fawkes library namespace.