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

Can't use value ranges from python #1294

Open
luxaritas opened this issue Dec 24, 2024 · 3 comments
Open

Can't use value ranges from python #1294

luxaritas opened this issue Dec 24, 2024 · 3 comments
Labels
bug Something isn't working process/needs triage Requires initial assessment of validity, priority etc.

Comments

@luxaritas
Copy link

luxaritas commented Dec 24, 2024

Describe the bug
An error is encountered when attempting to annotate a ValueRangeProvider as a CountableValueRange

Expected behavior
No error is encountered

Actual behavior

java.lang.java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: The entityClass (class <domainobject>) has a @PlanningVariable annotated property (<property>) that refers to a @ValueRangeProvider annotated member (method $method$get_range on class <domainobject>) that does not return a Collection, an array or a ValueRange

To Reproduce
Attach the following to a planning entity and attempt to run the solver

val: Annotated[int, PlanningVariable(value_range_provider_refs=['val'])] = 0
def get_range(self) -> Annotated[CountableValueRange, ValueRangeProvider(id='val')]:
        return ValueRangeFactory.create_int_value_range(0, 10)

Environment

Timefold Solver Version or Git ref:
1.17.0

Output of java -version:

openjdk version "23" 2024-09-17
OpenJDK Runtime Environment (build 23)
OpenJDK 64-Bit Server VM (build 23, mixed mode, sharing)

Output of uname -a or ver:

Linux 6.6.63-1-MANJARO #1 SMP PREEMPT_DYNAMIC Sat Nov 23 02:15:34 UTC 2024 x86_64 GNU/Linux
@luxaritas luxaritas added bug Something isn't working process/needs triage Requires initial assessment of validity, priority etc. labels Dec 24, 2024
@triceo
Copy link
Contributor

triceo commented Dec 25, 2024

CountableValueRange is not meant to be used as an annotation. Instead, a value range provider may return instances of this type as a means of providing values, if a collection is not used. (Which is what you're doing.)

Value ranges should only be annotated with ValueRangeProvider - and if there is only one value range, it doesn't need to be annotated at all.

Please remove the annotation and let us know if the issue persists.

@luxaritas
Copy link
Author

I’m not using it as an annotation here - I’m using it as the return type. This matches how the docs say to specify the return type of a function using ValueRangeFactory. (Nb: Annotated[ValueRangeProvider] would mean that the return type of the function is ValueRangeProvider)

@triceo
Copy link
Contributor

triceo commented Dec 25, 2024

OK, thanks for clarifying. In that case, this is probably a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working process/needs triage Requires initial assessment of validity, priority etc.
Projects
None yet
Development

No branches or pull requests

2 participants