Skip to content

Commit f77d4e5

Browse files
committed
feat: sync ConstraintMatch and ConstraintRef API
1 parent d42ef22 commit f77d4e5

File tree

4 files changed

+20
-80
lines changed

4 files changed

+20
-80
lines changed

tests/test_solution_manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,16 @@ def test_score_manager_constraint_ref():
240240

241241
ignored_java_functions_per_class = {
242242
'Indictment': {'getJustification'}, # deprecated
243-
'ConstraintRef': {'of', 'packageName', 'constraintName'} # built-in constructor and properties with @dataclass
243+
'ConstraintRef': {'of', 'packageName', 'constraintName'}, # built-in constructor and properties with @dataclass
244+
'ConstraintMatch': {
245+
'getConstraintRef', # built-in constructor and properties with @dataclass
246+
'getConstraintPackage', # deprecated
247+
'getConstraintName', # deprecated
248+
'getConstraintId', # deprecated
249+
'getJustificationList', # deprecated
250+
'getJustification', # built-in constructor and properties with @dataclass
251+
'getScore', # built-in constructor and properties with @dataclass
252+
}
244253
}
245254

246255

@@ -250,6 +259,7 @@ def test_has_all_methods():
250259
(ScoreAnalysis, JavaScoreAnalysis),
251260
(ConstraintAnalysis, JavaConstraintAnalysis),
252261
(ScoreExplanation, JavaScoreExplanation),
262+
(ConstraintMatch, JavaConstraintMatch),
253263
(ConstraintRef, JavaConstraintRef),
254264
(Indictment, JavaIndictment)):
255265
type_name = python_type.__name__

timefold-solver-python-core/src/main/java/ai/timefold/solver/python/score/constraint/ConstraintRefPythonJavaTypeMapping.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

timefold-solver-python-core/src/main/python/_timefold_java_interop.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ def update_log_level() -> None:
9898
PythonLoggingToLogbackAdapter.setLevel(logger.getEffectiveLevel())
9999

100100

101-
def register_python_java_type_mappings():
101+
def register_score_python_java_type_mappings():
102102
global _scores_registered, _java_score_mapping_dict, _python_score_mapping_dict
103103
if _scores_registered:
104104
return
105105

106106
_scores_registered = True
107107

108-
# score types
109108
from .score._score import SimpleScore, HardSoftScore, HardMediumSoftScore, BendableScore
110109
from ai.timefold.solver.core.api.score.buildin.simplelong import SimpleLongScore as _SimpleScore
111110
from ai.timefold.solver.core.api.score.buildin.hardsoftlong import HardSoftLongScore as _HardSoftScore
@@ -138,20 +137,6 @@ def register_python_java_type_mappings():
138137
add_python_java_type_mapping(HardMediumSoftScorePythonJavaTypeMapping(HardMediumSoftScoreType))
139138
add_python_java_type_mapping(BendableScorePythonJavaTypeMapping(BendableScoreType))
140139

141-
# score analysis types
142-
from .score._score_analysis import ConstraintRef
143-
from ai.timefold.solver.core.api.score.constraint import ConstraintRef as _ConstraintRef
144-
145-
from ai.timefold.solver.python.score.constraint import ConstraintRefPythonJavaTypeMapping
146-
147-
_python_score_mapping_dict['ConstraintRef'] = ConstraintRef
148-
149-
_java_score_mapping_dict['ConstraintRef'] = _ConstraintRef
150-
151-
ConstraintRefType = translate_python_class_to_java_class(ConstraintRef)
152-
153-
add_python_java_type_mapping(ConstraintRefPythonJavaTypeMapping(ConstraintRefType))
154-
155140

156141
def forward_logging_events(event: 'PythonLoggingEvent') -> None:
157142
logger.log(event.level().getPythonLevelNumber(),
@@ -316,7 +301,7 @@ def _add_to_compilation_queue(python_class: type | PythonSupplier) -> None:
316301
def _process_compilation_queue() -> None:
317302
global _compilation_queue
318303

319-
register_python_java_type_mappings()
304+
register_score_python_java_type_mappings()
320305
while len(_compilation_queue) > 0:
321306
python_class = _compilation_queue.pop(0)
322307

@@ -339,7 +324,7 @@ def _generate_constraint_provider_class(original_function: Callable[['_Constrain
339324
wrapped_constraint_provider: Callable[['_ConstraintFactory'],
340325
list['_Constraint']]) -> JClass:
341326
ensure_init()
342-
register_python_java_type_mappings()
327+
register_score_python_java_type_mappings()
343328
from ai.timefold.solver.python import PythonWrapperGenerator # noqa
344329
from ai.timefold.solver.core.api.score.stream import ConstraintProvider
345330
class_identifier = _get_class_identifier_for_object(original_function)

timefold-solver-python-core/src/main/python/score/_score_analysis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def compose_constraint_id(solution_type_or_package: Union[type, str], constraint
9090
constraint_name=constraint_name).constraint_id
9191

9292
def _to_java(self):
93-
return _java_score_mapping_dict['ConstraintRef'].of(self.package_name, self.constraint_name)
93+
from ai.timefold.solver.core.api.score.constraint import ConstraintRef as JavaConstraintRef
94+
return JavaConstraintRef.of(self.package_name, self.constraint_name)
9495

9596

9697
def _safe_hash(obj: Any) -> int:
@@ -118,6 +119,10 @@ class ConstraintMatch(Generic[Score_]):
118119
def identification_string(self) -> str:
119120
return self.constraint_ref.constraint_id
120121

122+
@property
123+
def get_indicted_object_list(self):
124+
return self.indicted_objects
125+
121126
def __hash__(self) -> int:
122127
combined_hash = hash(self.constraint_ref)
123128
combined_hash ^= _safe_hash(self.justification)

0 commit comments

Comments
 (0)