Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo committed Dec 3, 2024
1 parent 232b5c0 commit c687e3f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import ai.timefold.solver.core.api.score.stream.bi.BiJoiner;
import ai.timefold.solver.core.impl.bavet.common.index.joiner.BiJoinerComber;
import ai.timefold.solver.core.impl.bavet.common.tuple.UniTuple;
import ai.timefold.solver.core.impl.move.dataset.common.bridge.ForeBridgeUniDataStream;
import ai.timefold.solver.core.preview.api.move.Dataset;
import ai.timefold.solver.core.preview.api.move.UniDataStream;

import org.jspecify.annotations.NonNull;
Expand Down Expand Up @@ -77,9 +77,9 @@ private <B> UniDataStream<Solution_, A> ifExistsOrNot(boolean shouldExist, UniDa
joinerComber.getMergedJoiner(), joinerComber.getMergedFiltering()), childStreamList::add);
}

@Override
public Dataset<Solution_, Object> createDataset() {
return null;
public Dataset<Solution_, UniTuple<A>> createDataset() {
var stream = shareAndAddChild(new TerminalUniDataStream<>(datasetFactory, this));
return stream.getDataset();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@
import java.util.Objects;
import java.util.Set;

import ai.timefold.solver.core.impl.score.stream.bavet.common.BavetScoringConstraintStream;
import ai.timefold.solver.core.impl.bavet.common.tuple.AbstractTuple;

public final class Dataset<Solution_> {
public final class Dataset<Solution_, Tuple_ extends AbstractTuple> {

private final DefaultDatasetFactory<Solution_> defaultDatasetFactory;
private final BavetScoringConstraintStream<Solution_> scoringConstraintStream;
private final AbstractDataStream<Solution_> parent;

public Dataset(DefaultDatasetFactory<Solution_> defaultDatasetFactory,
BavetScoringConstraintStream<Solution_> scoringConstraintStream) {
AbstractDataStream<Solution_> parent) {
this.defaultDatasetFactory = Objects.requireNonNull(defaultDatasetFactory);
this.scoringConstraintStream = Objects.requireNonNull(scoringConstraintStream);
this.parent = Objects.requireNonNull(parent);
}

public void collectActiveDataStreams(Set<AbstractDataStream<Solution_>> dataStreamSet) {
// scoringConstraintStream.collectActiveDataStreams(dataStreamSet);
parent.collectActiveDataStreams(dataStreamSet);
}

public DatasetInstance<Solution_, Tuple_> instantiate(int inputStoreIndex) {
return new DatasetInstance<>(this, inputStoreIndex);
}

@Override
public boolean equals(Object entity) {
if (!(entity instanceof Dataset<?, ?> dataset)) {
return false;
}
return Objects.equals(defaultDatasetFactory, dataset.defaultDatasetFactory) && Objects.equals(parent, dataset.parent);
}

@Override
public int hashCode() {
return Objects.hash(defaultDatasetFactory, parent);
}
}
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

public final class DatasetSessionFactory<Solution_> {

// ************************************************************************
// Node creation
// ************************************************************************

@SuppressWarnings("unchecked")
public DatasetSession buildSession(Solution_ workingSolution) {
public DatasetSession<Solution_> buildSession(Solution_ workingSolution) {
return null;
}
}
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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

public interface DataStream<Solution_> {

Dataset<Solution_, Object> createDataset();

}

This file was deleted.

0 comments on commit c687e3f

Please sign in to comment.