ExpansionStrategy<T> controls the iteration loop: which labels to expand, in what order and when to stop. Subclass it to implement a custom policy.
Interface
template <typename T>
public:
};
Performs alpha-expansion moves on an EnergyModel using a pluggable max-flow solver.
Definition AlphaExpansion.hpp:20
Stores the graph and energy costs for the Alpha-Expansion algorithm.
Definition EnergyModel.hpp:17
Abstract base class for alpha-expansion iteration strategies.
Definition ExpansionStrategy.hpp:32
virtual ~ExpansionStrategy()=default
virtual int execute(AlphaExpansion< T > &optimizer, EnergyModel< T > &model) const =0
Runs the expansion strategy to convergence (or up to a cycle limit).
execute() calls optimizer.perform_expansion_move(alpha) for whatever labels and in whatever order the strategy decides. It returns the number of full cycles completed.
Example: Single-Pass Strategy
Tries each label exactly once and stops:
#pragma once
template <typename T>
public:
for (
int alpha = 0; alpha < model.
num_labels(); ++alpha)
return 1;
}
};
bool perform_expansion_move(const int alpha_label) const
Attempts a single alpha-expansion move for alpha_label.
Definition AlphaExpansion.hpp:41
int num_labels() const
Returns the total number of labels.
Definition EnergyModel.hpp:35
Using the Custom Strategy
#include "strategies/SinglePassStrategy.hpp"
auto factory = [](int v, int e) {
return std::make_unique<BKSolver<int>>(v, e);
};
SinglePassStrategy<int> strategy;
int cycles = strategy.execute(optimizer, model);
Tips
- Call
model.evaluate_total_energy() to check progress between moves.
- Call
model.get_labels() and model.set_labels() to save and restore state. GreedyStrategy uses this to roll back non-improving moves.
- Return the number of full cycles from
execute(). The demo app shows this value in the convergence dialog.