libeblearntools
|
#include <metaparser.h>
Public Member Functions | |
pairtree (string &var, string &val) | |
pairtree (uint var, uint val) | |
Construct a pairtree with its string ids directly. | |
pairtree () | |
Empty constructor, should be used for the unique root only. | |
virtual | ~pairtree () |
Destructor. | |
void | add (const string &var, string &val) |
Add variable/value pair to this tree. | |
map< uint, uint > | add (list< uint > &subvar, map< uint, uint > &ivars) |
natural_varmap | flatten (const string &key, natural_varmap *flat=NULL, map< uint, uint > *path=NULL) |
varmaplist | flatten (varmaplist *flat=NULL, map< uint, uint > *path=NULL) |
natural_varmap | best (const string &key, uint n=0, bool display=false) |
varmaplist | best (list< string > &keys, uint n=0, bool display=false, int maxiter=-1) |
varmaplist | best (list< string > &keys, const string &key, bool display=false) |
varmaplist | best (list< string > &keys, list< string > &keycomb, bool display=false) |
uint & | get_variable () |
Returns the variable name associated with this pair. | |
uint & | get_value () |
Returns the value associated with this pair. | |
void | pretty (string offset="") |
Pretty this tree, with a string offset beforehand. | |
void | pretty_flat (const string key, natural_varmap *flat=NULL) |
void | pretty_flat (varmaplist *flat=NULL, list< string > *keys=NULL) |
uint | get_max_uint (const string &var) |
Return the maximum uint value of variable var. | |
bool | exists (const string &var) |
Return true if variable var exists in the tree. | |
bool | delete_pair (const char *var, const char *value) |
map< uint, pairtree > & | get_subtree () |
Return sub tree. | |
Static Public Member Functions | |
static uint | get_var_id (const string &var) |
static uint | get_var_id (const char *var) |
static uint | get_val_id (const string &val) |
static list< uint > | to_varid_list (list< string > &l) |
static string | flat_to_string (const string key, natural_varmap *flat=NULL) |
static string | flat_to_string (varmaplist *flat=NULL, list< string > *keys=NULL) |
Static Public Attributes | |
static vector< string > | vars_vector |
Vector of all variables strings, ordered by their id. | |
static vector< string > | vals_vector |
Vector of all values strings, ordered by their id. |
A class representing a tree hierarchy of variable/value pairs. A pair tree is defined by a variable/value pair, and a subtree corresponding to 1 subvariable only (could be extended to multiple variables). The subtree is a map of pairtrees for each value of this subvariable.
ebl::pairtree::pairtree | ( | string & | var, |
string & | val | ||
) |
Constructor
var | A string containing a variable name. |
val | A string containing a value. |
map< uint, uint > ebl::pairtree::add | ( | list< uint > & | subvar, |
map< uint, uint > & | ivars | ||
) |
Add a set of variable/value pairs, organized by the 'subvar' order of variable names.
natural_varmap ebl::pairtree::best | ( | const string & | key, |
uint | n = 0 , |
||
bool | display = false |
||
) |
Return the n best values (minimized) of key, or all if n == 0.
display | If true, pretty best answers. |
varmaplist ebl::pairtree::best | ( | list< string > & | keys, |
uint | n = 0 , |
||
bool | display = false , |
||
int | maxiter = -1 |
||
) |
Return the n best sets of variables that minimize the keys in the order of their list, or all if n == 0.
display | If true, pretty best answers. |
maxiter | If >= 0, remove all occurences of 'i' > maxiter. |
varmaplist ebl::pairtree::best | ( | list< string > & | keys, |
const string & | key, | ||
bool | display = false |
||
) |
Return the best sets of variables that minimize the keys in the order of their list. Only 1 best answer per value of key 'key' is returned.
display | If true, pretty best answers. |
varmaplist ebl::pairtree::best | ( | list< string > & | keys, |
list< string > & | keycomb, | ||
bool | display = false |
||
) |
Return the best sets of variables that minimize the keys in the order of their list. Only 1 best answer per combination of values of each key contained in 'keycomb' is returned.
display | If true, pretty best answers. |
bool ebl::pairtree::delete_pair | ( | const char * | var, |
const char * | value | ||
) |
Delete pair var/val and its children. Returns true if found and deleted, false otherwise.
string ebl::pairtree::flat_to_string | ( | const string | key, |
natural_varmap * | flat = NULL |
||
) | [static] |
Returns a string representation of this tree flattened using key. If flat is not NULL, pretty this flat, otherwise generate a flat representation of the current tree.
string ebl::pairtree::flat_to_string | ( | varmaplist * | flat = NULL , |
list< string > * | keys = NULL |
||
) | [static] |
Returns a string representation of this tree flattened using key. If flat is not NULL, pretty this flat, otherwise generate a flat representation of the current tree.
keys | If not null, display keys first. |
varmaplist ebl::pairtree::flatten | ( | varmaplist * | flat = NULL , |
map< uint, uint > * | path = NULL |
||
) |
Return a flat representation of the tree, as a list of all possible branches (each branch is a map of var/val pairs).
natural_varmap ebl::pairtree::flatten | ( | const string & | key, |
natural_varmap * | flat = NULL , |
||
map< uint, uint > * | path = NULL |
||
) |
Return a flat representation of the tree, using the variable name key as key to represent each group of variables. E.g. if we have a tree with nodes "name" and "i", and leaves contain "error", "success" and we choose "error" as our key, this will return a map with all error values paired with all var/val pairs of "name", "i" and "success".
uint ebl::pairtree::get_val_id | ( | const string & | val | ) | [static] |
Returns the string id of variable 'val'. If not present, 'val' is added and assigned a new id.
uint ebl::pairtree::get_var_id | ( | const char * | var | ) | [static] |
Returns the string id of variable 'var'. If not present, 'var' is added and assigned a new id.
uint ebl::pairtree::get_var_id | ( | const string & | var | ) | [static] |
Returns the string id of variable 'var'. If not present, 'var' is added and assigned a new id.
void ebl::pairtree::pretty_flat | ( | const string | key, |
natural_varmap * | flat = NULL |
||
) |
Pretty this tree, flattened using key. If flat is not NULL, pretty this flat, otherwise generate a flat representation of the current tree.
void ebl::pairtree::pretty_flat | ( | varmaplist * | flat = NULL , |
list< string > * | keys = NULL |
||
) |
Pretty this tree, flattened. If flat is not NULL, pretty this flat, otherwise generate a flat representation of the current tree.
keys | If not null, display keys first. |
list< uint > ebl::pairtree::to_varid_list | ( | list< string > & | l | ) | [static] |
Returns list of ids corresponding to the list of strings 'l'. All strings are added to static internal members if not assigned yet.