didppy.SetConst

class didppy.SetConst

Set constant.

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.

eval()

Returns the 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

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.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

Raises:

OverflowError – If element is int and negative.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[1, 2])
>>> const.difference(other).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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.discard(1).eval(state, model)
{0}
eval()

Returns the set.

Returns:

The set.

Return type:

set

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.eval()
{0, 1}
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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[1, 2])
>>> const.intersection(other).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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[2, 3])
>>> const.isdisjoint(other).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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[0, 1, 2])
>>> const.issubset(other).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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[0])
>>> cost.issuperset(other).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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> const.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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[1, 2])
>>> const.symmetric_difference(other).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()
>>> state = model.target_state
>>> obj = model.add_object_type(number=4)
>>> const = model.create_set_const(object_type=obj, value=[0, 1])
>>> other = model.create_set_const(object_type=obj, value=[1, 2])
>>> const.union(other).eval(state, model)
{0, 1, 2}