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 
24 namespace fawkes{
25 #if 0 /* just to make Emacs auto-indent happy */
26 }
27 #endif
28 
29 /** @class NavGraphEdgeConstraint <navgraph/constraints/edge_constraint.h>
30  * Constraint that can be queried to check if an edge is blocked.
31  * @author Sebastian Reuter
32  * @author Tim Niemueller
33  *
34  * @fn bool NavGraphEdgeConstraint::blocks(const fawkes::NavGraphNode &from, const fawkes::NavGraphNode &to) throw() = 0
35  * Check if constraint blocks an edge.
36  * This method must be implemented by constraint classes. It is called
37  * to determine if an edge should be considered blocked and therefore
38  * cannot be expanded during path search.
39  *
40  * Note that the nodes may be passed in either ordering, therefore
41  * you should not rely on a particular order, not even for directed
42  * nodes!
43  *
44  * Further note that the method may not throw an exception. Handle
45  * this internally appropriately.
46  *
47  * @param from node from which the edge originates
48  * @param to node to which the edge leads
49  * @return true if the edge should be considered blocked, false otherwise
50  *
51  * @var std::string NavGraphEdgeConstraint::name_
52  * Name of constraint.
53  */
54 
55 
56 /** Constructor.
57  * @param name name of edge constraint
58  */
60 {
61  name_ = name;
62 }
63 
64 /** Constructor.
65  * @param name name of edge constraint
66  */
68 {
69  name_ = name;
70 }
71 
72 
73 /** Virtual empty destructor. */
75 {
76 }
77 
78 /** Get name of constraint.
79  * @return name of constraint
80  */
81 std::string
83 {
84  return name_;
85 }
86 
87 
88 /** Perform compuations before graph search and to indicate re-planning.
89  * The compute method is called on all constraints just before a path
90  * search is performed and to check if re-planning should be tried.
91  *
92  * It can be used for example to cache results for the coming search
93  * run. The search guarantees that for each complete search run
94  * compute() is called once and only once and that no two search runs
95  * overlap, i.e., compute() will not be called while another search is
96  * still running.
97  *
98  * Constraints must indicate whether any change has occured during
99  * computation or since the last compute() call through the return
100  * value. This is used to determine if re-planning should be
101  * attempted.
102  *
103  * @return true if a change has occured during computation or since
104  * the last call, false otherwise
105  */
106 bool
108 {
109  return false;
110 }
111 
112 
113 /** Check if constraint matches name.
114  * @param name name string to compare this constraints name to
115  * @return true if the given name is the same as this constraint's name,
116  * false otherwise
117  */
118 bool
119 NavGraphEdgeConstraint::operator==(const std::string &name) const
120 {
121  return name_ == name;
122 }
123 
124 
125 } // end of namespace fawkes
Fawkes library namespace.
bool operator==(const std::string &name) const
Check if constraint matches name.
std::string name_
Name of constraint.
virtual ~NavGraphEdgeConstraint()
Virtual empty destructor.
std::string name()
Get name of constraint.
virtual bool compute(void)
Perform compuations before graph search and to indicate re-planning.
NavGraphEdgeConstraint(const std::string &name)
Constructor.