public static void GovOpp(int randomSeed, RoundData round) { Random random = new Random(randomSeed); foreach (RoomData room in round.Rooms) { if (random.NextDouble() < 0.5) { // swap with probability of 1/2... TeamData tmp = room.Opp; room.Opp = room.Gov; room.Gov = tmp; } } }
public override bool Equals(object obj) { if (obj is RoundData) { RoundData rd = (RoundData)obj; return(RoundName.Equals(rd.RoundName)); } else if (obj is string) { return(RoundName.Equals(obj)); } else { throw new NotImplementedException(); } }
public static void Prepare(int randomSeed, int mcSteps, RoundData rd) { // copy startConfig from roundData startConfig = new List <RoomData>(); foreach (RoomData room in rd.Rooms) { startConfig.Add(new RoomData(room, true)); } nRooms = startConfig.Count; // determine avail judges from roundData, // only the ones shown in pool firstJudges = new List <RoundDebater>(); otherJudges = new List <RoundDebater>(); chairJudges = new List <RoundDebater>(); //int nNotAvail = 0; foreach (RoundDebater judge in rd.AllJudges) { if (judge.IsShown) { switch (judge.JudgeState) { case RoundDebater.JudgeStateType.FirstJudge: firstJudges.Add(judge); break; case RoundDebater.JudgeStateType.Judge: otherJudges.Add(judge); break; case RoundDebater.JudgeStateType.Chair: chairJudges.Add(judge); break; //case RoundDebater.JudgeStateType.NotAvail: // nNotAvail++; // break; } } } //nMinJudgesPerRoom = (rd.AllJudges.Count-nNotAvail)/nRooms; // int division! // some other config steps = mcSteps; random = new Random(randomSeed); // init bestConfig bestConfig = DoMonteCarloStep(); }
public static void Rooms(int randomSeed, RoundData round) { Random random = new Random(randomSeed); // check structure of round bool flag = false; int count = 0; foreach (RoomData room in round.Rooms) { if (!room.IsEmpty) { if (flag) { throw new Exception("Rooms not consecutive non-empty from beginning."); } else { count++; } } else { flag = true; } } if (count == 0) { throw new Exception("No non-empty rooms found."); } // shuffle rooms from 0 to count-1 Algorithms.RandomizeArray <RoomData>(round.Rooms, random, count); // keep rounddata consistent for (int i = 0; i < count; i++) { round.Rooms[i].Index = i; } round.UpdateAllArrays(); }
public static void Prepare(int randomSeed, int mcSteps, RoundData roundData, List <RoundDebater> bestSpeakers) { // copy startConfig from given/current roundData startConfig = new List <RoomData>(); availSpeakers = new List <RoundDebater>(); foreach (RoomData room in roundData.Rooms) { // only consider non-empty if (room.IsEmpty) { continue; } // already set FreeSpeakers are added to // availSpeakers (no ordering by Ranking) foreach (RoundDebater rd in room.FreeSpeakers) { availSpeakers.Add(rd); } // make a hard copy, and clear freespeakers RoomData newRoom = new RoomData(room, true); newRoom.FreeSpeakers.Clear(); startConfig.Add(newRoom); } nRooms = startConfig.Count; if (nRooms == 0) { throw new Exception("No non-empty Rooms found."); } // determine avail teams from roundData, // only the ones completely shown in pool // and ordered by ranking! foreach (RoundDebater rd in bestSpeakers) { TeamData td = roundData.AllTeams.Find(delegate(TeamData td_) { return(td_.Equals(rd.Role.TeamName)); }); if (td == null) { continue; } // check if debater is shown! foreach (RoundDebater rd_ in td) { if (rd.Equals(rd_) && !rd_.IsShown) { goto outer; } } // stop if we have enough free speakers if (availSpeakers.Count == 3 * nRooms) { break; } // debater is shown in pool, so add it availSpeakers.Add(rd); outer :; } if (availSpeakers.Count < 3 * nRooms) { throw new Exception("Found " + availSpeakers.Count + " available Speakers, not enough for " + nRooms + " rooms."); } // sort availSpeakers again by Ranking, since the ones already set in rooms come first in availSpeakers // ByRanking relies on correct ordering in availSpeakers availSpeakers.Sort(delegate(RoundDebater rd1, RoundDebater rd2) { int i1 = bestSpeakers.FindIndex(delegate(RoundDebater rd) { return(rd.Equals(rd1)); }); int i2 = bestSpeakers.FindIndex(delegate(RoundDebater rd) { return(rd.Equals(rd2)); }); return(i1.CompareTo(i2)); }); // some other config, not used by ByRanking steps = mcSteps; random = new Random(randomSeed); }
public static List <RoomData> Generate(RoundData roundData, List <TeamData> bestTeams, List <RoundDebater> bestSpeakers ) { List <RoomData> round = new List <RoomData>(); List <TeamData> breakingTeams = new List <TeamData>(); List <RoundDebater> breakingSpeakers = new List <RoundDebater>(); int nonEmptyRooms = 0; foreach (RoomData room in roundData.Rooms) { // only rooms with valid bestSpeaker and bestTeam (set by RoundResultSheet) if (room.ValidBest) { // teams if (room.BestTeam == 0) { breakingTeams.Add(room.Gov); } else { breakingTeams.Add(room.Opp); } // best non-team breaking Speaker breakingSpeakers.Add((RoundDebater)room.AsOrderedObjects()[room.BestSpeaker]); } if (!room.IsEmpty) { nonEmptyRooms++; } } if (nonEmptyRooms % 2 != 0 || breakingTeams.Count == 0 || nonEmptyRooms != breakingTeams.Count) { throw new Exception("Selected round not valid for creating breakround."); } // sort teams by ranking breakingTeams.Sort(delegate(TeamData td1, TeamData td2) { int i1 = bestTeams.FindIndex(delegate(TeamData td) { return(td.Equals(td1)); }); int i2 = bestTeams.FindIndex(delegate(TeamData td) { return(td.Equals(td2)); }); return(i1.CompareTo(i2)); }); // create round by power pairing // position of freeSpeakers is rather irrelevant for (int i = 0; i < breakingTeams.Count / 2; i++) { RoomData room = new RoomData(i, breakingTeams[i], breakingTeams[breakingTeams.Count - 1 - i]); // add two free speakers room.FreeSpeakers.Add(breakingSpeakers[2 * i]); room.FreeSpeakers.Add(breakingSpeakers[2 * i + 1]); round.Add(room); } return(round); }