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