Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 0441b9e

Browse files
committed
fix: address PR comments
1 parent 002566b commit 0441b9e

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ requires = [
33
"setuptools>=69.1.1",
44
"stubgenj>=0.2.5",
55
"JPype1>=1.5.0",
6-
"wheel",
7-
"multipledispatch>=1.0.0"
6+
"wheel"
87
]
98
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ def find_stub_files(stub_root: str):
145145
test_suite='tests',
146146
python_requires='>=3.10',
147147
install_requires=[
148-
'JPype1>=1.5.0',
149-
'multipledispatch>=1.0.0'
148+
'JPype1>=1.5.0'
150149
],
151150
cmdclass={'build_py': FetchDependencies},
152151
package_data={

tests/test_solution_manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ def assert_score_analysis(problem: Solution, score_analysis: ScoreAnalysis):
141141

142142

143143
def assert_score_analysis_summary(score_analysis: ScoreAnalysis):
144-
summary = score_analysis.summarize
144+
summary = score_analysis.summary
145145
assert "Explanation of score (3):" in summary
146146
assert "Constraint matches:" in summary
147147
assert "3: constraint (Maximize Value) has 3 matches:" in summary
148148
assert "1: justified with" in summary
149149

150150
match = score_analysis.constraint_analyses[0]
151-
match_summary = match.summarize
151+
match_summary = match.summary
152152
assert "Explanation of score (3):" in match_summary
153153
assert "Constraint matches:" in match_summary
154154
assert "3: constraint (Maximize Value) has 3 matches:" in match_summary
@@ -201,6 +201,10 @@ def test_score_manager_diff():
201201
diff = score_analysis.diff(second_score_analysis)
202202
assert diff.score.score == -1
203203

204+
diff_operation = score_analysis - second_score_analysis
205+
assert diff_operation.score.score == -1
206+
print(diff, diff_operation)
207+
204208
constraint_analyses = score_analysis.constraint_analyses
205209
assert len(constraint_analyses) == 1
206210

@@ -241,6 +245,8 @@ def test_score_manager_constraint_ref():
241245
ignored_java_functions_per_class = {
242246
'Indictment': {'getJustification'}, # deprecated
243247
'ConstraintRef': {'of', 'packageName', 'constraintName'}, # built-in constructor and properties with @dataclass
248+
'ConstraintAnalysis': {'summarize'}, # using summary instead
249+
'ScoreAnalysis': {'summarize'}, # using summary instead
244250
'ConstraintMatch': {
245251
'getConstraintRef', # built-in constructor and properties with @dataclass
246252
'getConstraintPackage', # deprecated

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
from .._timefold_java_interop import _java_score_mapping_dict
44
from _jpyinterpreter import unwrap_python_like_object, add_java_interface
55
from dataclasses import dataclass
6-
from multipledispatch import dispatch
76

8-
from typing import TypeVar, Generic, Union, TYPE_CHECKING, Any, cast, Optional, Type
7+
from typing import overload, TypeVar, Generic, Union, TYPE_CHECKING, Any, cast, Optional, Type
98

109
if TYPE_CHECKING:
1110
# These imports require a JVM to be running, so only import if type checking
@@ -120,7 +119,7 @@ def identification_string(self) -> str:
120119
return self.constraint_ref.constraint_id
121120

122121
@property
123-
def get_indicted_object_list(self):
122+
def indicted_object_list(self):
124123
return self.indicted_objects
125124

126125
def __hash__(self) -> int:
@@ -467,7 +466,7 @@ class ConstraintAnalysis(Generic[Score_]):
467466
but still non-zero constraint weight; non-empty if constraint has matches.
468467
This is a list to simplify access to individual elements,
469468
but it contains no duplicates just like `set` wouldn't.
470-
summarize : str
469+
summary : str
471470
Returns a diagnostic text
472471
that explains part of the score quality through the ConstraintAnalysis API.
473472
match_count : int
@@ -513,7 +512,7 @@ def score(self) -> Score_:
513512
return to_python_score(self._delegate.score())
514513

515514
@property
516-
def summarize(self) -> str:
515+
def summary(self) -> str:
517516
return self._delegate.summarize()
518517

519518

@@ -547,7 +546,7 @@ class ScoreAnalysis:
547546
constraint_analyses : list[ConstraintAnalysis]
548547
Individual ConstraintAnalysis instances that make up this ScoreAnalysis.
549548
550-
summarize : str
549+
summary : str
551550
Returns a diagnostic text that explains the solution through the `ConstraintAnalysis` API to identify which
552551
Constraints cause that score quality.
553552
The string is built fresh every time the method is called.
@@ -572,7 +571,10 @@ def __init__(self, delegate: '_JavaScoreAnalysis'):
572571
self._delegate = delegate
573572

574573
def __str__(self):
575-
return self.summarize
574+
return self.summary
575+
576+
def __sub__(self, other):
577+
return self.diff(other)
576578

577579
@property
578580
def score(self) -> 'Score':
@@ -595,41 +597,37 @@ def constraint_analyses(self) -> list[ConstraintAnalysis]:
595597
list['_JavaConstraintAnalysis[Score]'], self._delegate.constraintAnalyses())
596598
]
597599

598-
@dispatch(str, str)
600+
@overload
599601
def constraint_analysis(self, constraint_package: str, constraint_name: str) -> ConstraintAnalysis:
600-
"""
601-
Performs a lookup on `constraint_map`.
602-
603-
Parameters
604-
----------
605-
constraint_package : str
606-
constraint_name : str
602+
...
607603

608-
Returns
609-
-------
610-
ConstraintAnalysis
611-
None if no constraint matches of such constraint are present
612-
"""
613-
return ConstraintAnalysis(self._delegate.getConstraintAnalysis(constraint_package, constraint_name))
614-
615-
@dispatch(ConstraintRef)
604+
@overload
616605
def constraint_analysis(self, constraint_ref: 'ConstraintRef') -> ConstraintAnalysis:
606+
...
607+
608+
def constraint_analysis(self, *args) -> ConstraintAnalysis:
617609
"""
618610
Performs a lookup on `constraint_map`.
619611
620612
Parameters
621613
----------
614+
constraint_package : str
615+
constraint_name : str
622616
constraint_ref : ConstraintRef
623617
624618
Returns
625619
-------
626620
ConstraintAnalysis
627621
None if no constraint matches of such constraint are present
628622
"""
629-
return ConstraintAnalysis(self._delegate.getConstraintAnalysis(constraint_ref._to_java()))
623+
print(args)
624+
if len(args) == 1:
625+
return ConstraintAnalysis(self._delegate.getConstraintAnalysis(args[0]._to_java()))
626+
else:
627+
return ConstraintAnalysis(self._delegate.getConstraintAnalysis(args[0], args[1]))
630628

631629
@property
632-
def summarize(self) -> str:
630+
def summary(self) -> str:
633631
return self._delegate.summarize()
634632

635633
@property

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ deps =
1313
pytest-cov>=4.1.0
1414
coverage>=7.4.3
1515
JPype1>=1.5.0
16-
multipledispatch>=1.0.0
1716
commands =
1817
pytest --import-mode=importlib {posargs} tests
1918

0 commit comments

Comments
 (0)