FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
Core::FMTMask Class Reference

Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask. More...

#include <FMTMask.h>

Public Member Functions

 FMTMask (FMTMask &&rhs) noexcept
 Move copy constructor.
 
FMTMaskoperator= (FMTMask &&rhs) noexcept
 Move assignment operator for FMTMask.
 
void swap (FMTMask &rhs)
 Swap this mask with another.
 
 FMTMask ()
 Default constructor for FMTMask.
 
 FMTMask (const FMTMask &rhs)
 Copy constructor for FMTMask.
 
virtual ~FMTMask ()=default
 Default virtual destructor for FMTMask.
 
 FMTMask (const boost::dynamic_bitset< uint8_t > &bits)
 Construct a mask setting only the bitset data member.
 
 operator bool () const
 Return true if the mask is not empty by looking at the data bitset.
 
 FMTMask (const std::string &mask, const boost::dynamic_bitset< uint8_t > &bits)
 Construct a mask from an already set bitset and a string mask used as name.
 
 FMTMask (const std::string &mask, const std::vector< FMTTheme > &themes)
 Construct a complete mask from a string and sorted themes.
 
 FMTMask (const std::vector< std::string > &values, const std::vector< FMTTheme > &themes)
 Construct a mask from a vector of attribute strings and sorted themes.
 
 FMTMask (const std::vector< FMTTheme > &themes)
 Construct an empty mask sized for the given themes.
 
void clear ()
 Clear the data and name members.
 
size_t size () const
 Return the size of the bitset data member.
 
size_t count () const
 Return the number of bits set.
 
std::string get (const std::vector< FMTTheme > &themes) const
 Get the string mask name based on the bitset data and sorted themes.
 
std::string get (const FMTTheme &theme) const
 Get the attribute of the mask for a given theme.
 
const std::string & getAttribute (const FMTTheme &p_theme) const
 When you deal with FMTDevelopment you can directly call this to get a reference to the attribute string.
 
size_t getSubsetCount (const FMTTheme &theme) const
 Return the number of bits set for the given theme subset.
 
void set (const std::vector< FMTTheme > &themes, const std::string &value)
 Set the bitset data for some themes from a mask string.
 
void setExclusiveBits (const FMTMask &p_mask, const FMTTheme &p_theme)
 Flip only the theme subset and clear the mask of the intersection with another mask.
 
std::vector< size_t > getNonFullBlocks () const
 Return the indexes of the blocks that contain a 0.
 
bool isSubsetOf (const FMTMask &p_mask, const std::vector< size_t > &p_subset) const
 Check if this mask is a subset of another mask by looking at a block subset.
 
void set (const FMTTheme &theme, const std::string &value)
 Set the bitset data for a given theme from an attribute.
 
std::vector< const Core::FMTTheme * > getStaticThemes (const std::vector< const Core::FMTTheme * > &themes) const
 Return the themes that only use aggregates or a question mark for the mask.
 
std::vector< const Core::FMTTheme * > getSelectedThemes (const std::vector< Core::FMTTheme > &themes) const
 Return the themes that have any bit set in the mask.
 
bool isNotThemesSubset (const FMTMask &rhs, const std::vector< const Core::FMTTheme * > &themes) const
 Return true if this mask is not part of rhs based on the sorted themes.
 
bool isNotThemesSubset (const FMTMask &rhs, const std::vector< Core::FMTTheme > &themes) const
 Return true if this mask is not part of rhs based on the sorted themes.
 
FMTMask removeAggregates (const std::vector< FMTTheme > &themes, bool questionmarkonly=false) const
 Return a new mask with the bits of aggregates or question marks unset for the given themes.
 
bool empty () const
 Return true if the data member is empty.
 
void update (const std::vector< FMTTheme > &themes)
 Update the name member from the bitset data using a sorted list of themes.
 
std::vector< FMTMaskdecompose (const FMTTheme &theme) const
 Disaggregate the attribute of a theme from the mask into a vector of masks, one per possible attribute.
 
void append (const boost::dynamic_bitset< uint8_t > &bits)
 Append a bitset to the bitset data member of the mask.
 
template<class typetobinarize >
void binarizedAppend (const typetobinarize &element)
 Binarize an element and append it to the mask.
 
void unionWith (const FMTMask &rhs)
 Performs an in-place union with another mask.
 
FMTMask getUnion (const FMTMask &rhs) const
 Return the union of this mask and another mask.
 
FMTMask getIntersect (const FMTMask &rhs) const
 Return the intersection of this mask and another mask.
 
void setIntersect (const FMTMask &rhs)
 set the intersect with this mask using rhs mask.
 
boost::dynamic_bitset< uint8_t > getBitsetIntersect (const FMTMask &rhs) const
 Return the bitset of the intersection of this mask and another mask.
 
FMTMaskoperator= (const FMTMask &rhs)
 Copy assignment operator for FMTMask.
 
bool operator!= (const FMTMask &rhs) const
 Inequality comparison operator of FMTMask.
 
bool operator== (const FMTMask &rhs) const
 Equality comparison operator of FMTMask.
 
bool operator< (const FMTMask &rhs) const
 Less than comparison operator of FMTMask.
 
FMTMask resume (const boost::dynamic_bitset< uint8_t > &rhs) const
 Return a mask with the selected name and data using a bitset.
 
FMTMask resume (const std::vector< size_t > &indexes) const
 Return a mask with the selected name and data using mask indexes.
 
size_t hash () const
 Return the hash of the mask.
 
std::string getBitsString () const
 Return the binary representation of the bitset as a string.
 
 operator std::string () const
 Return the name of the mask.
 
bool isSubsetOf (const FMTMask &p_rhs) const
 Check if this mask is a subset of another mask.
 
const boost::dynamic_bitset< uint8_t > & getBitsetReference () const
 Return a const reference to the bitset data member.
 
const std::string & getStringReference () const
 Return a const reference to the name string member.
 
void reserve (size_t p_size)
 reserve memory for the boost dynamicbitset.
 
FMTMask refine (const FMTMask &mask, const std::vector< FMTTheme > &themes) const
 Return a new mask where the question marks are completed with the attributes of another mask.
 
FMTMask getPostSolveMask (const FMTMask &mask, const std::vector< FMTTheme > &themes) const
 Turn off the bits of themes that are still active on a base postsolve mask.
 
FMTMask preSolve (const FMTMaskFilter &filter, const std::vector< FMTTheme > &presolvedthemes) const
 Return a presolved mask with potentially less data using a filter and a subset of the original themes.
 
void preSolveRef (const FMTMaskFilter &p_filter, const std::vector< FMTTheme > &p_presolvedThemes, bool p_allowReallocation=true)
 Presolve this mask in place with potentially less data using a filter and a subset of the original themes.
 
bool canPreSolve (const FMTMaskFilter &p_filter, const std::vector< FMTTheme > &p_presolvedThemes) const
 Return true if the mask can be presolved with the given filter and themes.
 
FMTMask postSolve (const FMTMaskFilter &filter, const std::vector< FMTTheme > &basethemes) const
 Return a postsolved mask using a filter and the original themes.
 
template<>
void binarizedAppend (const double &element)
 

Friends

class FMTTheme
 
class boost::serialization::access
 Serialize the FMTMask for multiprocessing across multiple cpus (pickle in Python).
 

Detailed Description

Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask.

A set bit means the attribute of a given theme is part of the mask; the data size equals the sum of the theme sizes. The name member holds the attribute values as a string. Multiple bits set for a theme mean the mask contains an aggregate or a question mark.

Constructor & Destructor Documentation

◆ FMTMask() [1/8]

Core::FMTMask::FMTMask ( FMTMask &&  rhs)
noexcept

Move copy constructor.

Parameters
[in]rhsdevelopment to swap

◆ FMTMask() [2/8]

Core::FMTMask::FMTMask ( )

Default constructor for FMTMask.

◆ FMTMask() [3/8]

Core::FMTMask::FMTMask ( const FMTMask rhs)

Copy constructor for FMTMask.

Parameters
[in]rhsthe FMTMask to copy.

◆ ~FMTMask()

virtual Core::FMTMask::~FMTMask ( )
virtualdefault

Default virtual destructor for FMTMask.

◆ FMTMask() [4/8]

Core::FMTMask::FMTMask ( const boost::dynamic_bitset< uint8_t > &  bits)

Construct a mask setting only the bitset data member.

Parameters
[in]bitsthe bitset data.

◆ FMTMask() [5/8]

Core::FMTMask::FMTMask ( const std::string &  mask,
const boost::dynamic_bitset< uint8_t > &  bits 
)

Construct a mask from an already set bitset and a string mask used as name.

Parameters
[in]maskthe string mask used as name.
[in]bitsthe bitset data.

◆ FMTMask() [6/8]

Core::FMTMask::FMTMask ( const std::string &  mask,
const std::vector< FMTTheme > &  themes 
)

Construct a complete mask from a string and sorted themes.

Parameters
[in]maskthe string mask.
[in]themesthe sorted themes.

◆ FMTMask() [7/8]

Core::FMTMask::FMTMask ( const std::vector< std::string > &  values,
const std::vector< FMTTheme > &  themes 
)

Construct a mask from a vector of attribute strings and sorted themes.

Parameters
[in]valuesthe attribute strings.
[in]themesthe sorted themes.

◆ FMTMask() [8/8]

Core::FMTMask::FMTMask ( const std::vector< FMTTheme > &  themes)

Construct an empty mask sized for the given themes.

Parameters
[in]themesthe sorted themes.

Member Function Documentation

◆ append()

void Core::FMTMask::append ( const boost::dynamic_bitset< uint8_t > &  bits)

Append a bitset to the bitset data member of the mask.

Parameters
[in]bitsthe bitset to append.

◆ binarizedAppend() [1/2]

template<>
void Core::FMTMask::binarizedAppend ( const double &  element)
inline

◆ binarizedAppend() [2/2]

template<class typetobinarize >
void Core::FMTMask::binarizedAppend ( const typetobinarize &  element)
inline

Binarize an element and append it to the mask.

Template Parameters
typetobinarizethe type of the element.
Parameters
[in]elementthe element to binarize and append.

◆ canPreSolve()

bool Core::FMTMask::canPreSolve ( const FMTMaskFilter p_filter,
const std::vector< FMTTheme > &  p_presolvedThemes 
) const

Return true if the mask can be presolved with the given filter and themes.

Parameters
[in]p_filterthe mask filter.
[in]p_presolvedThemesthe presolved themes.
Returns
true if the mask can be presolved else false.

◆ clear()

void Core::FMTMask::clear ( )

Clear the data and name members.

◆ count()

size_t Core::FMTMask::count ( ) const

Return the number of bits set.

Returns
the number of bits set.

◆ decompose()

std::vector< FMTMask > Core::FMTMask::decompose ( const FMTTheme theme) const

Disaggregate the attribute of a theme from the mask into a vector of masks, one per possible attribute.

Parameters
[in]themethe theme to decompose.
Returns
a vector of masks, one per possible attribute.

◆ empty()

bool Core::FMTMask::empty ( ) const

Return true if the data member is empty.

Returns
true if the mask is empty else false.

◆ get() [1/2]

std::string Core::FMTMask::get ( const FMTTheme theme) const

Get the attribute of the mask for a given theme.

Parameters
[in]themethe theme.
Returns
the attribute of the theme.

◆ get() [2/2]

std::string Core::FMTMask::get ( const std::vector< FMTTheme > &  themes) const

Get the string mask name based on the bitset data and sorted themes.

Parameters
[in]themesthe sorted themes.
Returns
the string mask name.

◆ getAttribute()

const std::string & Core::FMTMask::getAttribute ( const FMTTheme p_theme) const

When you deal with FMTDevelopment you can directly call this to get a reference to the attribute string.

Parameters
[in]p_themethe theme we target
Returns
a const reference to the attribute.

◆ getBitsetIntersect()

boost::dynamic_bitset< uint8_t > Core::FMTMask::getBitsetIntersect ( const FMTMask rhs) const

Return the bitset of the intersection of this mask and another mask.

Parameters
[in]rhsthe other mask.
Returns
the intersection bitset.

◆ getBitsetReference()

const boost::dynamic_bitset< uint8_t > & Core::FMTMask::getBitsetReference ( ) const
inline

Return a const reference to the bitset data member.

Returns
a const reference to the bitset.

◆ getBitsString()

std::string Core::FMTMask::getBitsString ( ) const

Return the binary representation of the bitset as a string.

Returns
the binary representation of the bitset.

◆ getIntersect()

FMTMask Core::FMTMask::getIntersect ( const FMTMask rhs) const

Return the intersection of this mask and another mask.

Parameters
[in]rhsthe other mask.
Returns
the intersection mask.

◆ getNonFullBlocks()

std::vector< size_t > Core::FMTMask::getNonFullBlocks ( ) const

Return the indexes of the blocks that contain a 0.

Returns
a vector of indexes of the blocks that contain a 0.

◆ getPostSolveMask()

FMTMask Core::FMTMask::getPostSolveMask ( const FMTMask mask,
const std::vector< FMTTheme > &  themes 
) const

Turn off the bits of themes that are still active on a base postsolve mask.

Parameters
[in]maskthe mask used to turn off bits.
[in]themesthe themes.
Returns
the postsolve mask.

◆ getSelectedThemes()

std::vector< const Core::FMTTheme * > Core::FMTMask::getSelectedThemes ( const std::vector< Core::FMTTheme > &  themes) const

Return the themes that have any bit set in the mask.

Parameters
[in]themesthe themes to filter.
Returns
the selected themes.

◆ getStaticThemes()

std::vector< const Core::FMTTheme * > Core::FMTMask::getStaticThemes ( const std::vector< const Core::FMTTheme * > &  themes) const

Return the themes that only use aggregates or a question mark for the mask.

Parameters
[in]themesthe themes to filter.
Returns
the static themes.

◆ getStringReference()

const std::string & Core::FMTMask::getStringReference ( ) const
inline

Return a const reference to the name string member.

Returns
a const reference to the name string.

◆ getSubsetCount()

size_t Core::FMTMask::getSubsetCount ( const FMTTheme theme) const

Return the number of bits set for the given theme subset.

Parameters
[in]themethe theme.
Returns
the number of bits set for the theme subset.

◆ getUnion()

FMTMask Core::FMTMask::getUnion ( const FMTMask rhs) const

Return the union of this mask and another mask.

Parameters
[in]rhsthe other mask.
Returns
the union mask.

◆ hash()

size_t Core::FMTMask::hash ( ) const
inline

Return the hash of the mask.

Returns
the hash value.

◆ isNotThemesSubset() [1/2]

bool Core::FMTMask::isNotThemesSubset ( const FMTMask rhs,
const std::vector< const Core::FMTTheme * > &  themes 
) const

Return true if this mask is not part of rhs based on the sorted themes.

Parameters
[in]rhsthe other mask.
[in]themesthe sorted themes.
Returns
true if this mask is not a subset of rhs else false.

◆ isNotThemesSubset() [2/2]

bool Core::FMTMask::isNotThemesSubset ( const FMTMask rhs,
const std::vector< Core::FMTTheme > &  themes 
) const

Return true if this mask is not part of rhs based on the sorted themes.

Parameters
[in]rhsthe other mask.
[in]themesthe sorted themes.
Returns
true if this mask is not a subset of rhs else false.

◆ isSubsetOf() [1/2]

bool Core::FMTMask::isSubsetOf ( const FMTMask p_mask,
const std::vector< size_t > &  p_subset 
) const

Check if this mask is a subset of another mask by looking at a block subset.

Parameters
[in]p_maskthe other mask.
[in]p_subsetthe block subset.
Returns
true if all blocks are subset of this else false.

◆ isSubsetOf() [2/2]

bool Core::FMTMask::isSubsetOf ( const FMTMask p_rhs) const

Check if this mask is a subset of another mask.

Parameters
[in]p_rhsthe mask to check against.
Returns
true if this mask is a subset of p_rhs else false.

◆ operator bool()

Core::FMTMask::operator bool ( ) const
explicit

Return true if the mask is not empty by looking at the data bitset.

Returns
true if the mask is not empty else false.

◆ operator std::string()

Core::FMTMask::operator std::string ( ) const
inline

Return the name of the mask.

Returns
the name of the mask.

◆ operator!=()

bool Core::FMTMask::operator!= ( const FMTMask rhs) const

Inequality comparison operator of FMTMask.

Parameters
[in]rhsthe mask to compare with.
Returns
true if both masks are different else false.

◆ operator<()

bool Core::FMTMask::operator< ( const FMTMask rhs) const

Less than comparison operator of FMTMask.

Parameters
[in]rhsthe mask to compare with.
Returns
true if this mask is less than rhs else false.

◆ operator=() [1/2]

FMTMask & Core::FMTMask::operator= ( const FMTMask rhs)

Copy assignment operator for FMTMask.

Parameters
[in]rhsthe mask to copy.
Returns
a reference to this FMTMask.

◆ operator=() [2/2]

FMTMask & Core::FMTMask::operator= ( FMTMask &&  rhs)
noexcept

Move assignment operator for FMTMask.

Parameters
[in]rhsthe mask to move from.
Returns
a reference to this FMTMask.

◆ operator==()

bool Core::FMTMask::operator== ( const FMTMask rhs) const

Equality comparison operator of FMTMask.

Parameters
[in]rhsthe mask to compare with.
Returns
true if both masks are equal else false.

◆ postSolve()

FMTMask Core::FMTMask::postSolve ( const FMTMaskFilter filter,
const std::vector< FMTTheme > &  basethemes 
) const

Return a postsolved mask using a filter and the original themes.

Parameters
[in]filterthe mask filter.
[in]basethemesthe original themes.
Returns
the postsolved mask.

◆ preSolve()

FMTMask Core::FMTMask::preSolve ( const FMTMaskFilter filter,
const std::vector< FMTTheme > &  presolvedthemes 
) const

Return a presolved mask with potentially less data using a filter and a subset of the original themes.

Parameters
[in]filterthe mask filter.
[in]presolvedthemesthe presolved themes.
Returns
the presolved mask.

◆ preSolveRef()

void Core::FMTMask::preSolveRef ( const FMTMaskFilter p_filter,
const std::vector< FMTTheme > &  p_presolvedThemes,
bool  p_allowReallocation = true 
)

Presolve this mask in place with potentially less data using a filter and a subset of the original themes.

Parameters
[in]p_filterthe mask filter.
[in]p_presolvedThemesthe presolved themes.
[in]p_allowReallocationif true allows reallocation of the data.

◆ refine()

FMTMask Core::FMTMask::refine ( const FMTMask mask,
const std::vector< FMTTheme > &  themes 
) const

Return a new mask where the question marks are completed with the attributes of another mask.

Parameters
[in]maskthe mask to refine from.
[in]themesthe themes.
Returns
the refined mask.

◆ removeAggregates()

FMTMask Core::FMTMask::removeAggregates ( const std::vector< FMTTheme > &  themes,
bool  questionmarkonly = false 
) const

Return a new mask with the bits of aggregates or question marks unset for the given themes.

Parameters
[in]themesthe themes.
[in]questionmarkonlyif true only removes question marks.
Returns
the mask without aggregates.

◆ reserve()

void Core::FMTMask::reserve ( size_t  p_size)

reserve memory for the boost dynamicbitset.

Parameters
[in]p_sizenumber of bits to reserve.

◆ resume() [1/2]

FMTMask Core::FMTMask::resume ( const boost::dynamic_bitset< uint8_t > &  rhs) const

Return a mask with the selected name and data using a bitset.

Parameters
[in]rhsthe selection bitset.
Returns
the resumed mask.

◆ resume() [2/2]

FMTMask Core::FMTMask::resume ( const std::vector< size_t > &  indexes) const

Return a mask with the selected name and data using mask indexes.

Parameters
[in]indexesthe selection indexes.
Returns
the resumed mask.

◆ set() [1/2]

void Core::FMTMask::set ( const FMTTheme theme,
const std::string &  value 
)

Set the bitset data for a given theme from an attribute.

Parameters
[in]themethe theme.
[in]valuethe attribute.

◆ set() [2/2]

void Core::FMTMask::set ( const std::vector< FMTTheme > &  themes,
const std::string &  value 
)

Set the bitset data for some themes from a mask string.

Parameters
[in]themesthe themes.
[in]valuethe mask string.

◆ setExclusiveBits()

void Core::FMTMask::setExclusiveBits ( const FMTMask p_mask,
const FMTTheme p_theme 
)

Flip only the theme subset and clear the mask of the intersection with another mask.

Parameters
[in]p_maskthe mask to intersect with.
[in]p_themethe theme to subset on.

◆ setIntersect()

void Core::FMTMask::setIntersect ( const FMTMask rhs)

set the intersect with this mask using rhs mask.

Parameters
[in]rhsthe mask we intersect with.

◆ size()

size_t Core::FMTMask::size ( ) const

Return the size of the bitset data member.

Returns
the size of the bitset.

◆ swap()

void Core::FMTMask::swap ( FMTMask rhs)

Swap this mask with another.

Parameters
[in,out]rhsthe mask to swap with.

◆ unionWith()

void Core::FMTMask::unionWith ( const FMTMask rhs)

Performs an in-place union with another mask.

Parameters
rhsMask whose bits will be added to the current mask.

◆ update()

void Core::FMTMask::update ( const std::vector< FMTTheme > &  themes)

Update the name member from the bitset data using a sorted list of themes.

Parameters
[in]themesthe sorted themes.

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Serialize the FMTMask for multiprocessing across multiple cpus (pickle in Python).

Template Parameters
Archivethe archive type.
Parameters
[in,out]arthe archive to serialize to or from.
[in]versionthe serialization version.

◆ FMTTheme

friend class FMTTheme
friend

The documentation for this class was generated from the following file: