Infrared
|
Iterate over the assignments of a subset of variables. More...
#include <assignment.hpp>
Public Types | |
using | assignment_t = Assignment |
using | var_idx_t = assignment_t::var_idx_t |
using | var_value_t = assignment_t::var_value_t |
using | ep = typename FeatureNetwork::evaluation_policy_t |
using | fun_value_t = typename ep::fun_value_t |
using | function_t = typename ep::function_t |
using | constraint_t = typename ep::constraint_t |
Public Member Functions | |
AssignmentIterator (assignment_t &a, const std::vector< var_idx_t > &vars, const FeatureNetwork &cn, const std::vector< const constraint_t * > &constraints, const std::vector< const function_t * > &functions, const fun_value_t &initial_value) | |
constructor | |
void | reset () |
Reset iterator. | |
auto | value () |
get evaluation according to functions | |
void | register_finish_stage2_hook (int stage1_size, const std::function< void()> &hook) |
register hook to run after finishing stage 2 enumeration | |
const auto & | operator++ () |
Next valid partial assignment. | |
bool | finished () |
Check for termination. | |
Iterate over the assignments of a subset of variables.
The job of the assignment iterator goes beyond pure enumeration of the sub-assignments that are valid due to the domains of a subset of variables. It also checks validity due to constraints and functions and evaluates the functions.
Constraints and functions are evaluated as soon as all their variables are determined. For this purpose, the iterator precomputes tables ('boards'). Function values are combined via EvaluationPolicy::mul; partial products are tracked on the enumeration stack.
using ired::AssignmentIterator< FeatureNetwork >::assignment_t = Assignment |
using ired::AssignmentIterator< FeatureNetwork >::constraint_t = typename ep::constraint_t |
using ired::AssignmentIterator< FeatureNetwork >::ep = typename FeatureNetwork::evaluation_policy_t |
using ired::AssignmentIterator< FeatureNetwork >::fun_value_t = typename ep::fun_value_t |
using ired::AssignmentIterator< FeatureNetwork >::function_t = typename ep::function_t |
using ired::AssignmentIterator< FeatureNetwork >::var_idx_t = assignment_t::var_idx_t |
using ired::AssignmentIterator< FeatureNetwork >::var_value_t = assignment_t::var_value_t |
|
inline |
constructor
vars | vector of indices of the to-be-enumerated variables |
cn | constraint network, where everything takes place |
constraints | check assignments |
functions | check and evaluate assignments |
During the iteration, constraints and functions are evaluated. We evaluate only those constraints/functions that have at least on undetermined dependency on a variable in vars, where all dependencies outside of vars are already determined.
After construction with non-empty vars, the assignment is either set to the first valid assignment or finished() is true. After construction with empty vars, assignment is unchanged and finished() is false, but will be true immediately after a call to operator ++()!
|
inline |
Check for termination.
|
inline |
Next valid partial assignment.
Sets the assignment to the next valid assignment of vars_
|
inline |
register hook to run after finishing stage 2 enumeration
stage1_size | number of variables in stage 1 |
hook | function to be called after finishing stage 2 enumeration |
This is used in two-stage enumeration over two disjoint sets of variables; in the evaluation of a CN, this allows to marginalize over the second set and store the results as value of a function (the 'message') of the variables in the first set.
|
inline |
Reset iterator.
|
inline |
get evaluation according to functions
after initialization or a call of operator++, this yields the product of all functions on enumerated variables, where at least one variable is determined only by the enumeration