Beispiel #1
0
        public Employee[] createSchedule2()
        {
            if (isPossibleSchedule())
            {
                EmployeeQueue    eq          = new EmployeeQueue(roster);
                Queue <Employee> queue       = eq.queueRandom(r);
                long             brokenCount = 0;

                for (int w = 0; w < getWorkWeek(); w++)
                {
                    for (int p = 0; p < allPositions.Length; p++)
                    {
                        for (int l = 0; l < shiftTimes.Length; l++)
                        {
                            for (int z = 0; z < peoplePerShift()[w, p]; z++)
                            {
                                bool shiftFilled  = false;
                                bool checkDoubles = false;
                                do
                                {
                                    Employee tempEmployee = queue.Dequeue();
                                    if (tempEmployee.getName().Equals("Alex Four"))
                                    {
                                        shiftFilled = false;
                                        int a = 1;
                                        a++;
                                    }
                                    if (tempEmployee.canWork(w, shiftTimes[l], allPositions[p], checkDoubles, weekHours[p]))
                                    {
                                        foreach (Employee e in roster)
                                        {
                                            if (e.getName().Equals(tempEmployee.getName()))
                                            {
                                                e.setSchedule(w, shiftTimes[l], allPositions[p]);
                                                shiftFilled = true;
                                            }
                                        }
                                    }
                                    if (queue.Count == 0 && !shiftFilled)
                                    {
                                        brokenCount++;
                                        if (brokenCount > 1000)
                                        {
                                            return(null);
                                        }
                                        queue        = eq.queueRandom(r);
                                        checkDoubles = true;
                                        int b = 0;
                                        int totalEmployeesPosition = 0;
                                        foreach (Employee e in roster)
                                        {
                                            int a = 0;
                                            foreach (String positions in e.getPositions())
                                            {
                                                if (positions.Equals(allPositions[p]))
                                                {
                                                    totalEmployeesPosition++;
                                                    foreach (String s in e.getWorkSchedule())
                                                    {
                                                        if (!s.Equals("None"))
                                                        {
                                                            a += s.Split('/').Length;
                                                            if (a == weekHours[p])
                                                            {
                                                                b++;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (b == totalEmployeesPosition)
                                        {
                                            weekHours[p]++;
                                        }
                                    }
                                    if (shiftFilled)
                                    {
                                        queue = eq.queueRandom(r);
                                    }
                                } while (!shiftFilled);
                            }
                        }
                    }
                }
            }
            return(roster);
        }