-
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.
- Loading branch information
Showing
7 changed files
with
123 additions
and
22 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
49 changes: 49 additions & 0 deletions
49
core/src/main/java/ai/timefold/solver/core/impl/move/dataset/DatasetInstance.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,49 @@ | ||
package ai.timefold.solver.core.impl.move.dataset; | ||
|
||
import java.util.Iterator; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
|
||
import ai.timefold.solver.core.impl.bavet.common.tuple.AbstractTuple; | ||
import ai.timefold.solver.core.impl.bavet.common.tuple.TupleLifecycle; | ||
import ai.timefold.solver.core.impl.util.ElementAwareList; | ||
import ai.timefold.solver.core.impl.util.ElementAwareListEntry; | ||
|
||
public final class DatasetInstance<Solution_, Tuple_ extends AbstractTuple> | ||
implements TupleLifecycle<Tuple_> { | ||
|
||
private final Dataset<Solution_, Tuple_> parent; | ||
private final int inputStoreIndex; | ||
private final ElementAwareList<Tuple_> tupleList = new ElementAwareList<>(); | ||
|
||
public DatasetInstance(Dataset<Solution_, Tuple_> parent, int inputStoreIndex) { | ||
this.parent = Objects.requireNonNull(parent); | ||
this.inputStoreIndex = inputStoreIndex; | ||
} | ||
|
||
@Override | ||
public void insert(Tuple_ tuple) { | ||
var entry = tupleList.add(tuple); | ||
tuple.setStore(inputStoreIndex, entry); | ||
} | ||
|
||
@Override | ||
public void update(Tuple_ tuple) { | ||
// No need to do anything. | ||
} | ||
|
||
@Override | ||
public void retract(Tuple_ tuple) { | ||
ElementAwareListEntry<Tuple_> entry = tuple.removeStore(inputStoreIndex); | ||
entry.remove(); | ||
} | ||
|
||
public Iterator<Tuple_> iterator() { | ||
return tupleList.iterator(); | ||
} | ||
|
||
public Iterator<Tuple_> iterator(Random workingRandom) { | ||
return tupleList.randomizedIterator(workingRandom); | ||
} | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
core/src/main/java/ai/timefold/solver/core/impl/move/dataset/TerminalUniDataStream.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,47 @@ | ||
package ai.timefold.solver.core.impl.move.dataset; | ||
|
||
import java.util.Objects; | ||
|
||
import ai.timefold.solver.core.impl.bavet.common.tuple.UniTuple; | ||
import ai.timefold.solver.core.impl.move.dataset.common.DataNodeBuildHelper; | ||
|
||
final class TerminalUniDataStream<Solution_, A> | ||
extends AbstractUniDataStream<Solution_, A> { | ||
|
||
private final Dataset<Solution_, UniTuple<A>> dataset; | ||
|
||
public TerminalUniDataStream(DefaultDatasetFactory<Solution_> datasetFactory, AbstractUniDataStream<Solution_, A> parent) { | ||
super(datasetFactory, parent); | ||
this.dataset = new Dataset<>(datasetFactory, this); | ||
} | ||
|
||
@Override | ||
public void buildNode(DataNodeBuildHelper<Solution_> buildHelper) { | ||
assertEmptyChildStreamList(); | ||
var inputStoreIndex = buildHelper.reserveTupleStoreIndex(this); | ||
buildHelper.putInsertUpdateRetract(this, dataset.instantiate(inputStoreIndex)); | ||
} | ||
|
||
public Dataset<Solution_, UniTuple<A>> getDataset() { | ||
return dataset; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object entity) { | ||
if (!(entity instanceof TerminalUniDataStream<?, ?> that)) { | ||
return false; | ||
} | ||
return Objects.equals(dataset, that.dataset); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(dataset); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Terminal node"; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -2,6 +2,4 @@ | |
|
||
public interface DataStream<Solution_> { | ||
|
||
Dataset<Solution_, Object> createDataset(); | ||
|
||
} |
4 changes: 0 additions & 4 deletions
4
core/src/main/java/ai/timefold/solver/core/preview/api/move/Dataset.java
This file was deleted.
Oops, something went wrong.