All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.optaplanner.constraint.streams.bavet.common.BavetAbstractConstraintStream Maven / Gradle / Ivy

Go to download

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).

There is a newer version: 10.0.0
Show newest version
package org.optaplanner.constraint.streams.bavet.common;

import java.util.Set;
import java.util.function.Function;

import org.optaplanner.constraint.streams.bavet.BavetConstraint;
import org.optaplanner.constraint.streams.bavet.BavetConstraintFactory;
import org.optaplanner.constraint.streams.bavet.uni.BavetAbstractUniConstraintStream;
import org.optaplanner.constraint.streams.common.AbstractConstraintStream;
import org.optaplanner.constraint.streams.common.RetrievalSemantics;
import org.optaplanner.constraint.streams.common.ScoreImpactType;
import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.api.score.stream.ConstraintFactory;
import org.optaplanner.core.api.score.stream.ConstraintStream;
import org.optaplanner.core.api.score.stream.uni.UniConstraintStream;

public abstract class BavetAbstractConstraintStream extends AbstractConstraintStream {

    protected final BavetConstraintFactory constraintFactory;

    public BavetAbstractConstraintStream(BavetConstraintFactory constraintFactory,
            RetrievalSemantics retrievalSemantics) {
        super(retrievalSemantics);
        this.constraintFactory = constraintFactory;
    }

    // ************************************************************************
    // Penalize/reward
    // ************************************************************************

    protected BavetConstraint buildConstraint(String constraintPackage, String constraintName,
            Score constraintWeight, ScoreImpactType impactType,
            BavetScoringConstraintStream scoringConstraintStream) {
        Function> constraintWeightExtractor = buildConstraintWeightExtractor(
                constraintPackage, constraintName, constraintWeight);
        BavetConstraint constraint =
                new BavetConstraint<>(constraintFactory, constraintPackage, constraintName, constraintWeightExtractor,
                        impactType, false, scoringConstraintStream);
        scoringConstraintStream.setConstraint(constraint);
        return constraint;
    }

    protected BavetConstraint buildConstraintConfigurable(String constraintPackage, String constraintName,
            ScoreImpactType impactType,
            BavetScoringConstraintStream scoringConstraintStream) {
        Function> constraintWeightExtractor = buildConstraintWeightExtractor(
                constraintPackage, constraintName);
        BavetConstraint constraint =
                new BavetConstraint<>(constraintFactory, constraintPackage, constraintName, constraintWeightExtractor,
                        impactType, true, scoringConstraintStream);
        scoringConstraintStream.setConstraint(constraint);
        return constraint;
    }

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

    public abstract void collectActiveConstraintStreams(Set> constraintStreamSet);

    public abstract ConstraintStream getTupleSource();

    public abstract > void buildNode(NodeBuildHelper buildHelper);

    // ************************************************************************
    // Helper methods
    // ************************************************************************

    protected  BavetAbstractUniConstraintStream assertBavetUniConstraintStream(
            UniConstraintStream otherStream) {
        if (!(otherStream instanceof BavetAbstractUniConstraintStream)) {
            throw new IllegalStateException("The streams (" + this + ", " + otherStream
                    + ") are not built from the same " + ConstraintFactory.class.getSimpleName() + ".");
        }
        BavetAbstractUniConstraintStream other = (BavetAbstractUniConstraintStream) otherStream;
        if (constraintFactory != other.getConstraintFactory()) {
            throw new IllegalStateException("The streams (" + this + ", " + other
                    + ") are built from different constraintFactories (" + constraintFactory + ", "
                    + other.getConstraintFactory()
                    + ").");
        }
        return other;
    }

    // ************************************************************************
    // Getters/setters
    // ************************************************************************

    @Override
    public BavetConstraintFactory getConstraintFactory() {
        return constraintFactory;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy