smats  0.0.1
Satisfability Modulo Arithmetic Theories Symbols
Loading...
Searching...
No Matches
smats::Variable Class Reference

#include <variable.h>

Public Types

enum class  Type : std::uint8_t { CONTINUOUS , INTEGER , BINARY , BOOLEAN }
 
using Id = std::size_t
 

Public Member Functions

 Variable ()
 
 Variable (const std::string &name, Type type=Type::CONTINUOUS)
 
 Variable (const Variable &)=default
 
 Variable (Variable &&other) noexcept
 
Variableoperator= (const Variable &)=default
 
Variableoperator= (Variable &&other) noexcept
 
bool is_dummy () const
 
Id id () const
 
Type type () const
 
const std::string & name () const
 
bool equal_to (const Variable &o) const noexcept
 
bool less (const Variable &o) const noexcept
 
void hash (InvocableHashAlgorithm auto &hasher) const noexcept
 

Static Private Member Functions

static Id get_next_id (Variable::Type type)
 

Private Attributes

Id id_
 Unique identifier for the variable. The high-order byte stores the Type.
 
std::shared_ptr< const std::string > name_
 Name of the variable.
 

Detailed Description

Represents a symbolic variable.

A symbolic variable is a named entity that can take a value from a specific domain.

Warning
Do not use the operator== to verify equality between to Variable, as it creates a Formula. Use the equal_to() method instead.

Member Enumeration Documentation

◆ Type

enum class smats::Variable::Type : std::uint8_t
strong

Supported types of symbolic variables.

Enumerator
CONTINUOUS 

A CONTINUOUS variable takes a double value.

INTEGER 

An INTEGER variable takes an int value.

BINARY 

A BINARY variable takes an integer value from {0, 1}.

BOOLEAN 

A BOOLEAN variable takes a bool value.

Constructor & Destructor Documentation

◆ Variable() [1/2]

smats::Variable::Variable ( )
inline

Construct a dummy variable.

All default-constructed variables are considered the same variable by the equal_to method. A moved-from variable becomes a dummy variable.

◆ Variable() [2/2]

smats::Variable::Variable ( const std::string & name,
Type type = Type::CONTINUOUS )
explicit

Constructs a variable with a string.

Parameters
namename of the variable.
typetype of the variable.

Member Function Documentation

◆ equal_to()

bool smats::Variable::equal_to ( const Variable & o) const
inlinenodiscardnoexcept

Compare two variables to determine if they are equal. Two variables are equal if they have the same id_ .

Parameters
oother object to compare against
Returns
true the two object are equal
false if the two objects are different

◆ get_next_id()

Variable::Id smats::Variable::get_next_id ( Variable::Type type)
staticprivate

Get the next unique identifier for a variable.

The unique identifier is a 64-bit value that is composed of two parts:

  • The first high-order byte stores the Type of the variable
  • The remaining low-order bytes store a counter that is incremented each time a new variable is created.
Note
Id 0 is reserved for anonymous variable which is created by the default constructor, Variable(). As a result, the invariant get_next_id() > 0 is guaranteed.
Parameters
typetype of the variable
Returns
next unique identifier for a variable

◆ hash()

void smats::Variable::hash ( InvocableHashAlgorithm auto & hasher) const
inlinenoexcept

Compute the hash of this variable using the given hasher

Template Parameters
InvocableHashAlgorithmtype of the hash algorithm to use
Parameters
hasherhash algorithm to use

◆ id()

Id smats::Variable::id ( ) const
inlinenodiscard

Get read-only access to the unique identifier of the variable.

Returns
unique identifier of the variable

◆ is_dummy()

bool smats::Variable::is_dummy ( ) const
inlinenodiscard
Check whether the  variable is a dummy variable.

A dummy variable is a variable with an ID of zero and represents an anonymous variable. It should not be used in any context other than as a placeholder.

Returns
true if the variable is a dummy variable
false if the variable is not a dummy variable

◆ less()

bool smats::Variable::less ( const Variable & o) const
inlinenodiscardnoexcept

Compare two variables to determine the order between them. The ordering is based on the id_ values of the two variables.

Parameters
oother object to compare against
Returns
true if this object is less than the other object
false if this object is not less than the other object

◆ name()

const std::string & smats::Variable::name ( ) const
nodiscard

Get read-only access to the name of the variable.

Returns
name of the variable

◆ type()

Type smats::Variable::type ( ) const
inlinenodiscard

Get read-only access to the type of the variable. The type is stored in the upper byte of id_ .

Returns
type of the variable
See also
get_next_id()

Member Data Documentation

◆ id_

Id smats::Variable::id_
private

Unique identifier for the variable. The high-order byte stores the Type.

See also
get_next_id()

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