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

org.optaplanner.examples.conferencescheduling.domain.Talk 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
package org.optaplanner.examples.conferencescheduling.domain;

import java.util.List;
import java.util.Set;

import org.optaplanner.core.api.domain.entity.PlanningEntity;
import org.optaplanner.core.api.domain.entity.PlanningPin;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.domain.variable.PlanningVariable;
import org.optaplanner.examples.common.domain.AbstractPersistable;

@PlanningEntity
public class Talk extends AbstractPersistable {

    private String code;
    private String title;
    private TalkType talkType;
    private List speakerList;
    private Set themeTrackTagSet;
    private Set sectorTagSet;
    private Set audienceTypeSet;
    private int audienceLevel;
    private Set contentTagSet;
    private String language;
    private Set requiredTimeslotTagSet;
    private Set preferredTimeslotTagSet;
    private Set prohibitedTimeslotTagSet;
    private Set undesiredTimeslotTagSet;
    private Set requiredRoomTagSet;
    private Set preferredRoomTagSet;
    private Set prohibitedRoomTagSet;
    private Set undesiredRoomTagSet;
    private Set mutuallyExclusiveTalksTagSet;
    private Set prerequisiteTalkSet;
    private int favoriteCount;
    private int crowdControlRisk;
    private Timeslot publishedTimeslot;
    private Room publishedRoom;

    @PlanningPin
    private boolean pinnedByUser = false;

    @PlanningVariable
    private Timeslot timeslot;

    @PlanningVariable
    private Room room;

    public Talk() {
    }

    public Talk(long id) {
        super(id);
    }

    public boolean hasSpeaker(Speaker speaker) {
        return speakerList.contains(speaker);
    }

    public int overlappingThemeTrackCount(Talk other) {
        return overlappingCount(themeTrackTagSet, other.themeTrackTagSet);
    }

    private static  int overlappingCount(Set left, Set right) {
        int leftSize = left.size();
        if (leftSize == 0) {
            return 0;
        }
        int rightSize = right.size();
        if (rightSize == 0) {
            return 0;
        }
        Set smaller = leftSize < rightSize ? left : right;
        Set other = smaller == left ? right : left;
        int overlappingCount = 0;
        for (Item_ item : smaller) { // Iterate over smaller set, lookup in the larger.
            if (other.contains(item)) {
                overlappingCount++;
            }
        }
        return overlappingCount;
    }

    public int overlappingSectorCount(Talk other) {
        return overlappingCount(sectorTagSet, other.sectorTagSet);
    }

    public int overlappingAudienceTypeCount(Talk other) {
        return overlappingCount(audienceTypeSet, other.audienceTypeSet);

    }

    public int overlappingContentCount(Talk other) {
        return overlappingCount(contentTagSet, other.contentTagSet);

    }

    public int missingRequiredTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        return missingCount(requiredTimeslotTagSet, timeslot.getTagSet());

    }

    private static  int missingCount(Set required, Set available) {
        int requiredCount = required.size();
        if (requiredCount == 0) {
            return 0; // If no items are required, none can be missing.
        }
        int availableCount = available.size();
        if (availableCount == 0) {
            return requiredCount; // All the items are missing.
        }
        int missingCount = 0;
        for (Item_ item : required) {
            if (!available.contains(item)) {
                missingCount++;
            }
        }
        return missingCount;
    }

    public int missingPreferredTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        return missingCount(preferredTimeslotTagSet, timeslot.getTagSet());
    }

    public int prevailingProhibitedTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        return overlappingCount(prohibitedTimeslotTagSet, timeslot.getTagSet());
    }

    public int prevailingUndesiredTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        return overlappingCount(undesiredTimeslotTagSet, timeslot.getTagSet());
    }

    public int missingRequiredRoomTagCount() {
        if (room == null) {
            return 0;
        }
        return missingCount(requiredRoomTagSet, room.getTagSet());

    }

    public int missingPreferredRoomTagCount() {
        if (room == null) {
            return 0;
        }
        return missingCount(preferredRoomTagSet, room.getTagSet());
    }

    public int prevailingProhibitedRoomTagCount() {
        if (room == null) {
            return 0;
        }
        return overlappingCount(prohibitedRoomTagSet, room.getTagSet());

    }

    public int prevailingUndesiredRoomTagCount() {
        if (room == null) {
            return 0;
        }
        return overlappingCount(undesiredRoomTagSet, room.getTagSet());
    }

    public int missingSpeakerRequiredTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += missingCount(speaker.getRequiredTimeslotTagSet(), timeslot.getTagSet());
        }
        return count;
    }

    public int missingSpeakerPreferredTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += missingCount(speaker.getPreferredTimeslotTagSet(), timeslot.getTagSet());
        }
        return count;
    }

    public int prevailingSpeakerProhibitedTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += overlappingCount(speaker.getProhibitedTimeslotTagSet(), timeslot.getTagSet());
        }
        return count;
    }

    public int prevailingSpeakerUndesiredTimeslotTagCount() {
        if (timeslot == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += overlappingCount(speaker.getUndesiredTimeslotTagSet(), timeslot.getTagSet());
        }
        return count;
    }

    public int missingSpeakerRequiredRoomTagCount() {
        if (room == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += missingCount(speaker.getRequiredRoomTagSet(), room.getTagSet());
        }
        return count;
    }

    public int missingSpeakerPreferredRoomTagCount() {
        if (room == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += missingCount(speaker.getPreferredRoomTagSet(), room.getTagSet());
        }
        return count;
    }

    public int prevailingSpeakerProhibitedRoomTagCount() {
        if (room == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += overlappingCount(speaker.getProhibitedRoomTagSet(), room.getTagSet());
        }
        return count;
    }

    public int prevailingSpeakerUndesiredRoomTagCount() {
        if (room == null) {
            return 0;
        }
        int count = 0;
        for (Speaker speaker : speakerList) {
            count += overlappingCount(speaker.getUndesiredRoomTagSet(), room.getTagSet());
        }
        return count;
    }

    public boolean hasUnavailableRoom() {
        if (timeslot == null || room == null) {
            return false;
        }
        return room.getUnavailableTimeslotSet().contains(timeslot);
    }

    public int overlappingMutuallyExclusiveTalksTagCount(Talk other) {
        return overlappingCount(mutuallyExclusiveTalksTagSet, other.mutuallyExclusiveTalksTagSet);
    }

    public boolean hasMutualSpeaker(Talk other) {
        for (Speaker speaker : speakerList) {
            if (other.hasSpeaker(speaker)) {
                return true;
            }
        }
        return false;
    }

    public Integer getDurationInMinutes() {
        return timeslot == null ? null : timeslot.getDurationInMinutes();
    }

    public boolean overlapsTime(Talk other) {
        return timeslot != null && other.getTimeslot() != null && timeslot.overlapsTime(other.getTimeslot());
    }

    public int overlappingDurationInMinutes(Talk other) {
        if (timeslot == null) {
            return 0;
        }
        if (other.getTimeslot() == null) {
            return 0;
        }
        return timeslot.getOverlapInMinutes(other.getTimeslot());
    }

    public int combinedDurationInMinutes(Talk other) {
        if (timeslot == null) {
            return 0;
        }
        if (other.getTimeslot() == null) {
            return 0;
        }
        return timeslot.getDurationInMinutes() + other.getTimeslot().getDurationInMinutes();
    }

    @Override
    public String toString() {
        return code;
    }

    @ValueRangeProvider
    public Set getTimeslotRange() {
        return talkType.getCompatibleTimeslotSet();
    }

    @ValueRangeProvider
    public Set getRoomRange() {
        return talkType.getCompatibleRoomSet();
    }

    // ************************************************************************
    // Simple getters and setters
    // ************************************************************************

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public TalkType getTalkType() {
        return talkType;
    }

    public void setTalkType(TalkType talkType) {
        this.talkType = talkType;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public List getSpeakerList() {
        return speakerList;
    }

    public Set getThemeTrackTagSet() {
        return themeTrackTagSet;
    }

    public void setThemeTrackTagSet(Set themeTrackTagSet) {
        this.themeTrackTagSet = themeTrackTagSet;
    }

    public Set getSectorTagSet() {
        return sectorTagSet;
    }

    public void setSectorTagSet(Set sectorTagSet) {
        this.sectorTagSet = sectorTagSet;
    }

    public Set getAudienceTypeSet() {
        return audienceTypeSet;
    }

    public void setAudienceTypeSet(Set audienceTypeSet) {
        this.audienceTypeSet = audienceTypeSet;
    }

    public int getAudienceLevel() {
        return audienceLevel;
    }

    public void setAudienceLevel(int audienceLevel) {
        this.audienceLevel = audienceLevel;
    }

    public Set getContentTagSet() {
        return contentTagSet;
    }

    public void setContentTagSet(Set contentTagSet) {
        this.contentTagSet = contentTagSet;
    }

    public String getLanguage() {
        return language;
    }

    public void setSpeakerList(List speakerList) {
        this.speakerList = speakerList;
    }

    public Set getRequiredTimeslotTagSet() {
        return requiredTimeslotTagSet;
    }

    public void setRequiredTimeslotTagSet(Set requiredTimeslotTagSet) {
        this.requiredTimeslotTagSet = requiredTimeslotTagSet;
    }

    public Set getPreferredTimeslotTagSet() {
        return preferredTimeslotTagSet;
    }

    public void setPreferredTimeslotTagSet(Set preferredTimeslotTagSet) {
        this.preferredTimeslotTagSet = preferredTimeslotTagSet;
    }

    public Set getProhibitedTimeslotTagSet() {
        return prohibitedTimeslotTagSet;
    }

    public void setProhibitedTimeslotTagSet(Set prohibitedTimeslotTagSet) {
        this.prohibitedTimeslotTagSet = prohibitedTimeslotTagSet;
    }

    public Set getUndesiredTimeslotTagSet() {
        return undesiredTimeslotTagSet;
    }

    public void setUndesiredTimeslotTagSet(Set undesiredTimeslotTagSet) {
        this.undesiredTimeslotTagSet = undesiredTimeslotTagSet;
    }

    public Set getRequiredRoomTagSet() {
        return requiredRoomTagSet;
    }

    public void setRequiredRoomTagSet(Set requiredRoomTagSet) {
        this.requiredRoomTagSet = requiredRoomTagSet;
    }

    public Set getPreferredRoomTagSet() {
        return preferredRoomTagSet;
    }

    public void setPreferredRoomTagSet(Set preferredRoomTagSet) {
        this.preferredRoomTagSet = preferredRoomTagSet;
    }

    public Set getProhibitedRoomTagSet() {
        return prohibitedRoomTagSet;
    }

    public void setProhibitedRoomTagSet(Set prohibitedRoomTagSet) {
        this.prohibitedRoomTagSet = prohibitedRoomTagSet;
    }

    public Set getUndesiredRoomTagSet() {
        return undesiredRoomTagSet;
    }

    public void setUndesiredRoomTagSet(Set undesiredRoomTagSet) {
        this.undesiredRoomTagSet = undesiredRoomTagSet;
    }

    public boolean isPinnedByUser() {
        return pinnedByUser;
    }

    public void setPinnedByUser(boolean pinnedByUser) {
        this.pinnedByUser = pinnedByUser;
    }

    public Timeslot getTimeslot() {
        return timeslot;
    }

    public void setTimeslot(Timeslot timeslot) {
        this.timeslot = timeslot;
    }

    public Room getRoom() {
        return room;
    }

    public void setRoom(Room room) {
        this.room = room;
    }

    public Set getMutuallyExclusiveTalksTagSet() {
        return mutuallyExclusiveTalksTagSet;
    }

    public void setMutuallyExclusiveTalksTagSet(Set mutuallyExclusiveTalksTagSet) {
        this.mutuallyExclusiveTalksTagSet = mutuallyExclusiveTalksTagSet;
    }

    public Set getPrerequisiteTalkSet() {
        return prerequisiteTalkSet;
    }

    public void setPrerequisiteTalkSet(Set prerequisiteTalkSet) {
        this.prerequisiteTalkSet = prerequisiteTalkSet;
    }

    public int getFavoriteCount() {
        return favoriteCount;
    }

    public void setFavoriteCount(int favoriteCount) {
        this.favoriteCount = favoriteCount;
    }

    public int getCrowdControlRisk() {
        return crowdControlRisk;
    }

    public void setCrowdControlRisk(int crowdControlRisk) {
        this.crowdControlRisk = crowdControlRisk;
    }

    public Timeslot getPublishedTimeslot() {
        return publishedTimeslot;
    }

    public void setPublishedTimeslot(Timeslot publishedTimeslot) {
        this.publishedTimeslot = publishedTimeslot;
    }

    public Room getPublishedRoom() {
        return publishedRoom;
    }

    public void setPublishedRoom(Room publishedRoom) {
        this.publishedRoom = publishedRoom;
    }

    // ************************************************************************
    // With methods
    // ************************************************************************

    public Talk withTalkType(TalkType talkType) {
        this.talkType = talkType;
        return this;
    }

    public Talk withSpeakerList(List speakerList) {
        this.speakerList = speakerList;
        return this;
    }

    public Talk withThemeTrackTagSet(Set themeTrackTagSet) {
        this.themeTrackTagSet = themeTrackTagSet;
        return this;
    }

    public Talk withSectorTagSet(Set sectorTagSet) {
        this.sectorTagSet = sectorTagSet;
        return this;
    }

    public Talk withAudienceTypeSet(Set audienceTypeSet) {
        this.audienceTypeSet = audienceTypeSet;
        return this;
    }

    public Talk withAudienceLevel(int audienceLevel) {
        this.audienceLevel = audienceLevel;
        return this;
    }

    public Talk withContentTagSet(Set contentTagSet) {
        this.contentTagSet = contentTagSet;
        return this;
    }

    public Talk withLanguage(String language) {
        this.language = language;
        return this;
    }

    public Talk withRequiredRoomTagSet(Set requiredRoomTagSet) {
        this.requiredRoomTagSet = requiredRoomTagSet;
        return this;
    }

    public Talk withPreferredRoomTagSet(Set preferredRoomTagSet) {
        this.preferredRoomTagSet = preferredRoomTagSet;
        return this;
    }

    public Talk withProhibitedRoomTagSet(Set prohibitedRoomTagSet) {
        this.prohibitedRoomTagSet = prohibitedRoomTagSet;
        return this;
    }

    public Talk withUndesiredRoomTagSet(Set undesiredRoomTagSet) {
        this.undesiredRoomTagSet = undesiredRoomTagSet;
        return this;
    }

    public Talk withRequiredTimeslotTagSet(Set requiredTimeslotTagSet) {
        this.requiredTimeslotTagSet = requiredTimeslotTagSet;
        return this;
    }

    public Talk withProhibitedTimeslotTagSet(Set prohibitedTimeslotTagSet) {
        this.prohibitedTimeslotTagSet = prohibitedTimeslotTagSet;
        return this;
    }

    public Talk withPreferredTimeslotTagSet(Set preferredTimslotTagSet) {
        this.preferredTimeslotTagSet = preferredTimslotTagSet;
        return this;
    }

    public Talk withUndesiredTimeslotTagSet(Set undesiredTimeslotTagSet) {
        this.undesiredTimeslotTagSet = undesiredTimeslotTagSet;
        return this;
    }

    public Talk withMutuallyExclusiveTalksTagSet(Set mutuallyExclusiveTalksTagSet) {
        this.mutuallyExclusiveTalksTagSet = mutuallyExclusiveTalksTagSet;
        return this;
    }

    public Talk withPrerequisiteTalksCodesSet(Set prerequisiteTalksCodesSet) {
        this.prerequisiteTalkSet = prerequisiteTalksCodesSet;
        return this;
    }

    public Talk withFavoriteCount(int favoriteCount) {
        this.favoriteCount = favoriteCount;
        return this;
    }

    public Talk withTimeslot(Timeslot timeslot) {
        this.timeslot = timeslot;
        return this;
    }

    public Talk withRoom(Room room) {
        this.room = room;
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy