Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
worker rostering: domain + generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Dec 9, 2016
1 parent 92e5db4 commit 4dfe3ab
Show file tree
Hide file tree
Showing 17 changed files with 919 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,3 +16,4 @@
# Everything generated with optaplanner-training-generator
/optaplanner-training-lab1*
/optaplanner-training-lab901
/optaplanner-training-lab902
10 changes: 10 additions & 0 deletions optaplanner-training-lab902-solution/.gitignore
@@ -0,0 +1,10 @@
/target
/local

# Eclipse, Netbeans and IntelliJ files
/.*
!.gitignore
/nbproject
/*.ipr
/*.iws
/*.iml
73 changes: 73 additions & 0 deletions optaplanner-training-lab902-solution/pom.xml
@@ -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>
@@ -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
}

}
@@ -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;
}

}
@@ -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;
}

}
@@ -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 {

}
@@ -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;
}

}
@@ -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;
}

}

0 comments on commit 4dfe3ab

Please sign in to comment.