Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explain Score fails unexpectedly #182

Open
JRII972 opened this issue Jan 24, 2024 · 0 comments
Open

explain Score fails unexpectedly #182

JRII972 opened this issue Jan 24, 2024 · 0 comments

Comments

@JRII972
Copy link

JRII972 commented Jan 24, 2024

I manage to find a solution without a null value and without failure, but when I try to obtain the details of the score (to have the constraints not respected) it fails on a null value.

score_manager.explainScore(_unwrap_java_object(solution.getFinalBestSolution()))
org.optaplanner.jpyinterpreter.types.errors.AttributeErrorTraceback (most recent call last)
org.optaplanner.jpyinterpreter.types.errors.AttributeError: org.optaplanner.jpyinterpreter.types.errors.AttributeError: 'Timeslot' object has no attribute 'id'.

The above exception was the direct cause of the following exception:

java.lang.IllegalStateException           Traceback (most recent call last)
File DefaultScoreManager.java:40, in org.optaplanner.core.impl.score.DefaultScoreManager.explainScore()

java.lang.IllegalStateException: java.lang.IllegalStateException: Joiner (LESS_THAN) threw an exception matching left (Timeslot(id=1672758000.0, datetime=2023-01-03 16:00:00)) and right (None) objects.

The above exception was the direct cause of the following exception:

While solution.getFinalBestSolution() works without problem

@optapy.planning_entity
class Entity:
    def __init__(self, code, actual_value):
        self.code = code
        self.date = self.get_possible_date()[0]
        self.date_end = Timeslot( self.date._datetime + timedelta(hours=1))

   ...

    @optapy.planning_variable([Timeslot], value_range_provider_refs=['date_range'])
    def get_date(self): return self.date

    def set_date(self, date):  self.date = date

    def get_date_end(self):
        return Timeslot( self.date._datetime + timedelta(hours=1))

    def set_date_end(self, date_end): pass

   ...

@problem_fact
class Timeslot:
    _datetime:datetime
    def __init__(self, _datetime:datetime):
        self._datetime = _datetime

    @property
    def id(self) : return self._datetime.timestamp()

    ...

The only constraint :

constraint_factory.for_each_unique_pair(Entity,
                                                constraint.Joiners.overlapping(lambda entity: entity.date, lambda entity: entity.date_end))
        .penalize('Same value', optapy.score.SimpleScore.ONE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant