didppy.SetTable

class didppy.SetTable

Table of set constants.

t[index] returns a set expression referring to an item where t is SetTable and index is a sequence of ElementExpr, ElementVar, ElementResourceVar, or int.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj1 = model.add_object_type(number=2)
>>> obj2 = model.add_object_type(number=4)
>>> var = model.add_element_var(object_type=obj1, target=0)
>>> table = model.add_set_table(
...     {(0, 0, 0, 0): [1, 2], (1, 1, 1, 1): [2, 1]},
...     default=[],
...     object_type=obj2
... )
>>> table[0, var, 0, 1].eval(model.target_state, model)
set()

Methods

intersection(indices)

Takes the intersection of set constants in a table over the set of indices.

symmetric_difference(indices)

Takes the symmetric difference of set constants in a table over the set of indices.

union(indices)

Takes the union of set constants in a table over the set of indices.

intersection(indices)

Takes the intersection of set constants in a table over the set of indices.

Parameters:

indices (tuple of int, ElementExpr, ElementVar, ElementResourceVar, SetExpr, SetVar, or SetConst) – Tuple of index sets.

Returns:

The intersection.

Return type:

SetExpr

Raises:

OverflowError – If a negative integer is in indices.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj1 = model.add_object_type(number=2)
>>> obj2 = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj1, target=[0, 1])
>>> table = model.add_set_table(
...     {(0, 0, 0, 0): [1, 2], (1, 1, 1, 1): [2, 1]},
...     default=[],
...     object_type=obj2
... )
>>> table.intersection((0, var, 0, 0)).eval(model.target_state, model)
set()
symmetric_difference(indices)

Takes the symmetric difference of set constants in a table over the set of indices.

Parameters:

indices (tuple of int, ElementExpr, ElementVar, ElementResourceVar, SetExpr, SetVar, or SetConst) – Tuple of index sets.

Returns:

The symmetric difference.

Return type:

SetExpr

Raises:

OverflowError – If a negative integer is in indices.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj1 = model.add_object_type(number=2)
>>> obj2 = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj1, target=[0, 1])
>>> table = model.add_set_table(
...     {(0, 0, 0, 0): [1, 2], (1, 1, 1, 1): [2, 1]},
...     default=[],
...     object_type=obj2
... )
>>> table.symmetric_difference((0, var, 0, 0)).eval(model.target_state, model)
{1, 2}
union(indices)

Takes the union of set constants in a table over the set of indices.

Parameters:

indices (tuple of int, ElementExpr, ElementVar, ElementResourceVar, SetExpr, SetVar, or SetConst) – Tuple of index sets.

Returns:

The union.

Return type:

SetExpr

Raises:

OverflowError – If a negative integer is in indices.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj1 = model.add_object_type(number=2)
>>> obj2 = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj1, target=[0, 1])
>>> table = model.add_set_table(
...     {(0, 0, 0, 0): [1, 2], (1, 1, 1, 1): [2, 1]},
...     default=[],
...     object_type=obj2
... )
>>> table.union((0, var, 0, 0)).eval(model.target_state, model)
{1, 2}