diff --git a/src/main/resources/current_schedule.txt b/src/main/resources/current_schedule.txt new file mode 100644 index 0000000..995f1e3 --- /dev/null +++ b/src/main/resources/current_schedule.txt @@ -0,0 +1,20 @@ +sam. 10h : Minecraft_minigames +sam. 10h : 2XKO +sam. 11h : Overcooked2 +sam. 13h : MK8dx +sam. 13h : Among_Us +sam. 13h : CodeNames +sam. 15h : Echecs960 +sam. 16h : TriviaPoly +sam. 17h : Golf_it +sam. 18h : Balatro +sam. 18h : LG_One_night +sam. 20h : Babyfoot +sam. 20h : Smash_1v1 +sam. 21h : OSU +sam. 22h : Geoguessr +sam. 23h : LoL +dim. 00h : Ping-pong +dim. 00h : Overwatch2 +dim. 04h : RL_2V2 +dim. 04h : Valo \ No newline at end of file diff --git a/src/main/scala/Main.scala b/src/main/scala/Main.scala index 2e843ca..8cccf93 100644 --- a/src/main/scala/Main.scala +++ b/src/main/scala/Main.scala @@ -7,9 +7,19 @@ import java.time.{LocalDate, LocalDateTime} import scala.io.Source import java.time.Duration import scala.util.Random +import scala.util.CommandLineParser -@main def findSchedule(): Unit = - import Planner.* + given CommandLineParser.FromString[Option[Int]] with + def fromString(value: String): Option[Int] = + try + Some(value.toInt) + catch + case _: NumberFormatException => None + +import Planner.* +@main def main(): Unit = + + val option : Int = 0 //Put 1 to only calculate current conflicts, anything else to optimize val (gameNames, conflicts) = parseConflictMatrix("src/main/resources/conflict_matrix.csv") val updatedConflicts = adjustConflicts(conflicts, independentSets) @@ -19,6 +29,14 @@ import scala.util.Random independentSets = independentSets ) + option match + case 1 => + val currentConflicts = totalConflictsFromText(updatedConflicts, games) + println("Current schedule conflicts: " + currentConflicts) + case _ => findSchedule(gameNames, updatedConflicts, constraints) + +def findSchedule(gameNames: List[String], updatedConflicts: Map[(String, String), Int], constraints: Constraints): Unit = + val schedules = (0 until 1000).toList .map(x => @@ -38,6 +56,7 @@ import scala.util.Random printSchedule(sched, startTime) ) println("Found " + schedules.size + " distinct schedules") + // To test a single schedule : // val schedule = iterativeSchedule(games, updatedConflicts, constraints, 100).sorted @@ -45,6 +64,40 @@ import scala.util.Random // println("Optimized schedule conflicts: " + calculateTotalConflicts(schedule, updatedConflicts)) // printSchedule(schedule, startTime) + +import Planner.* +import Time.* +def totalConflictsFromText(conflictMatrix: ConflictMatrix, games: List[Game]): Int = + //Format : "day. XXh : Game_name" + val schedule = Source.fromFile("src/main/resources/current_schedule.txt").getLines() + val gameSlots = schedule.flatMap { line => + val parts = line.split(" : ").map(_.trim) + if parts.length != 2 then + println(s"Invalid line format: $line") + None + else + val timePart = parts(0) + val gamePart = parts(1) + val timeComponents = timePart.split(" ").map(_.trim) + if timeComponents.length != 2 then + println(s"Invalid time format in line: $line") + None + else + val dayStr = timeComponents(0) + val hourStr = timeComponents(1).replace("h", "") + val hour = hourStr.toInt + val start = dayStr match + case "sam." => Sat(hour) + case "dim." => Sun(hour) + games.find(_.name == gamePart) match + case Some(game) => + Some(ScheduleSlot(startTime.timeTo(start), game)) + case None => + println(s"Game $gamePart not found in game list.") + None + }.toList + calculateTotalConflicts(gameSlots, conflictMatrix) + object Planner: import Time.* @@ -220,8 +273,8 @@ object Planner: ) enum Time(hour: Int, day: Int, month: Int, year: Int): - case Sat(hour: Int) extends Time(hour, 7, 12, 2024) - case Sun(hour: Int) extends Time(hour, 8, 12, 2024) + case Sat(hour: Int) extends Time(hour, 6, 12, 2025) + case Sun(hour: Int) extends Time(hour, 7, 12, 2025) val formatter = DateTimeFormatter.ofPattern("EEE HH") val dateTime: LocalDateTime = LocalDateTime.of(year, month, day, hour, 0) @@ -244,6 +297,7 @@ object Planner: val breaks = List(Slot(Sat(12), Sat(13)), Slot(Sat(19), Sat(20))) val noNight = List(Slot(Sat(23), Sun(8))) + val noNight2 = List(Slot(Sun(0), Sun(8))) val noDeepNight = List(Slot(Sun(2), endTime)) val noLateAf = List(Slot(Sun(3), endTime)) val noMorning = List(Slot(startTime, Sat(12))) @@ -258,21 +312,22 @@ object Planner: Game("Babyfoot", 3, noNight), Game("Balatro", 1, noNight), Game("Geoguessr", 1, noNight), - Game("LoL", 4), + Game("Golf_it", 1, noNight), + Game("LoL", 5), Game("LG_One_night", 1, noNight ++ noEarly), Game("MK8dx", 4, noNight), - Game("HG_Minecraft", 2, noNight), + Game("Minecraft_minigames", 2, noNight), Game("OSU", 1, noDeepNight), Game("Overcooked2", 1, noNight), - Game("Overwatch2", 3, List(Slot(Sun(6), endTime))), + Game("Overwatch2", 3), Game("Ping-pong", 4, noNight), - Game("RL_3v3", 3), - Game("Starcraft2", 5), - Game("Smash_1v1", 4, noLateAf), - Game("Smash_2v2", 4), + Game("RL_2V2", 3), + Game("CodeNames", 3, noNight), + Game("Smash_1v1", 4, noNight2), + Game("2XKO", 2), Game("Valo", 3), - Game("Echecs", 2, noNight), - Game("TriviaPoly", 1, onlyAfternoon) + Game("Echecs960", 3, noNight), + Game("TriviaPoly", 2, onlyAfternoon) ) val independentSets = Set(