24 : max_cycles_(max_cycles), seed_(seed) {}
31 bool converged =
false;
33 std::vector<int> label_order(num_labels);
34 std::iota(label_order.begin(), label_order.end(), 0);
35 std::mt19937 g(seed_);
37 while (!converged && cycle < max_cycles_) {
38 bool any_changed =
false;
39 std::shuffle(label_order.begin(), label_order.end(), g);
40 for (
int alpha: label_order) {
43 if (!any_changed) converged =
true;
Performs alpha-expansion moves on an EnergyModel using a pluggable max-flow solver.
Definition AlphaExpansion.hpp:20
bool perform_expansion_move(const int alpha_label) const
Attempts a single alpha-expansion move for alpha_label.
Definition AlphaExpansion.hpp:41
Stores the graph and energy costs for the Alpha-Expansion algorithm.
Definition EnergyModel.hpp:17
int num_labels() const
Returns the total number of labels.
Definition EnergyModel.hpp:35
Abstract base class for alpha-expansion iteration strategies.
Definition ExpansionStrategy.hpp:32
Expansion strategy that shuffles the label order randomly each cycle.
Definition RandomizedStrategy.hpp:18
int execute(AlphaExpansion< T > &optimizer, EnergyModel< T > &model) const override
Runs randomized alpha-expansion until convergence or max_cycles.
Definition RandomizedStrategy.hpp:28
RandomizedStrategy(int max_cycles=100, unsigned int seed=42)
Constructs the strategy.
Definition RandomizedStrategy.hpp:23