internal static Session GetUnassignedSessionWithFewestAvailableOptions(this IEnumerable<Assignment> assignments, IEnumerable<Session> sessions, SessionAvailabilityCollection sessionMatrix)
        {
            Session result = null;
            var assignedSessionIds = assignments.Where(a => a.SessionId != null).Select(a => a.SessionId);

            var sessionDictionary = new Dictionary<int, int>();
            foreach (var session in sessions.Where(s => !assignedSessionIds.Contains(s.Id)))
            {
                sessionDictionary.Add(session.Id, sessionMatrix.GetAvailableAssignmentCount(session.Id));
            }

            if (sessionDictionary.Count() > 0)
            {
                var min = sessionDictionary.Min(s => s.Value);
                var keys = sessionDictionary.Where(sd => sd.Value == min).Select(a => a.Key);
                result = sessions.Where(a => keys.Contains(a.Id))
                    .OrderByDescending(b => b.GetDependentDepth(sessions))
                    .ThenByDescending(c => c.GetDependentCount(sessions))
                    .FirstOrDefault();
            }

            return result;
        }
Exemplo n.º 2
0
 private void Load(Solution solution)
 {
     _sessions = solution._sessions.ToList();
     _rooms = solution._rooms.ToList();
     _timeslots = solution._timeslots.ToList();
     _presenters = solution._presenters.ToList();
     _sessionMatrix = solution._sessionMatrix.Clone();
     this.Assignments = solution.Assignments.Clone();
 }
Exemplo n.º 3
0
        private void Load(SessionsCollection sessions, IEnumerable<Room> rooms, IEnumerable<Timeslot> timeslots)
        {
            _sessions = sessions;
            _rooms = rooms;
            _timeslots = timeslots;
            _presenters = sessions.GetPresenters();

            // Create the session availability matrix
            _sessionMatrix = new SessionAvailabilityCollection(sessions, rooms, timeslots);
            if (!_sessionMatrix.IsFeasible)
                throw new Exceptions.NoFeasibleSolutionsException();

            // Setup the empty assignment matrix
            foreach (var room in rooms)
                foreach (var timeslot in timeslots)
                    if (room.AvailableInTimeslot(timeslot.Id))
                        this.Assignments.Add(new Assignment(room.Id, timeslot.Id));

            // Make sure there are enough slots/rooms for all of the sessions
            if (sessions.Count() > this.Assignments.Count())
                throw new Exceptions.NoFeasibleSolutionsException("There are not enough rooms and timeslots to accommodate all of the sessions.");
        }