/// <summary> /// Constructs two offspring by combining this schedule with a given schedule. The first offspring will contain /// 1/4 of this schedule's rounds and 3/4 of the other schedule's rounds. The second offspring will contain the /// leftover rounds. /// </summary> /// <param name="other"></param> /// <param name="quarterRounds"></param> /// <returns></returns> public (BallStarsSchedule, BallStarsSchedule) Crossover(BallStarsSchedule other, int quarterRounds) { BallStarsSchedule offspring1 = ConstructOffspring(this, other, quarterRounds); BallStarsSchedule offspring2 = ConstructOffspring(other, this, quarterRounds); return(offspring1, offspring2); }
/// <summary> /// Constructs a schedule by taking 1/4 of schedule1's rounds and 3/4 of schedule2's rounds. /// </summary> /// <param name="schedule0"></param> /// <param name="schedule1"></param> /// <param name="quarterRounds"></param> /// <returns></returns> private BallStarsSchedule ConstructOffspring(BallStarsSchedule schedule0, BallStarsSchedule schedule1, int quarterRounds) { BallStarsSchedule result = new BallStarsSchedule(this.Rounds.Length, _amountOfTeams, _avgPlayersPerTeam); for (int i = 0; i < quarterRounds; i++) { result.Rounds[i] = schedule0.Rounds[i].Clone(); } for (int i = quarterRounds; i < this.Rounds.Length; i++) { result.Rounds[i] = schedule1.Rounds[i].Clone(); } result.UpdateScheduleStats(); return(result); }
/// <summary> /// Constructs a random schedule consisting of a given amount of rounds where teams are randomly scheduled to /// compete against each other in random events. /// </summary> /// <param name="amountOfTeams"></param> /// <param name="eventsPerRound"></param> /// <param name="regularEventsPerRound"></param> /// <param name="amountOfRounds"></param> /// <param name="matchPool"></param> /// <param name="breakRound"></param> /// <param name="avgPlayersPerTeam"></param> /// <param name="predefinedMatchUps">Given match-up tuples that cover the minimal requirements. These are /// assumed to be sorted.</param> public static BallStarsSchedule Random(int amountOfTeams, int eventsPerRound, int regularEventsPerRound, int amountOfRounds, List <SportsMatch> matchPool, bool breakRound, int avgPlayersPerTeam, List <Tuple <int, int> > predefinedMatchUps = null) { var schedule = new BallStarsSchedule(amountOfRounds, amountOfTeams, avgPlayersPerTeam); bool usePredefinedMatchUps = predefinedMatchUps != null; // Generate each random round independently unless match-ups are provided int currentMatchUpIndex = 0; for (int i = 0; i < amountOfRounds; i++) { if (!usePredefinedMatchUps) { schedule.Rounds[i] = RoundPlanning.Random(amountOfTeams, eventsPerRound, regularEventsPerRound, matchPool, avgPlayersPerTeam, breakRound); } else { // Get the desired subset of event match-ups List <Tuple <int, int> > eventMatchUps = predefinedMatchUps.GetRange(currentMatchUpIndex, regularEventsPerRound); currentMatchUpIndex += regularEventsPerRound; schedule.Rounds[i] = RoundPlanning.Random(amountOfTeams, eventsPerRound, regularEventsPerRound, matchPool, avgPlayersPerTeam, breakRound, eventMatchUps); // Go back to random generation if we've iterated through all the predefined match-ups usePredefinedMatchUps = currentMatchUpIndex < predefinedMatchUps.Count; } } schedule.UpdateScheduleStats(); return(schedule); }