m1une's library

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:heavy_check_mark: Heuristic Objective
(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

Verified with

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
Back to top page