org.optaplanner.constraint.streams.bavet.uni.BavetBiGroupBridgeUniConstraintStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of optaplanner-constraint-streams-bavet Show documentation
Show all versions of optaplanner-constraint-streams-bavet Show documentation
OptaPlanner solves planning problems.
This lightweight, embeddable planning engine implements powerful and scalable algorithms
to optimize business resource scheduling and planning.
This module contains implementation of Constraint streams (Bavet).
package org.optaplanner.constraint.streams.bavet.uni;
import java.util.Set;
import org.optaplanner.constraint.streams.bavet.BavetConstraintFactory;
import org.optaplanner.constraint.streams.bavet.bi.BavetGroupBiConstraintStream;
import org.optaplanner.constraint.streams.bavet.bi.BiTuple;
import org.optaplanner.constraint.streams.bavet.common.AbstractGroupNode;
import org.optaplanner.constraint.streams.bavet.common.BavetAbstractConstraintStream;
import org.optaplanner.constraint.streams.bavet.common.NodeBuildHelper;
import org.optaplanner.constraint.streams.bavet.common.TupleLifecycle;
import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.api.score.stream.ConstraintStream;
final class BavetBiGroupBridgeUniConstraintStream
extends BavetAbstractUniConstraintStream {
private final BavetAbstractUniConstraintStream parent;
private BavetGroupBiConstraintStream groupStream;
private final UniGroupNodeConstructor> nodeConstructor;
public BavetBiGroupBridgeUniConstraintStream(BavetConstraintFactory constraintFactory,
BavetAbstractUniConstraintStream parent,
UniGroupNodeConstructor> nodeConstructor) {
super(constraintFactory, parent.getRetrievalSemantics());
this.parent = parent;
this.nodeConstructor = nodeConstructor;
}
@Override
public boolean guaranteesDistinct() {
return true;
}
public void setGroupStream(BavetGroupBiConstraintStream groupStream) {
this.groupStream = groupStream;
}
// ************************************************************************
// Node creation
// ************************************************************************
@Override
public void collectActiveConstraintStreams(Set> constraintStreamSet) {
parent.collectActiveConstraintStreams(constraintStreamSet);
constraintStreamSet.add(this);
}
@Override
public > void buildNode(NodeBuildHelper buildHelper) {
if (!childStreamList.isEmpty()) {
throw new IllegalStateException("Impossible state: the stream (" + this
+ ") has an non-empty childStreamList (" + childStreamList + ") but it's a groupBy bridge.");
}
int inputStoreIndex = buildHelper.reserveTupleStoreIndex(parent.getTupleSource());
TupleLifecycle> tupleLifecycle =
buildHelper.getAggregatedTupleLifecycle(groupStream.getChildStreamList());
int outputStoreSize = buildHelper.extractTupleStoreSize(groupStream);
AbstractGroupNode, BiTuple, ?, ?, ?, ?> node =
nodeConstructor.apply(inputStoreIndex, tupleLifecycle, outputStoreSize);
buildHelper.addNode(node, this);
}
@Override
public ConstraintStream getTupleSource() {
return parent.getTupleSource();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy