Ejemplo n.º 1
0
        public void OnRoomAvailable()
        {
            IRoomRepository   roomRepo   = new RoomRepo();
            ICourseRepository courseRepo = new NonConflictingCourseRepo();

            AvailableRoomSearch roomSearch = new AvailableRoomSearch(roomRepo, courseRepo);
            var meetingDays = new List <DayOfWeek>()
            {
                DayOfWeek.Monday, DayOfWeek.Wednesday
            };
            var startingTime   = new TimeSpan(12, 0, 0);
            var endingTime     = new TimeSpan(13, 35, 0);
            var minCapacity    = 40;
            var availableRooms = roomSearch.AvailableRooms(meetingDays, startingTime, endingTime, minCapacity);

            //Assert.AreEqual<int>(1, availableRooms.Count);
            //Assert.AreEqual<string>("PKI 158", availableRooms[0].RoomName);
        }
Ejemplo n.º 2
0
        public void AvailableSlots()
        {
            var courseRepo = new NonConflictingCourseRepo();
            var roomRepo   = new RoomRepo();
            var roomSearch = new AvailableRoomSearch(roomRepo, courseRepo);

            SearchParameters searchParameters;

            searchParameters.MeetingDays = new List <DayOfWeek>()
            {
                DayOfWeek.Monday, DayOfWeek.Wednesday
            };
            searchParameters.Capacity  = 10;
            searchParameters.Duration  = new TimeSpan(1, 0, 0);
            searchParameters.StartTime = new TimeSpan(13, 0, 0);
            searchParameters.EndTime   = new TimeSpan(20, 0, 0);

            List <ScheduleSlot> slots = roomSearch.ScheduleSlotsAvailable(searchParameters);

            Assert.AreEqual <int>(3, slots.Count);
        }
Ejemplo n.º 3
0
        // Still working on this
        /// <summary>
        /// Recursively reassign a room for the course.
        /// </summary>
        /// <param name="node">A node represented the linked reassignments.</param>
        /// <param name="c">The course to be reassigned.</param>
        /// <returns>Null if it takes over three shuffles. The available room(s) otherwise.</returns>
        public LinkedReassignments recursiveReassign(LinkedReassignments node, Course c)
        {
            int steps = node.steps + 1;
            LinkedReassignments traverser;
            AvailableRoomSearch availableRoomSearch = new AvailableRoomSearch(RoomRepo, CourseRepo);
            IEnumerable <Room>  rooms = availableRoomSearch.AvailableRooms(c.MeetingDays, (TimeSpan)c.StartTime, (TimeSpan)c.EndTime, int.Parse(c.RoomCapRequest), Type);
            LinkedReassignments newnode;

            // If it takes more than three shuffles then that's too much and ends it
            if (steps > 3)
            {
                return(null);
            }

            // If there are available rooms with regards to room type
            else if (rooms.Count() > 0)
            {
                foreach (var room in rooms)
                {
                    traverser              = node;
                    newnode                = new LinkedReassignments();
                    newnode.steps          = steps;
                    newnode.courseSections = node.courseSections + "," + c.SectionNumber;
                    newnode.courseSteps    = node.courseSteps + "," + c.CourseName;
                    newnode.roomSteps      = (node.roomSteps + "," + room.RoomName);
                    newnode.next           = null;

                    while (traverser.next != null)
                    {
                        traverser = traverser.next;
                    }

                    traverser.next = newnode;
                }

                return(node);
            }

            // Finds all the rooms that match, if a course is assigned to it takes that room, then puts that course through
            // the algorithm
            else
            {
                // Took this from AvailableRoomSearch
                // Pretty sure it gets all rooms from the roomrepository that matches the requirements
                // Then finds all the courses that are assigned to those rooms
                var coursesGroupedByRoom = from room in RoomRepo.Rooms
                                           where room.Capacity >= int.Parse(c.RoomCapRequest) && room.RoomType == Type
                                           join course in CourseRepo.Courses on room equals course.RoomAssignment into courseGroup
                                           select new { Room = room, Courses = courseGroup };

                foreach (var courseGroup in coursesGroupedByRoom)
                {
                    // If no available rooms are found find all the courses assigned
                    // to rooms that match the specifications and run the algorithm on them
                    List <Course> courses = courseGroup.Courses
                                            .Where(x => x.HasRoomAssignment && x.MeetingDays.Intersect(c.MeetingDays).Count(z => true) != 0 && x.StartTime.HasValue &&
                                                   ((x.StartTime.Value <= c.EndTime && x.StartTime.Value >= c.StartTime) || (x.EndTime >= c.StartTime && x.EndTime <= c.EndTime)))
                                            .OrderBy(x => x.StartTime.Value)
                                            .ToList();

                    // Then we'll go through all the paths trying to shuffle here
                    for (int i = 0; i < courses.Count; i++)
                    {
                        newnode                = new LinkedReassignments();
                        traverser              = node;
                        newnode.steps          = steps;
                        newnode.courseSections = node.courseSections + "," + c.SectionNumber + "," + courses[i].SectionNumber;
                        newnode.courseSteps    = node.courseSteps + "," + c.CourseName + "," + courses[i].CourseName;
                        newnode.roomSteps      = node.roomSteps + "," + courses[i].RoomAssignment.RoomName + "," + courses[i].RoomAssignment.RoomName;
                        newnode.next           = null;
                        newnode                = recursiveReassign(newnode, courses[i]);

                        // The first node is just this nodes info which isn't what we want
                        if (newnode != null)
                        {
                            if (newnode.next != null)
                            {
                                newnode = newnode.next;

                                while (traverser.next != null)
                                {
                                    traverser = traverser.next;
                                }

                                traverser.next = newnode;
                            }
                        }
                    }
                }

                return(node);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor for SearchViewModel. Get instances of room and course repositories.
 /// </summary>
 public SearchViewModel()
 {
     roomSearch = new AvailableRoomSearch(RoomRepository.GetInstance(), CourseRepository.GetInstance());
 }
Ejemplo n.º 5
0
 public void ClassRepoNull_ThrowsException()
 {
     IRoomRepository     roomRepo   = new RoomRepo();
     ICourseRepository   courseRepo = null;
     AvailableRoomSearch roomSearch = new AvailableRoomSearch(roomRepo, courseRepo);
 }
Ejemplo n.º 6
0
 public void RoomRepoNull_ThrowsException()
 {
     IRoomRepository     roomRepo   = null;
     ICourseRepository   courseRepo = new NonConflictingCourseRepo();
     AvailableRoomSearch roomSearch = new AvailableRoomSearch(roomRepo, courseRepo);
 }