Variables Module
Variables
class lib_satprob.variables.Variables(
from_file: str,
from_vars: List[Var]
)
from_file(Optional[str]) - a path to the file containing a JSON object with a list variables. This argument involves lazily creation by reading from the given file. Default:None.from_vars(List[Var]) - a list of variables that implement Var abstract class.
Important
To create a Variables instance specify only one initialization argument (from_file or from_vars).
Supplements
type lib_satprob.variables.Assumptions = List[int]
type lib_satprob.variables.Constraints = List[List[int]]
type lib_satprob.variables.Supplements = Tuple[Assumptions, Constraints]
Variables Methods
- dimension()
- This method returns a list of integers. Each integer represents the number of possible values that the corresponding variable can take. Essentially, this is a list of values Var.dim for each contained variable.Return type: List[int]
- power()
- This method returns a the number of all possible unique Supplements that can be obtained for a given list of variables. Essentially, this is the product of a list of numbers that the Variables.dimension() method returns.Returns type: int
- substitute(using_values, using_var_map)
- This method substitutes values into each contained variable using the Var.substitute(…) method, and returns the combined result of their calls.Input arguments:
using_values(Optional[List[int]]) - a list of numbers in range of0to Variables.dimension() for each contained variable.using_var_map(Optional[VarMap]) - a dictionary where each contained variable is associated with a number in range of0to Var.dim.
Important
To substitute values specify only one input argument (
using_valuesorusing_var_map).Return type: Supplements
- enumerate(offset, length, with_random_state)
- This method enumerates all possible unique Supplements for a given list of variables starting with Supplements obtained by substituting the values
{ 0 }^nand ending with the maximum values for the corresponding Variables.dimension() (for example{ 1 }^nif all variables are binary), wherenis equal to the length of there Variables.dimension().The method provides from Enumerable.enumerate(…) inherited class.Input arguments:offset(Optional[int]) - a count of leading Supplements that will be skipped. Default:0.length(Optional[int]) - a count of Supplements that will be returned. If equalsNonethen return all Supplements fromoffsetto end. Default:None.with_random_state(Optional[RandomState]) - a state that is used to shuffle order of returned Supplements. If equalsNonethen returns in usual order. Default:None.
Return type: List[Supplements]
>>> from lib_satprob.variables import Variables
>>> from lib_satprob.variables.vars import Index
>>> vars = [Index(i) for i in range(1, 5)]
>>> variables = Variables(from_vars=vars)
>>> print(variables)
[Index(1), Index(2), Index(3), Index(4)]
>>> from lib_satprob.variables import Variables
>>> from lib_satprob.variables.vars import Domain
>>> vars = [
>>> Domain('d1', [1, 2, 3, 4, 5]),
>>> Domain('d2', [6, 7, 8, 9, 10]),
>>> Domain('d3', [11, 12, 13, 14, 15]),
>>> Domain('d4', [16, 17, 18, 19, 20])
>>> ]
>>> variables = Variables(from_vars=vars)
>>> print(variables)
[Domain('d1'), Domain('d2'), Domain('d3'), Domain('d4')]
>>> from lib_satprob.variables import Variables
>>> from lib_satprob.variables.vars import Index, XorSwitch
>>> vars = [
>>> *(Index(i) for i in range(1, 4)),
>>> XorSwitch('x1', [4, 5]),
>>> Index(6),
>>> ]
>>> variables = Variables(from_vars=vars)
>>> print(variables)
[Index(1), Index(2), Index(3), XorSwitch('x1'), Index(6)]
Indexes
class lib_satprob.variables.Indexes(
from_string: str,
from_iterable: Iterable[int]
)
from_string(Optional[str]) - a string with space-separated indexes of the corresponding variables. Default:None.from_iterable(Optional[List[int]]) - a list of integer indexes of the corresponding variables. Default:None.
Important
To create an Indexes instance specify only one initialization argument (from_string or from_iterable). Creation via from_string argument also supports internal intervals, for example: '1 2 3..8 10'
>>> from lib_satprob.variables import Indexes
>>> variables = Indexes(from_string='1 3..5 8')
>>> print(variables)
[Index(1), Index(3), Index(4), Index(5), Index(8)]
>>> from lib_satprob.variables import Interval
>>> variables = Range(from_iterable=[1, 3, 4, 8])
>>> print(variables)
[Index(1), Index(3), Index(4), Index(8)]
Range
class lib_satprob.variables.Range(
start: int,
length: int
)
start(int) - a start variable index of the range.length(int) - a number of indices in the range.
>>> from lib_satprob.variables import Range
>>> variables = Range(start=1, length=4)
>>> print(variables)
[Index(1), Index(2), Index(3), Index(4)]