forked from elenaxenouu/BookIt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimizationAlgorithm.java
More file actions
41 lines (33 loc) · 1.72 KB
/
OptimizationAlgorithm.java
File metadata and controls
41 lines (33 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//Για να λειτουργήσειγ πρέπει να δημιουργηθούν τα αρχεία TimeSlot.java;Booking.java;Shedule.java
//+ scheduleSolverConfig.xml + ScheduleConstraintProvider.java (για τους περιορισμούς)
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.SolverFactory;
import java.util.ArrayList;
import java.util.List;
public class OptimizationAlgorithm {
public void optimizeSchedule(List<User> users, int maxHoursPerDay) {
// Δημιουργία SolverFactory από το configuration του OptaPlanner
SolverFactory<Schedule> solverFactory = SolverFactory.createFromXmlResource("scheduleSolverConfig.xml");
Solver<Schedule> solver = solverFactory.buildSolver();
// Δημιουργία TimeSlots (π.χ. 10:00 - 18:00)
List<TimeSlot> timeSlots = new ArrayList<>();
for (int i = 9; i < 18; i++) {
timeSlots.add(new TimeSlot(i, i + 1));
}
// Δημιουργία κρατήσεων (Booking) από τους χρήστες
List<Booking> bookings = new ArrayList<>();
for (User user : users) {
bookings.add(new Booking(user));
}
// Δημιουργία προβλήματος (Schedule)
Schedule unsolvedSchedule = new Schedule();
unsolvedSchedule.setBookingList(bookings);
unsolvedSchedule.setTimeSlotList(timeSlots);
// Επίλυση προβλήματος
Schedule solvedSchedule = solver.solve(unsolvedSchedule);
// Εμφάνιση αποτελεσμάτων
for (Booking booking : solvedSchedule.getBookingList()) {
System.out.println(booking);
}
}
}