AIToolbox
A library that offers tools for AI problem solving.
|
This class offers a minimal interface to manager a factor graph. More...
#include <AIToolbox/Factored/Utils/FactorGraph.hpp>
Classes | |
class | FactorNode |
Public Types | |
using | Variables = PartialKeys |
using | FactorList = std::list< FactorNode > |
using | FactorIt = typename FactorList::iterator |
using | CFactorIt = typename FactorList::const_iterator |
using | FactorItList = std::vector< FactorIt > |
using | value_type = FactorData |
using | iterator = FactorIt |
using | const_iterator = CFactorIt |
Public Member Functions | |
FactorGraph (size_t variables) | |
Basic constructor. More... | |
FactorGraph (const FactorGraph &other) | |
Copy constructor. More... | |
FactorGraph & | operator= (const FactorGraph &)=delete |
Deleted assignment operator. More... | |
void | reset (size_t variables) |
This function re-initializes the graph from scratch as if it was just being built. More... | |
const FactorItList & | getFactors (size_t variable) const |
This function returns all factors adjacent to the given variable. More... | |
const Variables & | getVariables (size_t variable) const |
This function returns all variables adjacent to a factor adjacent to the input variable. More... | |
const Variables & | getVariables (FactorIt factor) const |
This function returns all variables adjacent to the given factor. More... | |
const Variables & | getVariables (CFactorIt factor) const |
This function returns all variables adjacent to the given factor. More... | |
Variables | getVariables (const FactorItList &factors) const |
This function returns all variables adjacent to any of the given factors. More... | |
FactorIt | getFactor (const Variables &variables) |
This function returns an iterator to a factor adjacent to the given variables. More... | |
void | erase (size_t variable) |
This function partially removes an variable from the graph. More... | |
size_t | variableSize () const |
This function returns the number of variables still in the graph. More... | |
size_t | factorSize () const |
This function returns the number of factors still in the graph. More... | |
FactorIt | begin () |
This function provides an editable iterator to the beginning of the internal factor list. More... | |
CFactorIt | begin () const |
This function provides a const iterator to the beginning of the internal factor list. More... | |
CFactorIt | cbegin () const |
This function provides a const iterator to the beginning of the internal factor list. More... | |
FactorIt | end () |
This function provides an editable interactor to the end of the internal factor list. More... | |
CFactorIt | end () const |
This function provides a const interactor to the end of the internal factor list. More... | |
CFactorIt | cend () const |
This function provides a const interactor to the end of the internal factor list. More... | |
size_t | bestVariableToRemove (const Factors &F) const |
This function returns the variable which is the cheapest to remove with GenericVariableElimination. More... | |
This class offers a minimal interface to manager a factor graph.
This class allows to store arbitrary data into each factor, and to maintain adjacency lists between the factors and a given number of variables. The interface is intentionally very simple and tries to do very little, in order to allow clients to optimize their use of the graph as much as possible.
This class maintains a single FactorNode for any unique combination of variables. When multiple factors are needed, a single FactorNode containing a vector of data should suffice.
This class can allocate list nodes from an internal static pool; so it is probably not thread-safe.
FactorData | The class that is stored for each FactorNode. |
using AIToolbox::Factored::FactorGraph< FactorData >::CFactorIt = typename FactorList::const_iterator |
using AIToolbox::Factored::FactorGraph< FactorData >::const_iterator = CFactorIt |
using AIToolbox::Factored::FactorGraph< FactorData >::FactorIt = typename FactorList::iterator |
using AIToolbox::Factored::FactorGraph< FactorData >::FactorItList = std::vector<FactorIt> |
using AIToolbox::Factored::FactorGraph< FactorData >::FactorList = std::list<FactorNode> |
using AIToolbox::Factored::FactorGraph< FactorData >::iterator = FactorIt |
using AIToolbox::Factored::FactorGraph< FactorData >::value_type = FactorData |
using AIToolbox::Factored::FactorGraph< FactorData >::Variables = PartialKeys |
AIToolbox::Factored::FactorGraph< FD >::FactorGraph | ( | size_t | variables | ) |
Basic constructor.
This constructor initializes the variable adjacency list with the given number of variables. Variables in this class cannot be added, only removed.
variables | The number of variables with which to start the graph. |
AIToolbox::Factored::FactorGraph< FD >::FactorGraph | ( | const FactorGraph< FactorData > & | other | ) |
Copy constructor.
This constructor simply copies the graph, but also makes sure that the internal stored iterators point to the correct containers.
We do not check the internal FactorData, so make sure it doesn't have pointers or iterators inside!
other | The graph to copy. |
FactorGraph< FD >::CFactorIt AIToolbox::Factored::FactorGraph< FD >::begin |
This function provides an editable iterator to the beginning of the internal factor list.
This function is used in order to allow editing of all the factors.
CFactorIt AIToolbox::Factored::FactorGraph< FactorData >::begin | ( | ) | const |
This function provides a const iterator to the beginning of the internal factor list.
size_t AIToolbox::Factored::FactorGraph< FD >::bestVariableToRemove | ( | const Factors & | F | ) | const |
This function returns the variable which is the cheapest to remove with GenericVariableElimination.
The choice is made heuristically, as computing the true best is an NP-Complete problem.
F | The value space for each variable. |
FactorGraph< FD >::CFactorIt AIToolbox::Factored::FactorGraph< FD >::cbegin |
This function provides a const iterator to the beginning of the internal factor list.
FactorGraph< FD >::CFactorIt AIToolbox::Factored::FactorGraph< FD >::cend |
This function provides a const interactor to the end of the internal factor list.
FactorGraph< FD >::CFactorIt AIToolbox::Factored::FactorGraph< FD >::end |
This function provides an editable interactor to the end of the internal factor list.
CFactorIt AIToolbox::Factored::FactorGraph< FactorData >::end | ( | ) | const |
This function provides a const interactor to the end of the internal factor list.
void AIToolbox::Factored::FactorGraph< FD >::erase | ( | size_t | variable | ) |
This function partially removes an variable from the graph.
This function removes the selected variable, and ALL factors associated with it.
Removing the same variable more than once does not do anything.
variable | The variable to be removed. |
size_t AIToolbox::Factored::FactorGraph< FD >::factorSize |
This function returns the number of factors still in the graph.
FactorGraph< FD >::FactorIt AIToolbox::Factored::FactorGraph< FD >::getFactor | ( | const Variables & | variables | ) |
This function returns an iterator to a factor adjacent to the given variables.
This function may return an iterator to an already existing factor, or if it didn't exist before, to a newly created one.
This means that it is safe to call this function multiple times with the same input, as only one factor will be created.
As factors are kept in a list, insertion is O(1).
variables | The variables the factor returned should be adjacent of. |
const FactorGraph< FD >::FactorItList & AIToolbox::Factored::FactorGraph< FD >::getFactors | ( | size_t | variable | ) | const |
This function returns all factors adjacent to the given variable.
variable | The variable to look for. |
const FactorGraph< FD >::Variables & AIToolbox::Factored::FactorGraph< FD >::getVariables | ( | CFactorIt | factor | ) | const |
This function returns all variables adjacent to the given factor.
factor | A const iterator to the factor to look for. |
FactorGraph< FD >::Variables AIToolbox::Factored::FactorGraph< FD >::getVariables | ( | const FactorItList & | factors | ) | const |
This function returns all variables adjacent to any of the given factors.
This function is equivalent to calling the getNeighbors(FactorIt) function multiple times, and merging the results to eliminate duplicates.
factors | A list of iterators to the factors to look for. |
const FactorGraph< FD >::Variables & AIToolbox::Factored::FactorGraph< FD >::getVariables | ( | FactorIt | factor | ) | const |
This function returns all variables adjacent to the given factor.
factor | An iterator to the factor to look for. |
const FactorGraph< FD >::Variables & AIToolbox::Factored::FactorGraph< FD >::getVariables | ( | size_t | variable | ) | const |
This function returns all variables adjacent to a factor adjacent to the input variable.
variable | The variable to look for. |
|
delete |
Deleted assignment operator.
Since we already provide a copy constructor, this is redundant. The assignment operator provided by default would be broken, so we remove it.
void AIToolbox::Factored::FactorGraph< FD >::reset | ( | size_t | variables | ) |
This function re-initializes the graph from scratch as if it was just being built.
variables | The number of variables with which to start the graph. |
size_t AIToolbox::Factored::FactorGraph< FD >::variableSize |
This function returns the number of variables still in the graph.
This function returns the number of active variables in the graph (that have not been explicitly eliminated via erase(size_t)).