didppy.SetVar

class didppy.SetVar

Set variable.

If an operator (-, &, ^, |) with a SetExpr, SetVar, or SetConst is applied, a new SetExpr is returned.

If a comparison operator (<, <=, ==, !=, >, >=) with a SetExpr, SetVar, or SetConst is applied, a Condition is returned.

Note that didppy.max() and didppy.min() should be used instead of max() and min() as comparison operators are overloaded.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[1, 2])
>>> state = model.target_state
>>> state[var]
{0, 1}
>>> (var - const).eval(state, model)
{0}
>>> (var & const).eval(state, model)
{1}
>>> (var ^ const).eval(state, model)
{0, 2}
>>> (var | const).eval(state, model)
{0, 1, 2}
>>> (var < const).eval(state, model)
False
>>> (var <= const).eval(state, model)
False
>>> (var == const).eval(state, model)
False
>>> (var != const).eval(state, model)
True
>>> (var > const).eval(state, model)
False
>>> (var >= const).eval(state, model)
False

Methods

add(element)

Adds an element to a set.

complement()

Returns the complement set.

contains(element)

Returns a condition checking if an element is included.

difference(other)

Returns a set where all elements in an input set are removed.

discard(element)

Removes an element from a set.

intersection(other)

Returns the intersection with another set.

is_empty()

Returns a condition checking if the set is empty.

isdisjoint(other)

Checks if two sets are disjoint.

issubset(other)

Checks if this set is a subset of another set.

issuperset(other)

Checks if this set is a superset of another set.

len()

Returns the cardinality of a set.

remove(element)

Removes an element from a set.

symmetric_difference(other)

Returns a set which only contains elements included in either of two sets but not in both.

union(other)

Returns the union of two sets.

add(element)

Adds an element to a set.

This method does not change the instance itself.

Parameters:

element (ElementExpr, ElementVar, ElementResourceVar, or int) – Element added to the set.

Returns:

The set where the element is added.

Return type:

SetExpr

Raises:

OverflowError – If element is int and negative.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.add(2).eval(state, model)
{0, 1, 2}
complement()

Returns the complement set.

Returns:

The complement set.

Return type:

SetExpr

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.complement().eval(state, model)
{2, 3}
contains(element)

Returns a condition checking if an element is included.

Parameters:

element (ElementExpr, ElementVar, ElementResourceVar, or int) – Element to check.

Returns:

The condition checking if an element is included in the set.

Return type:

Condition

Raises:

OverflowError – If element is int and negative.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.contains(0).eval(state, model)
True
difference(other)

Returns a set where all elements in an input set are removed.

This method is the same as - operation. This method does not change the instance itself.

Parameters:

other (SetExpr, SetVar, or SetConst) – Set to remove.

Returns:

The set where all elements in other are removed.

Return type:

SetExpr

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[1, 2])
>>> state = model.target_state
>>> var.difference(const).eval(state, model)
{0}
discard(element)

Removes an element from a set.

This method does not change the instance itself.

Parameters:

element (ElementExpr, ElementVar, ElementResourceVar, or int) – Element removed from the set.

Returns:

The set where the element is removed.

Return type:

SetExpr

Raises:

OverflowError – If element is int and negative.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.discard(1).eval(state, model)
{0}
intersection(other)

Returns the intersection with another set.

This method is the same as & operation. This method does not change the instance itself.

Parameters:

other (SetExpr, SetVar, or SetConst) – Set to take the intersection with.

Returns:

The intersection.

Return type:

SetExpr

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[1, 2])
>>> state = model.target_state
>>> var.intersection(const).eval(state, model)
{1}
is_empty()

Returns a condition checking if the set is empty.

Returns:

The condition checking if the set is empty.

Return type:

Condition

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.is_empty().eval(state, model)
False
isdisjoint(other)

Checks if two sets are disjoint.

Parameters:

other (SetExpr, SetVar, or SetConst) – The other set.

Returns:

The condition that the two sets are disjoint.

Return type:

Condition

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[2, 3])
>>> state = model.target_state
>>> var.isdisjoint(const).eval(state, model)
True
issubset(other)

Checks if this set is a subset of another set.

Parameters:

other (SetExpr, SetVar, or SetConst) – The other set.

Returns:

The condition that the two sets are disjoint.

Return type:

Condition

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[0, 1, 2])
>>> state = model.target_state
>>> var.issubset(const).eval(state, model)
True
issuperset(other)

Checks if this set is a superset of another set.

Parameters:

other (SetExpr, SetVar, or SetConst) – The other set.

Returns:

The condition that the two sets are disjoint.

Return type:

Condition

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[0])
>>> state = model.target_state
>>> expr.issuperset(const).eval(state, model)
True
len()

Returns the cardinality of a set.

Returns:

The cardinality.

Return type:

IntExpr

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.len().eval(state, model)
2
remove(element)

Removes an element from a set.

This method does not change the instance itself.

Parameters:

element (ElementExpr, ElementVar, ElementResourceVar, or int) – Element removed from the set.

Returns:

The set where the element is removed.

Return type:

SetExpr

Raises:

OverflowError – If element is int and negative.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> state = model.target_state
>>> var.remove(1).eval(state, model)
{0}
symmetric_difference(other)

Returns a set which only contains elements included in either of two sets but not in both.

This method is the same as ^ operation. This method does not change the instance itself.

Parameters:

other (SetExpr, SetVar, or SetConst) – Set to take the symmetric difference with.

Returns:

The symmetric difference set.

Return type:

SetExpr

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[1, 2])
>>> state = model.target_state
>>> var.symmetric_difference(const).eval(state, model)
{0, 2}
union(other)

Returns the union of two sets.

This method is the same as | operation. This method does not change the instance itself.

Parameters:

other (SetExpr, SetVar, or SetConst) – Set to take the union with.

Returns:

The union.

Return type:

SetExpr

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_set_var(object_type=obj, target=[0, 1])
>>> const = model.create_set_const(object_type=obj, value=[1, 2])
>>> state = model.target_state
>>> var.union(const).eval(state, model)
{0, 1, 2}