-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
204 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
8 changes: 0 additions & 8 deletions
8
core/src/main/java/ai/timefold/solver/core/preview/api/move/MoveProvider.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
45 changes: 45 additions & 0 deletions
45
core/src/main/java/ai/timefold/solver/core/preview/api/move/provider/ChangeMoveProvider.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,45 @@ | ||
package ai.timefold.solver.core.preview.api.move.provider; | ||
|
||
import java.util.Objects; | ||
|
||
import ai.timefold.solver.core.impl.move.generic.ChangeMove; | ||
import ai.timefold.solver.core.preview.api.domain.metamodel.PlanningVariableMetaModel; | ||
import ai.timefold.solver.core.preview.api.move.MoveConstructor; | ||
import ai.timefold.solver.core.preview.api.move.stream.MoveProvider; | ||
import ai.timefold.solver.core.preview.api.move.stream.MoveStreams; | ||
|
||
public class ChangeMoveProvider<Solution_, Entity_, Value_> | ||
implements MoveProvider<Solution_> { | ||
|
||
private final PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel; | ||
|
||
public ChangeMoveProvider(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel) { | ||
this.variableMetaModel = Objects.requireNonNull(variableMetaModel); | ||
} | ||
|
||
@Override | ||
public MoveConstructor<Solution_> apply(MoveStreams<Solution_> solutionMoveStreams) { | ||
var valueStream = solutionMoveStreams.enumeratePossibleValues(variableMetaModel) | ||
.filter(this::acceptValue); | ||
if (variableMetaModel.allowsUnassigned()) { | ||
valueStream = valueStream.addNull(); | ||
} | ||
return solutionMoveStreams.pick(solutionMoveStreams.enumerateEntities(variableMetaModel.entity()) | ||
.filter(this::acceptEntity)) | ||
.pick(valueStream, this::acceptEntityValuePair) | ||
.asMove((solution, entity, value) -> new ChangeMove<>(variableMetaModel, entity, value)); | ||
} | ||
|
||
protected boolean acceptEntity(Entity_ entity) { | ||
return true; | ||
} | ||
|
||
protected boolean acceptValue(Value_ value) { | ||
return true; | ||
} | ||
|
||
protected boolean acceptEntityValuePair(Entity_ entity, Value_ value) { | ||
return true; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/ai/timefold/solver/core/preview/api/move/stream/CachedMoveUniStream.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,11 @@ | ||
package ai.timefold.solver.core.preview.api.move.stream; | ||
|
||
import java.util.function.Function; | ||
|
||
public interface CachedMoveUniStream<Solution_, A> { | ||
|
||
CachedMoveUniStream<Solution_, A> filter(Function<A, Boolean> filter); | ||
|
||
CachedMoveUniStream<Solution_, A> addNull(); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/ai/timefold/solver/core/preview/api/move/stream/JitMoveBiStream.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,11 @@ | ||
package ai.timefold.solver.core.preview.api.move.stream; | ||
|
||
import ai.timefold.solver.core.api.function.TriFunction; | ||
import ai.timefold.solver.core.preview.api.move.BiMoveConstructor; | ||
import ai.timefold.solver.core.preview.api.move.Move; | ||
|
||
public interface JitMoveBiStream<Solution_, A, B> extends JitMoveStream<Solution_> { | ||
|
||
BiMoveConstructor<Solution_, A, B> asMove(TriFunction<Solution_, A, B, Move<Solution_>> moveFactory); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/ai/timefold/solver/core/preview/api/move/stream/JitMoveStream.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,7 @@ | ||
package ai.timefold.solver.core.preview.api.move.stream; | ||
|
||
public interface JitMoveStream<Solution_> { | ||
|
||
MoveStreams<Solution_> getMoveFactory(); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
core/src/main/java/ai/timefold/solver/core/preview/api/move/stream/JitMoveUniStream.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,41 @@ | ||
package ai.timefold.solver.core.preview.api.move.stream; | ||
|
||
import java.util.function.BiPredicate; | ||
import java.util.function.Function; | ||
|
||
public interface JitMoveUniStream<Solution_, A> extends JitMoveStream<Solution_> { | ||
|
||
default <B> JitMoveBiStream<Solution_, A, B> pick(Class<B> clz) { | ||
return pick(getMoveFactory().enumerate(clz)); | ||
} | ||
|
||
default <B> JitMoveBiStream<Solution_, A, B> pick(Class<B> clz, BiPredicate<A, B> filter) { | ||
return pick(getMoveFactory().enumerate(clz), filter); | ||
} | ||
|
||
<B> JitMoveBiStream<Solution_, A, B> pick(CachedMoveUniStream<Solution_, B> cachedMoveUniStream); | ||
|
||
<B> JitMoveBiStream<Solution_, A, B> pick(CachedMoveUniStream<Solution_, B> cachedMoveUniStream, BiPredicate<A, B> filter); | ||
|
||
<B> JitMoveBiStream<Solution_, A, B> pick(Function<A, CachedMoveUniStream<Solution_, B>> cachedMoveUniStreamFunction); | ||
|
||
default JitMoveBiStream<Solution_, A, A> pickOther(Class<A> clz) { | ||
return pickOther(getMoveFactory().enumerate(clz)); | ||
} | ||
|
||
default JitMoveBiStream<Solution_, A, A> pickOther(Class<A> clz, BiPredicate<A, A> filter) { | ||
return pickOther(getMoveFactory().enumerate(clz), filter); | ||
} | ||
|
||
// TODO identity or equality? | ||
default JitMoveBiStream<Solution_, A, A> pickOther(CachedMoveUniStream<Solution_, A> cachedMoveUniStream) { | ||
return pick(cachedMoveUniStream, (a, b) -> !a.equals(b)); | ||
} | ||
|
||
// TODO identity or equality? | ||
default JitMoveBiStream<Solution_, A, A> pickOther(CachedMoveUniStream<Solution_, A> cachedMoveUniStream, | ||
BiPredicate<A, A> filter) { | ||
return pick(cachedMoveUniStream, filter); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
core/src/main/java/ai/timefold/solver/core/preview/api/move/stream/MoveProvider.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,16 @@ | ||
package ai.timefold.solver.core.preview.api.move.stream; | ||
|
||
import java.util.function.Function; | ||
|
||
import ai.timefold.solver.core.api.domain.solution.PlanningSolution; | ||
import ai.timefold.solver.core.preview.api.move.MoveConstructor; | ||
|
||
/** | ||
* Implement this to provide a definition for one move type. | ||
* | ||
* @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation | ||
*/ | ||
@FunctionalInterface | ||
public interface MoveProvider<Solution_> | ||
extends Function<MoveStreams<Solution_>, MoveConstructor<Solution_>> { | ||
} |
48 changes: 48 additions & 0 deletions
48
core/src/main/java/ai/timefold/solver/core/preview/api/move/stream/MoveStreams.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,48 @@ | ||
package ai.timefold.solver.core.preview.api.move.stream; | ||
|
||
import java.util.Collection; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
import ai.timefold.solver.core.impl.domain.solution.descriptor.DefaultPlanningVariableMetaModel; | ||
import ai.timefold.solver.core.preview.api.domain.metamodel.PlanningEntityMetaModel; | ||
import ai.timefold.solver.core.preview.api.domain.metamodel.PlanningVariableMetaModel; | ||
|
||
public interface MoveStreams<Solution_> { | ||
|
||
<A> CachedMoveUniStream<Solution_, A> enumerate(Class<A> clz); | ||
|
||
default <Entity_> CachedMoveUniStream<Solution_, Entity_> | ||
enumerateEntities(PlanningEntityMetaModel<Solution_, Entity_> entityMetaModel) { | ||
return enumerate(entityMetaModel.type()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
default <Entity_, A> CachedMoveUniStream<Solution_, A> | ||
enumeratePossibleValues(PlanningVariableMetaModel<Solution_, Entity_, A> variableMetaModel) { | ||
var variableDescriptor = | ||
((DefaultPlanningVariableMetaModel<Solution_, Entity_, A>) variableMetaModel).variableDescriptor(); | ||
var valueRangeDescriptor = variableDescriptor.getValueRangeDescriptor(); | ||
if (variableDescriptor.isValueRangeEntityIndependent()) { | ||
return enumerate(solution -> (Collection<A>) valueRangeDescriptor.extractValueRange(solution, null)); | ||
} else { | ||
return enumerateFromEntity(variableMetaModel.entity(), | ||
(solution, entity) -> (Collection<A>) valueRangeDescriptor.extractValueRange(solution, entity)); | ||
} | ||
} | ||
|
||
<A> CachedMoveUniStream<Solution_, A> enumerate(Function<Solution_, Collection<A>> collectionFunction); | ||
|
||
<Entity_, A> CachedMoveUniStream<Solution_, A> enumerateFromEntity( | ||
PlanningEntityMetaModel<Solution_, Entity_> entityMetaModel, | ||
BiFunction<Solution_, Entity_, Collection<A>> collectionFunction); | ||
|
||
<A> CachedMoveUniStream<Solution_, A> enumerate(Collection<A> collection); | ||
|
||
default <A> JitMoveUniStream<Solution_, A> pick(Class<A> clz) { | ||
return pick(enumerate(clz)); | ||
} | ||
|
||
<A> JitMoveUniStream<Solution_, A> pick(CachedMoveUniStream<Solution_, A> cachedMoveUniStream); | ||
|
||
} |