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

org.optaplanner.examples.dinnerparty.solver.dinnerPartyConstraints.drl 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 the examples which demonstrate how to use it in a normal Java application.

There is a newer version: 9.44.0.Final
Show newest version
/*
 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.optaplanner.examples.dinnerparty.solver;
    dialect "java"

import org.optaplanner.core.api.score.buildin.simple.SimpleScoreHolder;

import org.optaplanner.examples.dinnerparty.domain.Gender;
import org.optaplanner.examples.dinnerparty.domain.Guest;
import org.optaplanner.examples.dinnerparty.domain.Hobby;
import org.optaplanner.examples.dinnerparty.domain.HobbyPractician;
import org.optaplanner.examples.dinnerparty.domain.Job;
import org.optaplanner.examples.dinnerparty.domain.JobType;
import org.optaplanner.examples.dinnerparty.domain.DinnerParty;
import org.optaplanner.examples.dinnerparty.domain.Seat;
import org.optaplanner.examples.dinnerparty.domain.SeatDesignation;
import org.optaplanner.examples.dinnerparty.domain.Table;

global SimpleScoreHolder scoreHolder;

// ############################################################################
// Hard constraints
// ############################################################################

// Maintain a boy-girl-boy-girl seating arrangement is obsolete because it's build into the moves

// 1 democrat and 1 republican = 2 politians at each table but NOT two of the same kind
// 2 doctors at each table but NOT two of the same kind
// 2 coaches at each table but NOT two of the same kind
// 2 programmers at each table but NOT two of the same kind
// 2 socialites at each table
// 2 teachers at each table
rule "twoSameJobTypePerTable"
    when
        $jobType : JobType()
        $table : Table()
        not (
            SeatDesignation(guestJobType == $jobType, seatTable == $table, $leftId : id, $firstJob : guestJob)
            and SeatDesignation(guestJobType == $jobType, seatTable == $table, id > $leftId,
                    differentKindIfNeeded($firstJob))
        )
    then
        scoreHolder.addConstraintMatch(kcontext, -100);
end
// This is to avoid score traps. The score function should for example give an incentive
// to put it 1 doctor at a table without doctors even though 2 doctors are needed.
// This extra rule can be avoided by weighting the broken constraint of the other rule
rule "atLeastOneJobTypePerTableScoreGuider"
    when
        $table : Table()
        $jobType : JobType()
        not SeatDesignation(guestJobType == $jobType, seatTable == $table)
    then
        scoreHolder.addConstraintMatch(kcontext, -100);
end


// Each person must share a hobby with his/her left neighbour
// (so also the same or another hobby with his/her right neighbour)
rule "leftHasHobbyInCommon"
    when
        $leftDesignation : SeatDesignation($leftGuest : guest)
        $rightDesignation : SeatDesignation(isRightOf($leftDesignation), $rightGuest : guest)
        not (
            HobbyPractician(guest == $leftGuest, $leftHobby : hobby)
            and HobbyPractician(guest == $rightGuest, hobby == $leftHobby)
        )
    then
        scoreHolder.addConstraintMatch(kcontext, -100);
end




© 2015 - 2024 Weber Informatics LLC | Privacy Policy