-
Notifications
You must be signed in to change notification settings - Fork 183
feat: add replaceValue... methods to MutableSolutionView #2180
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
Open
triceo
wants to merge
6
commits into
TimefoldAI:main
Choose a base branch
from
triceo:smarter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+394
−26
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e69d2f
perf: improve value move within a list
triceo e69ab2c
feat: introduce replace(...) operations to MutableSolutionView
triceo 938e393
review
triceo d6b65ac
review
triceo 5cf6682
review
triceo 632aee4
Update core/src/main/java/ai/timefold/solver/core/preview/api/move/Mu…
triceo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,31 @@ <Entity_, Value_> void changeVariable(PlanningVariableMetaModel<Solution_, Entit | |
| <Entity_, Value_> Value_ moveValueBetweenLists(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, | ||
| Entity_ sourceEntity, int sourceIndex, Entity_ destinationEntity, int destinationIndex); | ||
|
|
||
| /** | ||
| * Replaces a value from one entity's {@link PlanningListVariable planning list variable} with another. | ||
| * The value is removed from the replacementIndex, shifting all later values to the left. | ||
| * The value is then added at the sourceIndex, replacing the pre-existing value and unassigning it. | ||
| * This means that the replacement list will be one item shorter after the move. | ||
| * | ||
| * @param variableMetaModel Describes the variable to be changed. | ||
| * @param sourceEntity The entity in which the value will be replaced. | ||
| * @param sourceIndex The index in the source entity's list variable which contains the value to be replaced; | ||
| * Acceptable values range from zero to one less than list size. | ||
| * @param replacementEntity The entity from which the value will be taken. | ||
| * @param replacementIndex The index in the destination entity's list variable which contains the value to be moved; | ||
triceo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Acceptable values range from zero to one less than list size. | ||
| * All values at or after the index are shifted to the left. | ||
| * @return the value that was replaced | ||
| * @throws IndexOutOfBoundsException if either index is out of bounds | ||
| * @throws IllegalArgumentException if sourceEntity == replacementEntity; | ||
| * use {@link #replaceValueInList(PlanningListVariableMetaModel, Object, int, int)} instead. | ||
| * @see #moveValueBetweenLists(PlanningListVariableMetaModel, Object, int, Object, int) Similar operation that moves the | ||
| * value to the destination without removing the pre-existing value. | ||
| */ | ||
| <Entity_, Value_> Value_ replaceValueBetweenLists( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dislike the name |
||
| PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, | ||
| Entity_ replacementEntity, int replacementIndex); | ||
|
|
||
triceo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * As defined by {@link #moveValueBetweenLists(PlanningListVariableMetaModel, Object, int, Object, int)}, | ||
| * but using {@link PositionInList} to specify the source and destination positions. | ||
|
|
@@ -207,12 +232,39 @@ default <Entity_, Value_> Value_ moveValueBetweenLists( | |
| * @return the value that was moved | ||
| * @throws IndexOutOfBoundsException if either index is out of bounds | ||
| * @throws IllegalArgumentException if sourceIndex == destinationIndex | ||
triceo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @see #replaceValueInList(PlanningListVariableMetaModel, Object, int, int) Similar operation that replaces the value at | ||
| * the destination index instead. | ||
| * @see #shiftValue(PlanningListVariableMetaModel, Object, int, int) Equivalent operation using offset calculation instead | ||
| * of index arithmetics. | ||
| */ | ||
| <Entity_, Value_> Value_ moveValueInList(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, | ||
| Entity_ sourceEntity, int sourceIndex, int destinationIndex); | ||
triceo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Moves a value within one entity's {@link PlanningListVariable planning list variable}. | ||
| * Behaves as if the value is first put in the replacementIndex, | ||
| * and then removed from the sourceIndex, shifting all later values to the left | ||
triceo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * The value previously at the replacementIndex is unassigned. | ||
| * | ||
| * @param variableMetaModel Describes the variable to be changed. | ||
| * @param sourceEntity The entity whose variable value is to be moved. | ||
| * @param sourceIndex The index in the source entity's list variable which contains the value to be moved; | ||
| * Acceptable values range from zero to one less than list size. | ||
| * All values after the index are shifted to the left. | ||
| * @param replacementIndex The index in the source entity's list variable to which the value will be moved; | ||
| * Acceptable values range from zero to one less than list size. | ||
| * The value previously at this index is unassigned. | ||
| * @return the value that was replaced | ||
| * @throws IndexOutOfBoundsException if either index is out of bounds | ||
| * @throws IllegalArgumentException if sourceIndex == replacementIndex | ||
triceo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @see #moveValueInList(PlanningListVariableMetaModel, Object, int, int) Similar operation that moves the value to the | ||
| * destination index instead. | ||
| * @see #shiftValue(PlanningListVariableMetaModel, Object, int, int) Equivalent operation using offset calculation instead | ||
| * of index arithmetic. | ||
| */ | ||
| <Entity_, Value_> Value_ replaceValueInList(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, | ||
| Entity_ sourceEntity, int sourceIndex, int replacementIndex); | ||
|
|
||
| /** | ||
| * Moves a value within one entity's {@link PlanningListVariable planning list variable}, | ||
| * by the given offset. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.