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