This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker rostering: domain + generator
- Loading branch information
Showing
17 changed files
with
919 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/target | ||
/local | ||
|
||
# Eclipse, Netbeans and IntelliJ files | ||
/.* | ||
!.gitignore | ||
/nbproject | ||
/*.ipr | ||
/*.iws | ||
/*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.optaplanner.training</groupId> | ||
<artifactId>optaplanner-training</artifactId> | ||
<version>7.0.0.Beta4-training-4</version> | ||
</parent> | ||
|
||
<artifactId>optaplanner-training-lab902-solution</artifactId> | ||
|
||
<repositories> | ||
<!-- TODO remove this once maven central replicates the jboss repository --> | ||
<!-- Included so the examples sources in the distribution zip build out-of-the-box with maven --> | ||
<repository> | ||
<id>jboss-public-repository-group</id> | ||
<name>JBoss Public Repository Group</name> | ||
<url>https://repository.jboss.org/nexus/content/groups/public/</url> | ||
<layout>default</layout> | ||
<releases> | ||
<enabled>true</enabled> | ||
<updatePolicy>never</updatePolicy> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
<updatePolicy>daily</updatePolicy> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!-- Internal dependencies --> | ||
<dependency> | ||
<groupId>org.optaplanner</groupId> | ||
<artifactId>optaplanner-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.optaplanner</groupId> | ||
<artifactId>optaplanner-benchmark</artifactId> | ||
</dependency> | ||
<!-- External dependencies --> | ||
<!-- Common utils --> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
</dependency> | ||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.poi</groupId> | ||
<artifactId>poi</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.poi</groupId> | ||
<artifactId>poi-ooxml</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
45 changes: 45 additions & 0 deletions
45
...lution/src/main/java/org/optaplanner/training/workerrostering/app/WorkerRosteringApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2016 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.training.workerrostering.app; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.optaplanner.core.api.solver.SolverFactory; | ||
import org.optaplanner.training.workerrostering.domain.Roster; | ||
import org.optaplanner.training.workerrostering.persistence.WorkerRosteringGenerator; | ||
|
||
public class WorkerRosteringApp { | ||
|
||
public static void main(String[] args) { | ||
WorkerRosteringGenerator generator = new WorkerRosteringGenerator(); | ||
Roster roster = generator.createRoster(10, 28); | ||
|
||
// LAB-SOLUTION-START | ||
SolverFactory<Roster> solverFactory = SolverFactory.createFromXmlResource( | ||
"org/optaplanner/training/workerrostering/solver/workerRosteringSolverConfig.xml"); | ||
roster = solverFactory.buildSolver().solve(roster); | ||
// LAB-SOLUTION-END | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...b902-solution/src/main/java/org/optaplanner/training/workerrostering/domain/Employee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2016 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.training.workerrostering.domain; | ||
|
||
import java.util.Set; | ||
|
||
public class Employee { | ||
|
||
private final String name; | ||
private final Set<Skill> skillSet; | ||
|
||
public Employee(String name, Set<Skill> skillSet) { | ||
this.name = name; | ||
this.skillSet = skillSet; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Set<Skill> getSkillSet() { | ||
return skillSet; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...lab902-solution/src/main/java/org/optaplanner/training/workerrostering/domain/Roster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2016 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.training.workerrostering.domain; | ||
|
||
import java.util.List; | ||
|
||
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty; | ||
import org.optaplanner.core.api.domain.solution.PlanningScore; | ||
import org.optaplanner.core.api.domain.solution.PlanningSolution; | ||
import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty; | ||
import org.optaplanner.core.api.domain.solution.drools.ProblemFactProperty; | ||
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider; | ||
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; | ||
|
||
@PlanningSolution | ||
public class Roster { | ||
|
||
@ProblemFactProperty | ||
private RosterParametrization rosterParametrization; | ||
@ProblemFactCollectionProperty | ||
private List<Skill> skillList; | ||
@ProblemFactCollectionProperty | ||
private List<Spot> spotList; | ||
@ProblemFactCollectionProperty | ||
private List<TimeSlot> timeSlotList; | ||
@ProblemFactCollectionProperty | ||
@ValueRangeProvider(id = "employeeRange") | ||
private List<Employee> employeeList; | ||
|
||
@PlanningEntityCollectionProperty | ||
private List<ShiftAssignment> shiftAssignmentList; | ||
|
||
@PlanningScore | ||
private HardSoftScore score; | ||
|
||
private Roster() { | ||
} | ||
|
||
public Roster(RosterParametrization rosterParametrization, | ||
List<Skill> skillList, List<Spot> spotList, List<TimeSlot> timeSlotList, List<Employee> employeeList, | ||
List<ShiftAssignment> shiftAssignmentList) { | ||
this.rosterParametrization = rosterParametrization; | ||
this.skillList = skillList; | ||
this.spotList = spotList; | ||
this.timeSlotList = timeSlotList; | ||
this.employeeList = employeeList; | ||
this.shiftAssignmentList = shiftAssignmentList; | ||
score = null; | ||
} | ||
|
||
public RosterParametrization getRosterParametrization() { | ||
return rosterParametrization; | ||
} | ||
|
||
public List<Skill> getSkillList() { | ||
return skillList; | ||
} | ||
|
||
public List<Spot> getSpotList() { | ||
return spotList; | ||
} | ||
|
||
public List<TimeSlot> getTimeSlotList() { | ||
return timeSlotList; | ||
} | ||
|
||
public List<Employee> getEmployeeList() { | ||
return employeeList; | ||
} | ||
|
||
public List<ShiftAssignment> getShiftAssignmentList() { | ||
return shiftAssignmentList; | ||
} | ||
|
||
public HardSoftScore getScore() { | ||
return score; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
.../src/main/java/org/optaplanner/training/workerrostering/domain/RosterParametrization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2016 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.training.workerrostering.domain; | ||
|
||
public class RosterParametrization { | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...lution/src/main/java/org/optaplanner/training/workerrostering/domain/ShiftAssignment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2016 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.training.workerrostering.domain; | ||
|
||
import org.optaplanner.core.api.domain.entity.PlanningEntity; | ||
import org.optaplanner.core.api.domain.variable.PlanningVariable; | ||
|
||
@PlanningEntity | ||
public class ShiftAssignment { | ||
|
||
private final Spot spot; | ||
private final TimeSlot timeSlot; | ||
|
||
@PlanningVariable(valueRangeProviderRefs = "employeeRange") | ||
private Employee employee; | ||
|
||
private ShiftAssignment() { | ||
spot = null; | ||
timeSlot = null; | ||
} | ||
|
||
public ShiftAssignment(Spot spot, TimeSlot timeSlot) { | ||
this.timeSlot = timeSlot; | ||
this.spot = spot; | ||
} | ||
|
||
public Spot getSpot() { | ||
return spot; | ||
} | ||
|
||
public TimeSlot getTimeSlot() { | ||
return timeSlot; | ||
} | ||
|
||
public Employee getEmployee() { | ||
return employee; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return spot + " " + timeSlot; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...-lab902-solution/src/main/java/org/optaplanner/training/workerrostering/domain/Skill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2016 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.training.workerrostering.domain; | ||
|
||
public class Skill { | ||
|
||
private final String name; | ||
|
||
public Skill(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
} |
Oops, something went wrong.