org.optaplanner.examples.conferencescheduling.domain.Talk Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of optaplanner-examples Show documentation
Show all versions of optaplanner-examples 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 the examples which demonstrate how to use it in a normal Java application.
/*
* Copyright 2017 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.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(valueRangeProviderRefs = "timeslotRange")
private Timeslot timeslot;
@PlanningVariable(valueRangeProviderRefs = "roomRange")
private Room room;
public Talk() {
}
public Talk(long id) {
super(id);
}
public boolean hasSpeaker(Speaker speaker) {
return speakerList.contains(speaker);
}
public boolean hasAnyUnavailableSpeaker() {
if (timeslot == null) {
return false;
}
for (Speaker speaker : speakerList) {
if (speaker.getUnavailableTimeslotSet().contains(timeslot)) {
return true;
}
}
return false;
}
public int overlappingThemeTrackCount(Talk other) {
return (int) themeTrackTagSet.stream().filter(tag -> other.themeTrackTagSet.contains(tag)).count();
}
public int overlappingSectorCount(Talk other) {
return (int) sectorTagSet.stream().filter(tag -> other.sectorTagSet.contains(tag)).count();
}
public int overlappingAudienceTypeCount(Talk other) {
return (int) audienceTypeSet.stream().filter(audienceType -> other.audienceTypeSet.contains(audienceType)).count();
}
public int overlappingContentCount(Talk other) {
return (int) contentTagSet.stream().filter(tag -> other.contentTagSet.contains(tag)).count();
}
public int missingRequiredTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) requiredTimeslotTagSet.stream().filter(tag -> !timeslot.hasTag(tag)).count();
}
public int missingPreferredTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) preferredTimeslotTagSet.stream().filter(tag -> !timeslot.hasTag(tag)).count();
}
public int prevailingProhibitedTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) prohibitedTimeslotTagSet.stream().filter(tag -> timeslot.hasTag(tag)).count();
}
public int prevailingUndesiredTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) undesiredTimeslotTagSet.stream().filter(tag -> timeslot.hasTag(tag)).count();
}
public int missingRequiredRoomTagCount() {
if (room == null) {
return 0;
}
return (int) requiredRoomTagSet.stream().filter(tag -> !room.hasTag(tag)).count();
}
public int missingPreferredRoomTagCount() {
if (room == null) {
return 0;
}
return (int) preferredRoomTagSet.stream().filter(tag -> !room.hasTag(tag)).count();
}
public int prevailingProhibitedRoomTagCount() {
if (room == null) {
return 0;
}
return (int) prohibitedRoomTagSet.stream().filter(tag -> room.hasTag(tag)).count();
}
public int prevailingUndesiredRoomTagCount() {
if (room == null) {
return 0;
}
return (int) undesiredRoomTagSet.stream().filter(tag -> room.hasTag(tag)).count();
}
public int missingSpeakerRequiredTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getRequiredTimeslotTagSet().stream())
.filter(tag -> !timeslot.hasTag(tag)).count();
}
public int missingSpeakerPreferredTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getPreferredTimeslotTagSet().stream())
.filter(tag -> !timeslot.hasTag(tag)).count();
}
public int prevailingSpeakerProhibitedTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getProhibitedTimeslotTagSet().stream())
.filter(tag -> timeslot.hasTag(tag)).count();
}
public int prevailingSpeakerUndesiredTimeslotTagCount() {
if (timeslot == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getUndesiredTimeslotTagSet().stream())
.filter(tag -> timeslot.hasTag(tag)).count();
}
public int missingSpeakerRequiredRoomTagCount() {
if (room == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getRequiredRoomTagSet().stream())
.filter(tag -> !room.hasTag(tag)).count();
}
public int missingSpeakerPreferredRoomTagCount() {
if (room == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getPreferredRoomTagSet().stream())
.filter(tag -> !room.hasTag(tag)).count();
}
public int prevailingSpeakerProhibitedRoomTagCount() {
if (room == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getProhibitedRoomTagSet().stream())
.filter(tag -> room.hasTag(tag)).count();
}
public int prevailingSpeakerUndesiredRoomTagCount() {
if (room == null) {
return 0;
}
return (int) speakerList.stream().flatMap(speaker -> speaker.getUndesiredRoomTagSet().stream())
.filter(tag -> room.hasTag(tag)).count();
}
public boolean hasUnavailableRoom() {
if (timeslot == null || room == null) {
return false;
}
return room.getUnavailableTimeslotSet().contains(timeslot);
}
public int overlappingMutuallyExclusiveTalksTagCount(Talk other) {
return (int) mutuallyExclusiveTalksTagSet.stream().filter(tag -> other.mutuallyExclusiveTalksTagSet.contains(tag)).count();
}
public int missingPrerequisiteCount() {
return (int) prerequisiteTalkSet.stream()
.filter(prerequisite -> prerequisite.getTimeslot() == null || timeslot.endsBefore(prerequisite.getTimeslot()))
.count();
}
public boolean hasMutualSpeaker(Talk talk) {
for (Speaker speaker : talk.getSpeakerList()) {
if (speakerList.contains(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());
}
@Override
public String toString() {
return code;
}
@ValueRangeProvider(id = "timeslotRange")
public Set getTimeslotRange() {
return talkType.getCompatibleTimeslotSet();
}
@ValueRangeProvider(id = "roomRange")
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 withTimeslot(Timeslot timeSlot) {
this.timeslot = timeSlot;
return this;
}
public Talk withRoom(Room room) {
this.room = room;
return this;
}
}