Skip to content

Commit

Permalink
feat: Meeting Schedule Quickstart (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfred authored Apr 8, 2024
1 parent 1f812a2 commit 1652379
Show file tree
Hide file tree
Showing 29 changed files with 3,421 additions and 13 deletions.
14 changes: 12 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ a|* <<vehicle-routing, Vehicle Routing>>
* <<food-packaging, Food packaging>>
* <<order-picking, Order Picking>>
* <<school-timetabling, School timetabling>>
* <<facility-location, Facility location problem>>
* <<facility-location-problem, Facility location problem>>
* <<conference-scheduling, Conference Scheduling>>
* <<bed-scheduling, Bed Allocation Scheduling>>
* <<bed-allocation-scheduling, Bed Allocation Scheduling>>
* <<flight-crew-scheduling, Flight Crew Scheduling>>
* <<meeting-scheduling, Meeting Scheduling>>

a|* link:hello-world/README.adoc[Java (Hello World)] (Java, Maven or Gradle)
* link:use-cases/school-timetabling/README.adoc[Quarkus] (Java, Maven or Gradle, Quarkus)
Expand Down Expand Up @@ -112,6 +114,14 @@ image::use-cases/flight-crew-scheduling/quarkus-flight-crew-scheduling-screensho

* link:use-cases/flight-crew-scheduling/README.adoc[Run quarkus-flight-crew-scheduling] (Java, Maven, Quarkus)

=== Meeting Scheduling

Assign timeslots and rooms for meetings to produce a better schedule.

image::use-cases/meeting-scheduling/quarkus-meeting-scheduling-screenshot.png[]

* link:use-cases/meeting-scheduling/README.adoc[Run quarkus-flight-crew-scheduling] (Java, Maven, Quarkus)

== Legal notice

Timefold Quickstarts was https://timefold.ai/blog/2023/optaplanner-fork/[forked] on 20 April 2023 from OptaPlanner Quickstarts,
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<module>use-cases/conference-scheduling</module>
<module>use-cases/bed-allocation</module>
<module>use-cases/flight-crew-scheduling</module>
<module>use-cases/meeting-scheduling</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

import jakarta.enterprise.context.ApplicationScoped;

import ai.timefold.solver.core.impl.util.MutableReference;
import ai.timefold.solver.core.impl.util.Pair;

import org.acme.bedallocation.domain.Bed;
import org.acme.bedallocation.domain.BedPlan;
import org.acme.bedallocation.domain.Department;
Expand Down Expand Up @@ -151,23 +148,25 @@ private List<Stay> generateStayDates(List<Stay> stays, List<Room> rooms, List<Lo
new Pair<>(0.95f, 3),
new Pair<>(1f, 4));
for (int i = 0; i < rooms.size(); i++) {
MutableReference<LocalDate> currentDate = new MutableReference<>(LocalDate.from(initialDate));
while (currentDate.getValue().isBefore(maxDate)) {
LocalDate currentDate = LocalDate.from(initialDate);
while (currentDate.isBefore(maxDate)) {
double countDays = random.nextDouble();
int numDays = periodCount.stream()
.filter(p -> countDays <= p.key())
.mapToInt(Pair::value)
.findFirst()
.getAsInt();
MutableReference<LocalDate> nextDate = new MutableReference<>(currentDate.getValue().plusDays(numDays));
if (nextDate.getValue().isAfter(maxDate)) {
nextDate.setValue(maxDate);
LocalDate nextDate = currentDate.plusDays(numDays);
if (nextDate.isAfter(maxDate)) {
nextDate = maxDate;
}
LocalDate finalCurrentDate = currentDate;
LocalDate finalNexDate = nextDate;
applyRandomValue(1, updatedStays, stay -> stay.getArrivalDate() == null, stay -> {
stay.setArrivalDate(currentDate.getValue());
stay.setDepartureDate(nextDate.getValue());
stay.setArrivalDate(finalCurrentDate);
stay.setDepartureDate(finalNexDate);
});
currentDate.setValue(nextDate.getValue().plusDays(1));
currentDate = nextDate.plusDays(1);
}
}
return updatedStays.stream().filter(s -> s.getArrivalDate() != null).toList();
Expand Down Expand Up @@ -333,4 +332,7 @@ private <T, L> void applyRandomValue(int count, List<T> values, L secondParam, P
}
}
}

private record Pair<K, V>(K key, V value) {
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions use-cases/meeting-scheduling/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
= Meeting Scheduling (Java, Quarkus, Maven)

Assign timeslots and rooms for meetings to produce a better schedule.

image::./quarkus-meeting-scheduling-screenshot.png[]

* <<run,Run the application>>
* <<package,Run the packaged application>>
* <<container,Run the application in a container>>
* <<native,Run it native>>
[[run]]
== Run the application

. Git clone the timefold-quickstarts repo and navigate to this directory:
+
[source, shell]
----
$ git clone https://github.com/TimefoldAI/timefold-quickstarts.git
...
$ cd timefold-quickstarts/use-cases/meeting-scheduling
----

. Start the application with Maven:
+
[source, shell]
----
$ mvn quarkus:dev
----


. Visit http://localhost:8080 in your browser.

. Click on the *Solve* button.

Then try _live coding_:

. Make some changes in the source code.
. Refresh your browser (F5).

Notice that those changes are immediately in effect.


[[package]]
== Run the packaged application

When you're done iterating in `quarkus:dev` mode,
package the application to run as a conventional jar file.

. Build it with Maven:
+
[source, shell]
----
$ mvn package
----
. Run the Maven output:
+
[source, shell]
----
$ java -jar ./target/quarkus-app/quarkus-run.jar
----
+
[NOTE]
====
To run it on port 8081 instead, add `-Dquarkus.http.port=8081`.
====

. Visit http://localhost:8080 in your browser.

. Click on the *Solve* button.

[[container]]
== Run the application in a container

. Build a container image:
+
[source, shell]
----
$ mvn package -Dcontainer
----
The container image name
. Run a container:
+
[source, shell]
----
$ docker run -p 8080:8080 --rm $USER/timefold-solver-quarkus-meeting-scheduling-quickstart:1.0-SNAPSHOT
----

[[native]]
== Run it native

To increase startup performance for serverless deployments,
build the application as a native executable:

. https://quarkus.io/guides/building-native-image#configuring-graalvm[Install GraalVM and gu install the native-image tool]

. Compile it natively. This takes a few minutes:
+
[source, shell]
----
$ mvn package -Dnative
----

. Run the native executable:
+
[source, shell]
----
$ ./target/*-runner
----

. Visit http://localhost:8080 in your browser.

. Click on the *Solve* button.

== More information

Visit https://timefold.ai[timefold.ai].
Loading

0 comments on commit 1652379

Please sign in to comment.