Alpha Expansion Library
C++ library for the Alpha-Expansion graph-cut algorithm with Python bindings
Loading...
Searching...
No Matches
SequentialStrategy.hpp
Go to the documentation of this file.
1#pragma once
2
5
13template <typename T>
15public:
18 SequentialStrategy(int max_cycles = 100) : max_cycles_(max_cycles) {}
19
22 int execute(AlphaExpansion<T> &optimizer, EnergyModel<T> &model) const override {
23 int num_labels = model.num_labels();
24 int cycle = 0;
25 bool converged = false;
26
27 while (!converged && cycle < max_cycles_) {
28 bool any_changed = false;
29 for (int alpha = 0; alpha < num_labels; ++alpha) {
30 if (optimizer.perform_expansion_move(alpha)) any_changed = true;
31 }
32 if (!any_changed) converged = true;
33 cycle++;
34 }
35 return cycle;
36 }
37
38private:
39 int max_cycles_;
40};
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 cycles through labels in fixed order 0, 1, …, K-1.
Definition SequentialStrategy.hpp:14
SequentialStrategy(int max_cycles=100)
Constructs the strategy.
Definition SequentialStrategy.hpp:18
int execute(AlphaExpansion< T > &optimizer, EnergyModel< T > &model) const override
Runs sequential alpha-expansion until convergence or max_cycles.
Definition SequentialStrategy.hpp:22