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