Skip to content

feat: maximum function over connected ranges#2137

Open
plentydone wants to merge 1 commit intoTimefoldAI:mainfrom
plentydone:max-function-connected-ranges
Open

feat: maximum function over connected ranges#2137
plentydone wants to merge 1 commit intoTimefoldAI:mainfrom
plentydone:max-function-connected-ranges

Conversation

@plentydone
Copy link

Let me know what you think about the concept of this feature and it's implementation. I brought it up in Discord some weeks back. Naming things is hard.

The (very minimal) doc example is more or less my use case, calculating equipment usage at all times based on a job attribute, compared to an equipment capacity value that is lessened based on the quantity of jobs. Sort of an enhanced version of maximum overlap.

In implementing it I was starting to feel like a grouping joiner that yields tuples for distinct overlapping ranges of values (possibly with an optional filter function?) would be a more flexible and maintainable interface, but I wanted to send something along to see if you have any early opinions. It feels like a lot of use cases would be answered by a tuple of (Collection of Range_ simultaneously overlapping), (start Point_ of overlapping range), (end Point_ of overlapping range)

Happy to refactor any of the interface, implementation, tests, docs, etc according to your input.

(activeJobList, duration) -> {
var required = activeJobList.stream().mapToInt(Job::getCapacityRequired).sum()
var capacity = equipment.getCapacity() - (activeJobList.size() - 1); // Lose a little capacity per additional job
return Math.max(0, capacity - required);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do something like multiplying by the duration here to get a scaled penalty

@triceo
Copy link
Collaborator

triceo commented Feb 23, 2026

Hello @plentydone, and thanks for the PR!

After a first quick read, I have 2 comments:

  • Why should there be a function to do max specifically? max is just one type of a reduction function, others could be min, avg, ... IMO this feature should be generified to allow for any reduction function, similarly to map+reduce in Java streams. The ConstraintCollector already has all you need for that; I'm just not sure we should use that interface here directly.
  • I am a bit worried that this code is designed to not be incremental. In the world of optimization, iterating over collections kills performance. You could argue that these collections will be short, and therefore not a problem, and you may be right. But it gives people ideas that processing collections in CS is good or acceptable, and I'm not sure how I feel about that. At the same time, making this incremental probably takes the complexity of this issue to another level entirely.

@plentydone
Copy link
Author

@triceo love the feedback, agreed with all points. This spun off a discussion where @Christopher-Chianelli mentioned that he saw value in the max feature, so I figured I would prompt some ideas with an MR.

Do you think the feature should be in line with my comment a (new) grouping joiner that yields tuples for distinct overlapping ranges of values (possibly with an optional filter function?) ? I agree that makes the feature relatively large, but I'm happy to go back to the drawing board and take a swing at it at least as a thought experiment. (That would also allow me to pull it into my own project more easily without maintaining a build.)

@triceo
Copy link
Collaborator

triceo commented Feb 23, 2026

Do you think the feature should be in line with my comment a (new) grouping joiner that yields tuples for distinct overlapping ranges of values (possibly with an optional filter function?)

TBH I cannot really imagine right now how that would look. Do you have an API strawman you wanna paste here in chat?

FYI we are already working on joiners which allow for overlap of different collections.

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

Successfully merging this pull request may close these issues.

2 participants