@@ -74,6 +74,16 @@ def is_feasible(self) -> bool:
74
74
def of (score : int ) -> 'SimpleScore' :
75
75
return SimpleScore (score , init_score = 0 )
76
76
77
+ @staticmethod
78
+ def parse (score_text : str ) -> 'SimpleScore' :
79
+ if 'init' in score_text :
80
+ init , score = score_text .split ('/' )
81
+ else :
82
+ init = '0init'
83
+ score = score_text
84
+
85
+ return SimpleScore (int (score ), init_score = int (init .rstrip ('init' )))
86
+
77
87
def _to_java_score (self ):
78
88
if self .init_score < 0 :
79
89
return _java_score_mapping_dict ['SimpleScore' ].ofUninitialized (self .init_score , self .score )
@@ -127,6 +137,17 @@ def is_feasible(self) -> bool:
127
137
def of (hard_score : int , soft_score : int ) -> 'HardSoftScore' :
128
138
return HardSoftScore (hard_score , soft_score , init_score = 0 )
129
139
140
+ @staticmethod
141
+ def parse (score_text : str ) -> 'HardSoftScore' :
142
+ if 'init' in score_text :
143
+ init , hard , soft = score_text .split ('/' )
144
+ else :
145
+ init = '0init'
146
+ hard , soft = score_text .split ('/' )
147
+
148
+ return HardSoftScore (int (hard .rstrip ('hard' )), int (soft .rstrip ('soft' )),
149
+ init_score = int (init .rstrip ('init' )))
150
+
130
151
def _to_java_score (self ):
131
152
if self .init_score < 0 :
132
153
return _java_score_mapping_dict ['HardSoftScore' ].ofUninitialized (self .init_score , self .hard_score , self .soft_score )
@@ -193,6 +214,17 @@ def is_feasible(self) -> bool:
193
214
def of (hard_score : int , medium_score : int , soft_score : int ) -> 'HardMediumSoftScore' :
194
215
return HardMediumSoftScore (hard_score , medium_score , soft_score , init_score = 0 )
195
216
217
+ @staticmethod
218
+ def parse (score_text : str ) -> 'HardMediumSoftScore' :
219
+ if 'init' in score_text :
220
+ init , hard , medium , soft = score_text .split ('/' )
221
+ else :
222
+ init = '0init'
223
+ hard , medium , soft = score_text .split ('/' )
224
+
225
+ return HardMediumSoftScore (int (hard .rstrip ('hard' )), int (medium .rstrip ('medium' )),
226
+ int (soft .rstrip ('soft' )), init_score = int (init .rstrip ('init' )))
227
+
196
228
def _to_java_score (self ):
197
229
if self .init_score < 0 :
198
230
return _java_score_mapping_dict ['HardMediumSoftScore' ].ofUninitialized (self .init_score , self .hard_score ,
@@ -239,6 +271,22 @@ def is_feasible(self) -> bool:
239
271
def of (hard_scores : tuple [int , ...], soft_scores : tuple [int , ...]) -> 'BendableScore' :
240
272
return BendableScore (hard_scores , soft_scores , init_score = 0 )
241
273
274
+ @staticmethod
275
+ def parse (score_text : str ) -> 'BendableScore' :
276
+ if 'init' in score_text :
277
+ init , hard_score_text , soft_score_text = score_text .split ('/[' )
278
+ else :
279
+ hard_score_text , soft_score_text = score_text .split ('/[' )
280
+ # Remove leading [ from hard score text,
281
+ # since there is no init score in the text
282
+ # (and thus the split will not consume it)
283
+ hard_score_text = hard_score_text [1 :]
284
+ init = '0init'
285
+
286
+ hard_scores = tuple ([int (score ) for score in hard_score_text [:hard_score_text .index (']' )].split ('/' )])
287
+ soft_scores = tuple ([int (score ) for score in soft_score_text [:soft_score_text .index (']' )].split ('/' )])
288
+ return BendableScore (hard_scores , soft_scores , init_score = int (init .rstrip ('init' )))
289
+
242
290
def _to_java_score (self ):
243
291
IntArrayCls = JArray (JInt )
244
292
hard_scores = IntArrayCls (self .hard_scores )
@@ -249,8 +297,10 @@ def _to_java_score(self):
249
297
return _java_score_mapping_dict ['BendableScore' ].of (hard_scores , soft_scores )
250
298
251
299
def __str__ (self ):
252
- return (f'{ list (self .hard_scores )} hard/{ list (self .soft_scores )} soft' if self .is_solution_initialized else
253
- f'{ self .init_score } init/{ list (self .hard_scores )} hard/{ list (self .soft_scores )} soft' )
300
+ hard_text = f'{ str (list (self .hard_scores )).replace (", " , "/" )} hard'
301
+ soft_text = f'{ str (list (self .soft_scores )).replace (", " , "/" )} soft'
302
+ return (f'{ hard_text } /{ soft_text } ' if self .is_solution_initialized else
303
+ f'{ self .init_score } init/{ hard_text } /{ soft_text } ' )
254
304
255
305
256
306
# Import score conversions here to register conversions (circular import)
0 commit comments