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
TypeError: Ambiguous overloads ... when using ConstraintCollectors.compose #85
Comments
This is caused by jpype-project/jpype#1016 , which is fixed in the latest version of JPype (which main uses, but not in the current latest release on PyPI). However, it probably still not work on |
Thanks for the quick reply!
My function looks like this now: def no_24h_marathon(constraint_factory):
def more_than_16h(earliest, latest):
return latest - earliest
def shift_start(assign):
return assign.shift.start.timestamp()
return (
constraint_factory.forEach(assignment_class)
.groupBy(
lambda a: a.person.name,
ConstraintCollectors.compose(
# https://stackoverflow.com/questions/70507127/optapy-having-problems-with-constraints-groupby-and-sum/70714798#70714798
ConstraintCollectors.min(
ToIntFunction @ shift_start
),
ConstraintCollectors.max(
ToIntFunction @ shift_start
),
more_than_16h,
),
)
.penalize(
"No 24h marathon",
HardSoftScore.ONE_HARD,
lambda _, c: c <= _DIFF_IN_SECONDS,
)
) |
My bad, I overlooked that I have to use I still haven't got it to work, as I can't really calculate anything with the The code now looks like this: _DIFF_IN_SECONDS = 16 * 60 * 60
def no_24h_marathon(constraint_factory):
def time_difference(earliest, latest):
return (latest - earliest).total_seconds()
return (
constraint_factory.forEach(assignment_class)
.groupBy(
lambda a: a.person.name,
ConstraintCollectors.compose(
# https://stackoverflow.com/questions/70507127/optapy-having-problems-with-constraints-groupby-and-sum/70714798#70714798
ConstraintCollectors.min(
Function @ (lambda assign: assign.shift.start.timestamp())
),
ConstraintCollectors.max(
Function @ (lambda assign: assign.shift.start.timestamp())
),
time_difference,
),
)
.penalize(
"No 24h marathon",
HardSoftScore.ONE_HARD,
lambda _, c: c <= _DIFF_IN_SECONDS,
)
) With this I get:
I've tried doing this too: def time_difference(earliest, latest):
return int(latest) - int(earliest) but get this error:
Sorry for bugging you like this and I am immensly grateful for your help! |
That should be fixed by 7c8c1b0, which is in the latest release (8.19.0a1). I recommend upgrading your optapy version. |
I did that and tried around a lot. I still get the It seems to work fine when using I have attached a minimal example of the error happening (GitHub does not allow adding When you change |
This is what I get running your code using
I was able to reproduce it by changing the group by lambda to:
The issue seems to be a typecheck that happens inside |
awesome, I now got it to work with converting the |
Look like the error was caused by this code: |
I am currently trying to optimize some shifts. As these shifts start every 8 hours I want to make sure that no person does more than 2 shifts in a row and has to work 24h at once.
My idea was to group all shift assignments by person and then use a composed collector to get the earliest and latest shift and then make sure these shifts do not fill the entire 24 hours (because another constraint is that every person gets exactly 3 shifts).
When I do this I get this
TypError
about overloads when trying to solve:Should I use a different approach? Any and every help would be greatly appreciated.
Thanks for this python wrapper, it helps a lot!
The text was updated successfully, but these errors were encountered: