@@ -454,6 +454,20 @@ def concat(self, other):
454
454
else :
455
455
raise RuntimeError (f'Unhandled constraint stream type { type (other )} .' )
456
456
457
+ def complement (self , item_type : Type [A ]) -> 'UniConstraintStream[A]' :
458
+ """
459
+ Adds to the stream all instances of a given class which are not yet present in it.
460
+ These instances must be present in the solution,
461
+ which means the class needs to be either a planning entity or a problem fact.
462
+
463
+ Parameters
464
+ ----------
465
+ item_type : Type[A]
466
+ the type of the instances to add to the stream.
467
+ """
468
+ item_type = get_class (item_type )
469
+ return UniConstraintStream (self .delegate .complement (item_type ), self .package , self .a_type )
470
+
457
471
def penalize (self , constraint_weight : ScoreType , match_weigher : Callable [[A ], int ] = None ) -> \
458
472
'UniConstraintBuilder[A, ScoreType]' :
459
473
"""
@@ -1000,6 +1014,29 @@ def concat(self, other):
1000
1014
else :
1001
1015
raise RuntimeError (f'Unhandled constraint stream type { type (other )} .' )
1002
1016
1017
+ def complement (self , item_type : Type [A ], padding_function : Callable [[A ], B ] = None ) -> 'BiConstraintStream[A, B]' :
1018
+ """
1019
+ Adds to the stream all instances of a given class which are not yet present in it.
1020
+ These instances must be present in the solution,
1021
+ which means the class needs to be either a planning entity or a problem fact.
1022
+
1023
+ The instances will be read from the first element of the input tuple.
1024
+ When an output tuple needs to be created for the newly inserted instances,
1025
+ the first element will be the new instance.
1026
+ The rest of the tuple will be padded with the result of the padding function,
1027
+ applied on the new instance.
1028
+
1029
+ Parameters
1030
+ ----------
1031
+ item_type : Type[A]
1032
+ the type of the instances to add to the stream.
1033
+
1034
+ padding_function : Callable[[A], B]
1035
+ a function that computes the padding value for the new tuple.
1036
+ """
1037
+ item_type = get_class (item_type )
1038
+ return BiConstraintStream (self .delegate .complement (item_type , padding_function ), self .package , self .a_type , self .b_type )
1039
+
1003
1040
def penalize (self , constraint_weight : ScoreType , match_weigher : Callable [[A , B ], int ] = None ) -> \
1004
1041
'BiConstraintBuilder[A, B, ScoreType]' :
1005
1042
"""
@@ -1544,6 +1581,34 @@ def concat(self, other):
1544
1581
else :
1545
1582
raise RuntimeError (f'Unhandled constraint stream type { type (other )} .' )
1546
1583
1584
+ def complement (self , item_type : Type [A ], padding_function_b : Callable [[A ], B ] = None ,
1585
+ padding_function_c : Callable [[A ], C ] = None ) -> 'TriConstraintStream[A, B, C]' :
1586
+ """
1587
+ Adds to the stream all instances of a given class which are not yet present in it.
1588
+ These instances must be present in the solution,
1589
+ which means the class needs to be either a planning entity or a problem fact.
1590
+
1591
+ The instances will be read from the first element of the input tuple.
1592
+ When an output tuple needs to be created for the newly inserted instances,
1593
+ the first element will be the new instance.
1594
+ The rest of the tuple will be padded with the result of the padding function,
1595
+ applied on the new instance.
1596
+
1597
+ Parameters
1598
+ ----------
1599
+ item_type : Type[A]
1600
+ the type of the instances to add to the stream.
1601
+
1602
+ padding_function_b : Callable[[A], B]
1603
+ a function that computes the padding value for the second fact in the new tuple.
1604
+
1605
+ padding_function_c : Callable[[A], C]
1606
+ a function that computes the padding value for the third fact in the new tuple.
1607
+ """
1608
+ item_type = get_class (item_type )
1609
+ return TriConstraintStream (self .delegate .complement (item_type , padding_function_b , padding_function_c ),
1610
+ self .package , self .a_type , self .b_type , self .c_type )
1611
+
1547
1612
def penalize (self , constraint_weight : ScoreType ,
1548
1613
match_weigher : Callable [[A , B , C ], int ] = None ) -> 'TriConstraintBuilder[A, B, C, ScoreType]' :
1549
1614
"""
@@ -2083,6 +2148,39 @@ def concat(self, other):
2083
2148
else :
2084
2149
raise RuntimeError (f'Unhandled constraint stream type { type (other )} .' )
2085
2150
2151
+ def complement (self , item_type : Type [A ], padding_function_b : Callable [[A ], B ] = None ,
2152
+ padding_function_c : Callable [[A ], C ] = None ,
2153
+ padding_function_d : Callable [[A ], D ] = None ) -> 'QuadConstraintStream[A, B, C, D]' :
2154
+ """
2155
+ Adds to the stream all instances of a given class which are not yet present in it.
2156
+ These instances must be present in the solution,
2157
+ which means the class needs to be either a planning entity or a problem fact.
2158
+
2159
+ The instances will be read from the first element of the input tuple.
2160
+ When an output tuple needs to be created for the newly inserted instances,
2161
+ the first element will be the new instance.
2162
+ The rest of the tuple will be padded with the result of the padding function,
2163
+ applied on the new instance.
2164
+
2165
+ Parameters
2166
+ ----------
2167
+ item_type : Type[A]
2168
+ the type of the instances to add to the stream.
2169
+
2170
+ padding_function_b : Callable[[A], B]
2171
+ a function that computes the padding value for the second fact in the new tuple.
2172
+
2173
+ padding_function_c : Callable[[A], C]
2174
+ a function that computes the padding value for the third fact in the new tuple.
2175
+
2176
+ padding_function_d : Callable[[A], D]
2177
+ a function that computes the padding value for the fourth fact in the new tuple.
2178
+ """
2179
+ item_type = get_class (item_type )
2180
+ return QuadConstraintStream (
2181
+ self .delegate .complement (item_type , padding_function_b , padding_function_c , padding_function_d ),
2182
+ self .package , self .a_type , self .b_type , self .c_type , self .d_type )
2183
+
2086
2184
def penalize (self , constraint_weight : ScoreType ,
2087
2185
match_weigher : Callable [[A , B , C , D ], int ] = None ) -> 'QuadConstraintBuilder[A, B, C, D, ScoreType]' :
2088
2186
"""
0 commit comments