-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve the new list variable logic (#1248)
For some reason, this commit was not merged together with ee760ca and I only discovered it now.
- Loading branch information
Showing
6 changed files
with
75 additions
and
108 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
...olver/core/impl/domain/variable/AbstractExternalizedNextPrevElementVariableProcessor.java
This file was deleted.
Oops, something went wrong.
This file contains 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
26 changes: 0 additions & 26 deletions
26
...i/timefold/solver/core/impl/domain/variable/ExternalizedNextElementVariableProcessor.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
...mefold/solver/core/impl/domain/variable/ExternalizedNextPrevElementVariableProcessor.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ai.timefold.solver.core.impl.domain.variable; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import ai.timefold.solver.core.impl.domain.variable.descriptor.ShadowVariableDescriptor; | ||
import ai.timefold.solver.core.impl.domain.variable.nextprev.NextElementShadowVariableDescriptor; | ||
import ai.timefold.solver.core.impl.domain.variable.nextprev.PreviousElementShadowVariableDescriptor; | ||
import ai.timefold.solver.core.impl.score.director.InnerScoreDirector; | ||
|
||
final class ExternalizedNextPrevElementVariableProcessor<Solution_> { | ||
|
||
public static <Solution_> ExternalizedNextPrevElementVariableProcessor<Solution_> | ||
ofPrevious(PreviousElementShadowVariableDescriptor<Solution_> shadowVariableDescriptor) { | ||
return new ExternalizedNextPrevElementVariableProcessor<>(shadowVariableDescriptor, -1); | ||
} | ||
|
||
public static <Solution_> ExternalizedNextPrevElementVariableProcessor<Solution_> | ||
ofNext(NextElementShadowVariableDescriptor<Solution_> shadowVariableDescriptor) { | ||
return new ExternalizedNextPrevElementVariableProcessor<>(shadowVariableDescriptor, 1); | ||
} | ||
|
||
private final ShadowVariableDescriptor<Solution_> shadowVariableDescriptor; | ||
private final int modifier; | ||
|
||
private ExternalizedNextPrevElementVariableProcessor(ShadowVariableDescriptor<Solution_> shadowVariableDescriptor, | ||
int modifier) { | ||
this.shadowVariableDescriptor = Objects.requireNonNull(shadowVariableDescriptor); | ||
this.modifier = modifier; | ||
} | ||
|
||
public void setElement(InnerScoreDirector<Solution_, ?> scoreDirector, List<Object> listVariable, Object element, | ||
int index) { | ||
var target = index + modifier; | ||
if (target < 0 || target >= listVariable.size()) { | ||
setValue(scoreDirector, element, null); | ||
} else { | ||
setValue(scoreDirector, element, listVariable.get(target)); | ||
} | ||
} | ||
|
||
private void setValue(InnerScoreDirector<Solution_, ?> scoreDirector, Object element, Object value) { | ||
if (getElement(element) != value) { | ||
scoreDirector.beforeVariableChanged(shadowVariableDescriptor, element); | ||
shadowVariableDescriptor.setValue(element, value); | ||
scoreDirector.afterVariableChanged(shadowVariableDescriptor, element); | ||
} | ||
} | ||
|
||
public Object getElement(Object element) { | ||
return shadowVariableDescriptor.getValue(element); | ||
} | ||
|
||
public void unsetElement(InnerScoreDirector<Solution_, ?> scoreDirector, Object element) { | ||
setValue(scoreDirector, element, null); | ||
} | ||
|
||
} |
27 changes: 0 additions & 27 deletions
27
...mefold/solver/core/impl/domain/variable/ExternalizedPreviousElementVariableProcessor.java
This file was deleted.
Oops, something went wrong.
This file contains 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