title: Tournament scheduling issues
body: <p>Currently I'm working on a 1 day tournament scheduling application. Since, each year the number of participating teams is different, I want to automate the scheduling.</p>
  
  <p>Teams are split in 2 groups. each group plays a single round robin tournament.
  I managed to generate all the games to play, but I'm struggling with the planning.</p>
  
  <p>additionally, the teams need to compete in 3 different sport disciplines, with each a dedicated field. (e.g. football field, volleybal field)</p>
  
  <p>Given:
  - games to play
  - fields per sport + available timeslots per field (slots of +-15 minutes)</p>
  
  <p>assumptions:
  - timeslots are not limited
  - 1 field per sport available
  - schedule doesn't need to be balanced in 1st iteration</p>
  
  <p>problems:
  - the quality of my schedule is not that good. in fact, not all timeslots are fully filled, even if there is a solution. the 'density' of my schedule also depends on the order of games processed.</p>
  
  <p>code snippet:</p>
  
  <pre><code>        //algo
          while (_games.Any())
          {
              gameToPlan = _games.Dequeue();
  
              var occupiedHomeTeam = GetTimeslotsOccupiedByTeam(gameToPlan.HomeTeam);
              var occupiedAwayTeam = GetTimeslotsOccupiedByTeam(gameToPlan.AwayTeam);
              var occupiedTeams = occupiedHomeTeam.Union(occupiedAwayTeam);
  
              var availableFields = fields.Where(f =&gt; f.AllowedSports.Contains(gameToPlan.Sport))
                                          .Where(f =&gt; f.Timeslots.Any(t =&gt; t.Game == null &amp;&amp;
                                                                          !t.Occupied &amp;&amp;
                                                                          !occupiedTeams.Any(oc =&gt; oc.Start == t.Start &amp;&amp;
                                                                                                   oc.End == t.End)));
              if (!availableFields.Any())
              {
                  _games.Enqueue(gameToPlan);
                  continue;
              }
              var field = availableFields.First();
              var timeSlots = field.Timeslots.Where(t =&gt; t.Game == null &amp;&amp; 
                                                 !t.Occupied &amp;&amp; 
                                                 !occupiedTeams.Any(oc =&gt; oc.Start == t.Start &amp;&amp; 
                                                                          oc.End   == t.End))
                                      .OrderBy(t =&gt; t.Start);
               if (!timeSlots.Any())
               {
                  _games.Enqueue(gameToPlan);
                  continue;
              }   
              var ts = timeSlots.First();
              ts.Occupied = true;
              ts.Game = gameToPlan;
              gameToPlan.Timeslot = ts;
              gameToPlan.TimeslotId = ts.Id;
              _uow.Save();
          }
  </code></pre>
  
  <p>Can anyone give me an overview of approach, available algorithms,...?</p>
  
  <p>thanks in advance</p>