Heuristic Objective
(heuristic/objective.hpp)
- View this file on GitHub
- Last update: 2026-08-12 20:17:35+09:00
- Include:
#include "heuristic/objective.hpp"
Overview
Shared minimization and maximization vocabulary for heuristic search policies.
Most users only need to pass an Objective when constructing or calling a
search tool:
#include "heuristic/hill_climbing.hpp"
using m1une::heuristic::Objective;
m1une::heuristic::HillClimbing climbing(Objective::minimize);
The default objective in every heuristic header is Objective::maximize.
Interface
| Interface | Description | Complexity |
|---|---|---|
enum class Objective { minimize, maximize }; |
Selects whether smaller or larger scores rank first. | $O(1)$ |
bool better_score(const Score& first, const Score& second, Objective objective) |
Returns whether first is strictly better than second. Score must support <. |
$O(1)$ plus one or two score comparisons |
AnnealingObjective and HillClimbingObjective are aliases of Objective, so
one objective value can be reused across local-search policies.
better_score(first, second, objective) is mainly a helper for implementing
other heuristic algorithms. It is strict: equal scores return false in both
directions.
Required by
Heuristic Search
(heuristic/all.hpp)
Beam Search
(heuristic/beam_search.hpp)
Hill Climbing
(heuristic/hill_climbing.hpp)
Simulated Annealing
(heuristic/simulated_annealing.hpp)
Verified with
verify/heuristic/beam_search.test.cpp
verify/heuristic/hill_climbing.test.cpp
verify/heuristic/simulated_annealing.test.cpp
Code
#ifndef M1UNE_HEURISTIC_OBJECTIVE_HPP
#define M1UNE_HEURISTIC_OBJECTIVE_HPP 1
namespace m1une {
namespace heuristic {
enum class Objective {
minimize,
maximize,
};
template <class Score>
bool better_score(const Score& first, const Score& second,
Objective objective) {
if (objective == Objective::maximize) return second < first;
return first < second;
}
} // namespace heuristic
} // namespace m1une
#endif // M1UNE_HEURISTIC_OBJECTIVE_HPP#line 1 "heuristic/objective.hpp"
namespace m1une {
namespace heuristic {
enum class Objective {
minimize,
maximize,
};
template <class Score>
bool better_score(const Score& first, const Score& second,
Objective objective) {
if (objective == Objective::maximize) return second < first;
return first < second;
}
} // namespace heuristic
} // namespace m1une