didppy.SetResourceVar
- class didppy.SetResourceVar
Set resource variable.
If an operator (
-,&,^,|) with aSetExpr,SetVar, orSetConstis applied, a newSetExpris returned.If a comparison operator (
<,<=,==,!=,>,>=) with aSetExpr,SetVar, orSetConstis applied, aConditionis returned.Note that
didppy.max()anddidppy.min()should be used instead ofmax()andmin()as comparison operators are overloaded.Examples
>>> import didppy as dp >>> model = dp.Model() >>> obj = model.add_object_type(number=4) >>> var = model.add_set_resource_var(object_type=obj, target=[0, 1], less_is_better=False) >>> 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.
all(x, f)Returns whether the condition holds for all elements in the set.
any(x, f)Returns whether the condition holds for any element in the set.
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.
filter(x, f)Returns a filtered 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.
max(x, f)Returns the maximum of function evaluation results over a set.
min(x, f)Returns the minimum of function evaluation results over a set.
product(x, f)Returns the product of function evaluation results over a set.
remove(element)Removes an element from a set.
sum(x, f)Returns the sum of function evaluation results over 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:
- Raises:
OverflowError – If
elementisintand 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}
- all(x, f)
Returns whether the condition holds for all elements in the set.
- any(x, f)
Returns whether the condition holds for any element in the set.
- complement()
Returns the complement set.
- Returns:
The complement set.
- Return type:
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:
- Raises:
OverflowError – If
elementisintand 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:
- Returns:
The set where all elements in
otherare removed.- Return type:
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:
- Raises:
OverflowError – If
elementisintand 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}
- filter(x, f)
Returns a filtered set.
- Parameters:
x (LocalVar) – Local variable to use for iterator over the set.
f (Condition) – Condition to filter the set.
- Returns:
The filtered set.
- Return type:
Examples
>>> import didppy as dp >>> model = dp.Model() >>> obj = model.add_object_type(number=4) >>> var = model.add_set_resource_var(object_type=obj, target=[0, 1, 2, 3], less_is_better=False) >>> state = model.target_state >>> x = model.add_local_var() >>> var.filter(x, x > 1).eval(state, model) {2, 3}
- 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:
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:
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:
- Returns:
The condition that the two sets are disjoint.
- Return type:
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:
- Returns:
The condition that the two sets are disjoint.
- Return type:
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:
- Returns:
The condition that the two sets are disjoint.
- Return type:
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:
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
- max(x, f)
Returns the maximum of function evaluation results over a set.
- Parameters:
- Returns:
The maximum of function evaluation results over the set.
- Return type:
Examples
>>> import didppy as dp >>> model = dp.Model() >>> obj = model.add_object_type(number=4) >>> var = model.add_set_resource_var(object_type=obj, target=[0, 1], less_is_better=False) >>> state = model.target_state >>> table = model.add_int_table([2, 3]) >>> x = model.add_local_var() >>> var.max(x, table[x] * table[x]).eval(state, model) 9
- min(x, f)
Returns the minimum of function evaluation results over a set.
- Parameters:
- Returns:
The minimum of function evaluation results over the set.
- Return type:
Examples
>>> import didppy as dp >>> model = dp.Model() >>> obj = model.add_object_type(number=4) >>> var = model.add_set_resource_var(object_type=obj, target=[0, 1], less_is_better=False) >>> state = model.target_state >>> table = model.add_int_table([2, 3]) >>> x = model.add_local_var() >>> var.min(x, table[x] * table[x]).eval(state, model) 4
- product(x, f)
Returns the product of function evaluation results over a set.
- Parameters:
- Returns:
The product of function evaluation results over the set.
- Return type:
Examples
>>> import didppy as dp >>> model = dp.Model() >>> obj = model.add_object_type(number=4) >>> var = model.add_set_resource_var(object_type=obj, target=[0, 1], less_is_better=False) >>> state = model.target_state >>> table = model.add_int_table([2, 3]) >>> x = model.add_local_var() >>> var.product(x, table[x] * table[x]).eval(state, model) 36
- 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:
- Raises:
OverflowError – If
elementisintand 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}
- sum(x, f)
Returns the sum of function evaluation results over a set.
- Parameters:
- Returns:
The sum of function evaluation results over the set.
- Return type:
Examples
>>> import didppy as dp >>> model = dp.Model() >>> obj = model.add_object_type(number=4) >>> var = model.add_set_resource_var(object_type=obj, target=[0, 1], less_is_better=False) >>> state = model.target_state >>> table = model.add_int_table([2, 3]) >>> x = model.add_local_var() >>> var.sum(x, table[x] * table[x]).eval(state, model) 13
- 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:
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:
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}