public void ResultInTheSameNumberOfAssignments()
        {
            var sessions = new SessionsCollection();
            sessions.Add(1, null, Presenter.Create(1));
            sessions.Add(2, 1, Presenter.Create(2));
            sessions.Add(3, null, Presenter.Create(3));
            sessions.Add(4, 1, Presenter.Create(4));

            var rooms = new List<Room>();
            rooms.Add(Room.Create(1, 10));
            rooms.Add(Room.Create(2, 10));

            var timeslots = new List<Timeslot>();
            timeslots.Add(Timeslot.Create(1, 9.0));
            timeslots.Add(Timeslot.Create(2, 10.25));

            var solution = new Solution(sessions, rooms, timeslots);
            while (solution.AssignmentsCompleted < sessions.Count())
            {
                solution.AssignSessionsWithOnlyOneOption();
                solution.AssignMostConstrainedSession();
            }

            var s2 = solution.SwapAssignments();

            Assert.AreEqual(solution.Assignments.Count(), s2.Assignments.Count());
        }
        public void KeepTheOriginalAssignmentsUnchanged()
        {
            var sessions = new SessionsCollection();
            sessions.Add(1, null, Presenter.Create(1));
            sessions.Add(2, 1, Presenter.Create(2));
            sessions.Add(3, null, Presenter.Create(3));
            sessions.Add(4, 1, Presenter.Create(4));

            var rooms = new List<Room>();
            rooms.Add(Room.Create(1, 10));
            rooms.Add(Room.Create(2, 10));

            var timeslots = new List<Timeslot>();
            timeslots.Add(Timeslot.Create(1, 9.0));
            timeslots.Add(Timeslot.Create(2, 10.25));

            var solution = new Solution(sessions, rooms, timeslots);
            while (solution.AssignmentsCompleted < sessions.Count())
            {
                solution.AssignSessionsWithOnlyOneOption();
                solution.AssignMostConstrainedSession();
            }

            var originalSolution = solution.Assignments.Serialize();
            solution.Assignments.WriteSchedule();

            var s2 = solution.SwapAssignments();
            var postSwapSolution = solution.Assignments.Serialize();
            solution.Assignments.WriteSchedule();

            Assert.AreEqual(originalSolution, postSwapSolution);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns an optimized conference schedule based on the inputs.
        /// </summary>
        /// <param name="sessions">A list of sessions and their associated attributes.</param>
        /// <param name="rooms">A list of rooms that sessions can be held in along with their associated attributes.</param>
        /// <param name="timeslots">A list of time slots during which sessions can be delivered.</param>
        /// <returns>A collection of assignments representing the room and timeslot in which each session will be delivered.</returns>
        public IEnumerable<Assignment> Process(IEnumerable<Session> sessions, IEnumerable<Room> rooms, IEnumerable<Timeslot> timeslots)
        {
            var solution = new Solution(sessions, rooms, timeslots);

            while (solution.AssignmentsCompleted < sessions.Count())
            {
                if (solution.AssignSessionsWithOnlyOneOption() > 0)
                    solution.RaiseUpdateEvent(_updateEventHandler);

                if (solution.AssignMostConstrainedSession() > 0)
                    solution.RaiseUpdateEvent(_updateEventHandler);
            }

            if (!solution.IsFeasible)
                throw new Exceptions.NoFeasibleSolutionsException();
            else
                solution = solution.Optimize(_updateEventHandler);

            return solution.Results;
        }
        public void ResultInTwoDifferencesInAssignments()
        {
            var sessions = new SessionsCollection();
            sessions.Add(1, null, Presenter.Create(1));
            sessions.Add(2, 1, Presenter.Create(2));
            sessions.Add(3, null, Presenter.Create(3));
            sessions.Add(4, 1, Presenter.Create(4));

            var rooms = new List<Room>();
            rooms.Add(Room.Create(1, 10));
            rooms.Add(Room.Create(2, 10));

            var timeslots = new List<Timeslot>();
            timeslots.Add(Timeslot.Create(1, 9.0));
            timeslots.Add(Timeslot.Create(2, 10.25));

            var solution = new Solution(sessions, rooms, timeslots);
            while (solution.AssignmentsCompleted < sessions.Count())
            {
                solution.AssignSessionsWithOnlyOneOption();
                solution.AssignMostConstrainedSession();
            }

            var s2 = solution.SwapAssignments();

            int differenceCount = 0;
            foreach (var a1 in solution.Assignments)
            {
                var a2 = s2.Assignments.Where(a => a.RoomId == a1.RoomId && a.TimeslotId == a1.TimeslotId).Single();
                if (a1.SessionId != a2.SessionId)
                    differenceCount++;
            }

            Assert.AreEqual(2, differenceCount);
        }
Exemplo n.º 5
0
 internal Solution(Solution solution)
 {
     Load(solution);
 }
Exemplo n.º 6
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();
 }