Beispiel #1
0
        public MockDatabase()
        {
            User user1 = new User
            {
                Id           = 1,
                UniversityId = "s0000001",
                FirstName    = "Connagh",
                LastName     = "Muldoon",
                Email        = "*****@*****.**",
                PhoneNumber  = "01452699316",
                DateOfBirth  = new DateTime(1995, 06, 01),
                Role         = UserRole.Student,
                Graduated    = false
            };
            User user2 = new User
            {
                Id           = 2,
                UniversityId = "s0000002",
                FirstName    = "Thomas",
                LastName     = "Clark",
                Email        = "*****@*****.**",
                PhoneNumber  = "01452234765",
                DateOfBirth  = new DateTime(1995, 02, 23),
                Role         = UserRole.Student,
                Enrollments  = new List <Identifier>()
            };
            User user3 = new User
            {
                Id           = 3,
                UniversityId = "s0000003",
                FirstName    = "Abu",
                LastName     = "Alam",
                Email        = "*****@*****.**",
                PhoneNumber  = "01452543876",
                DateOfBirth  = new DateTime(1988, 08, 12),
                Role         = UserRole.Lecturer
            };

            Module module1 = new Module
            {
                Id          = 1,
                ModuleTitle = "Applied Ass Kicking",
                ModuleCode  = "CT1337"
            };

            ModuleRun moduleRun1 = new ModuleRun
            {
                Id       = 1,
                Lecturer = user3.ToIdentifier(),
                Module   = module1.ToIdentifier()
            };

            module1.ModuleRuns = new List <Identifier>()
            {
                moduleRun1.ToIdentifier()
            };

            Assignment assignment1 = new Assignment
            {
                Id             = 1,
                AssignmentName = "1. Chew Bubblegum",
                ModuleRun      = moduleRun1.ToIdentifier()
            };

            moduleRun1.Assignments = new List <Identifier>()
            {
                assignment1.ToIdentifier()
            };

            Course course1 = new Course
            {
                Id           = 1,
                Title        = "Computing - BSc W/Hons",
                CourseLeader = user3.ToIdentifier(),
                ModuleRuns   = new List <Identifier>()
                {
                    moduleRun1.ToIdentifier()
                },
                Students = new List <Identifier>()
                {
                    user1.ToIdentifier()
                }
            };

            Result result1 = new Result()
            {
                Id         = 1,
                Assignment = assignment1.ToIdentifier(),
                Grade      = 74,
                Student    = user1.ToIdentifier()
            };

            assignment1.Results = new List <Identifier>()
            {
                result1.ToIdentifier()
            };

            user1.Enrollments = new List <Identifier>()
            {
                moduleRun1.ToIdentifier()
            };
            user1.Course      = new Identifier(course1);
            user3.Enrollments = new List <Identifier>()
            {
                moduleRun1.ToIdentifier()
            };
            user3.Course = new Identifier(course1);

            UsersCollection.Add(user1);
            UsersCollection.Add(user2);
            UsersCollection.Add(user3);
            ModulesCollection.Add(module1);
            ModuleRunsCollection.Add(moduleRun1);
            AssignmentsCollection.Add(assignment1);
            ResultsCollection.Add(result1);
            CoursesCollection.Add(course1);
        }
        private IEnumerable <(Assignment assignmentOnSaturday, Assignment assignmentOnSunday)> GetWeekendAssignments(AssignmentsCollection assignments)
        {
            for (int i = _schedulePeriod.Start + 5; i < _schedulePeriod.Length; i += 7)
            {
                assignments.AllRounds.TryGetValue(i, out var assignmentOnSaturday);
                assignments.AllRounds.TryGetValue(i + 1, out var assignmentOnSunday);

                yield return(assignmentOnSaturday, assignmentOnSunday);
            }
        }
Beispiel #3
0
        public override void Run()
        {
            Parallel.ForEach(_model.People, p =>
            {
                p.Assignments.StartNewRound();
                _stateCalculator.InitializeState(p);
            });

            foreach (var day in _model.SchedulePeriod)
            {
                Parallel.ForEach(_model.People, p => _stateCalculator.RefreshState(p, day));

                if (_model.Calendar.IsWeekend(day))
                {
                    foreach (var person in _model.People)
                    {
                        if (HasOneAssignmentOnThisWeekend(person, day, out var d) && CanRemoveAssignment(person, d))
                        {
                            var originalState       = person.State.Clone();
                            var originalAssignments = person.Assignments.Clone();

                            person.Assignments.Remove(d);
                            _stateCalculator.InitializeState(person);

                            var   originalWeekEnd = _model.Calendar.IsSaturday(day) ? day + 1 : day;
                            var   newAssignments  = new Assignment[2];
                            State stateOnSaturday = null;
                            AssignmentsCollection assignmentsCollectionOnSaturday = null;

                            foreach (var day2 in _model.SchedulePeriod)
                            {
                                _stateCalculator.RefreshState(person, day2);

                                if (day2 > originalWeekEnd)
                                {
                                    if (_model.Calendar.IsSaturday(day2) && _workEligibilityChecker.CanWorkOnDay(person, day2))
                                    {
                                        foreach (var demand in SelectDemandsForDay(day2))
                                        {
                                            var cost = _costFunction.CalculateCost(person, demand, day2);
                                            if (Math.Abs(cost - _costFunction.MaxCost) > double.Epsilon)
                                            {
                                                stateOnSaturday = person.State.Clone();
                                                assignmentsCollectionOnSaturday = person.Assignments.Clone();
                                                newAssignments[0] = person.Assignments.Add(day2, new Assignment(person, day2, demand.Shift));
                                                break;
                                            }
                                        }
                                    }

                                    if (newAssignments[0] != null && _model.Calendar.IsSunday(day2) && _workEligibilityChecker.CanWorkOnDay(person, day2))
                                    {
                                        foreach (var demand in SelectDemandsForDay(day2))
                                        {
                                            var cost = _costFunction.CalculateCost(person, demand, day2);
                                            if (Math.Abs(cost - _costFunction.MaxCost) > double.Epsilon)
                                            {
                                                newAssignments[1] = person.Assignments.Add(day2, new Assignment(person, day2, demand.Shift));
                                                goto NewAssigningEnded;
                                            }
                                        }
                                    }

                                    if (_model.Calendar.IsSunday(day2) && newAssignments[0] != null)
                                    {
                                        person.Assignments = assignmentsCollectionOnSaturday;
                                        person.State       = stateOnSaturday;
                                        _stateCalculator.RefreshState(person, day2);
                                        newAssignments[0] = null;
                                    }
                                }
                            }

NewAssigningEnded:
                            person.Assignments = originalAssignments;
                            person.State       = originalState;

                            if (newAssignments[0] != null && newAssignments[1] != null)
                            {
                                person.Assignments.Remove(d);
                                person.Assignments.Add(newAssignments[0].Day, newAssignments[0]);
                                person.Assignments.Add(newAssignments[1].Day, newAssignments[1]);
                            }

                            _stateCalculator.InitializeState(person);
                            foreach (var dd in _model.SchedulePeriod.Mutate(end: day))
                            {
                                _stateCalculator.RefreshState(person, dd);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 ///     Override LoadSubItemCollections
 /// </summary>
 protected override void LoadSubItemCollections()
 {
     Assignments = new AssignmentsCollection(this);
     Assignments.SetTable(GetInternalData().Tables["FileAttachmentAssignments"]);
 }