Fawkes API Fawkes Development Version
edge_constraint.cpp
1/***************************************************************************
2 * edge_constraint.cpp - base class for edge constraints
3 *
4 * Created: Sat Jul 12 14:48:02 2014
5 * Copyright 2014 Sebastian Reuter
6 * 2014 Tim Niemueller
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#include <navgraph/constraints/edge_constraint.h>
23
24namespace fawkes {
25
26/** @class NavGraphEdgeConstraint <navgraph/constraints/edge_constraint.h>
27 * Constraint that can be queried to check if an edge is blocked.
28 * @author Sebastian Reuter
29 * @author Tim Niemueller
30 *
31 * @fn bool NavGraphEdgeConstraint::blocks(const fawkes::NavGraphNode &from, const fawkes::NavGraphNode &to) noexcept = 0
32 * Check if constraint blocks an edge.
33 * This method must be implemented by constraint classes. It is called
34 * to determine if an edge should be considered blocked and therefore
35 * cannot be expanded during path search.
36 *
37 * Note that the nodes may be passed in either ordering, therefore
38 * you should not rely on a particular order, not even for directed
39 * nodes!
40 *
41 * Further note that the method may not throw an exception. Handle
42 * this internally appropriately.
43 *
44 * @param from node from which the edge originates
45 * @param to node to which the edge leads
46 * @return true if the edge should be considered blocked, false otherwise
47 *
48 * @var std::string NavGraphEdgeConstraint::name_
49 * Name of constraint.
50 */
51
52/** Constructor.
53 * @param name name of edge constraint
54 */
56{
57 name_ = name;
58}
59
60/** Constructor.
61 * @param name name of edge constraint
62 */
64{
65 name_ = name;
66}
67
68/** Virtual empty destructor. */
70{
71}
72
73/** Get name of constraint.
74 * @return name of constraint
75 */
76std::string
78{
79 return name_;
80}
81
82/** Perform compuations before graph search and to indicate re-planning.
83 * The compute method is called on all constraints just before a path
84 * search is performed and to check if re-planning should be tried.
85 *
86 * It can be used for example to cache results for the coming search
87 * run. The search guarantees that for each complete search run
88 * compute() is called once and only once and that no two search runs
89 * overlap, i.e., compute() will not be called while another search is
90 * still running.
91 *
92 * Constraints must indicate whether any change has occured during
93 * computation or since the last compute() call through the return
94 * value. This is used to determine if re-planning should be
95 * attempted.
96 *
97 * @return true if a change has occured during computation or since
98 * the last call, false otherwise
99 */
100bool
102{
103 return false;
104}
105
106/** Check if constraint matches name.
107 * @param name name string to compare this constraints name to
108 * @return true if the given name is the same as this constraint's name,
109 * false otherwise
110 */
111bool
112NavGraphEdgeConstraint::operator==(const std::string &name) const
113{
114 return name_ == name;
115}
116
117} // end of namespace fawkes
std::string name_
Name of constraint.
NavGraphEdgeConstraint(const std::string &name)
Constructor.
bool operator==(const std::string &name) const
Check if constraint matches name.
virtual bool compute(void) noexcept
Perform compuations before graph search and to indicate re-planning.
virtual ~NavGraphEdgeConstraint()
Virtual empty destructor.
std::string name()
Get name of constraint.
Fawkes library namespace.