Agency Staff
7 Implementation of the algorithm
7.3 Roster representation and roster class
7.3.1 Overview
The roster class is one of the most important classes in the whole project. The roster class encapsulates the concept of a nurse duty roster, and common operations which may be performed upon rosters (e.g. crossover, mutation, randomisation, error checking etc.).
The roster class holds both the genetic and tabular representations of a week’s duty roster (as outlined in section 6.3) and references to all classes associated with the duty roster, including references to staff members, shifts and shift types.
7.3.2 Historic days
The roster class holds a number of days from the previous week’s roster. These days have been named “historic days” and solely exist to enable the detection of problems between weekly rosters. For example if a nurse works night duty at the end of one week, they cannot work day duty at the beginning of the next. The number of historic days required to detect all possible problems between weekly rosters will vary
depending on the constraints, and must be externally assigned to a roster class. 7.3.3 Class contents
The below diagram illustrates the main components that compose the roster’s class. The lines on the diagram represent dependencies between the various components.
Roster Class Shift Matrix
Shift Shift Shift Shift Shift Shift
Shift Shift Shift Shift Shift Shift
Shift Shift Shift Shift Shift Shift
Valid shifts collection Shif t Shif t Shift Staff Collections Shif t Shif t Staff Assignable matrix
True True True True True True
True True True True True True
True True True True True True
Hours worked by array
{37.5, 22.5, 15, 22.5, 37.5, ... }
Open days array
{True, True, True, True, ....}
Assignable slots array
{6,6,6,6,6,...}
Chromasomes
The roster class contains the following simple data structures: • The “shift matrix”
This is simple a 2D array of shifts, and represents a tabular form of the roster (section 6.3.2). The columns of this array represent days, while the rows represent staff members. Therefore any element in this array represents an assignment to a particular shift on a particular day for a particular staff member.
If the value is null, this represents a day off. • Historic day count
This counts how many days are included in the shift matrix are from the week before the week represented by the roster class.
• The “assignable matrix”
This is a 2D array of Booleans. It’s purpose is to determine which slots in the roster have been fixed by the user and may not be altered. If an element in the “assignable matrix” is true, then this indicates that the corresponding element in the roster matrix can be freely changed by the program.
Note that “historic days” always have a false value in the assignable matrix. Since they come from previous weeks, they cannot be changed.
• The “staff collection”
This is a collection of all the staff member objects associated with the duty roster i.e. all the staff members to which the roster refers.
• The “hours worked by…” array
This is an array containing the maximum number of hours worked in a week by each staff member.
It serves 2 purposes:
1. Avoids method calls to find the number of hours worked by each staff member.
2. Allows independent adjustment of the number of hours worked in a week. • The “maximum assignable slots” array
This is a 1D array, as large as the staff collection. It’s purpose is to store the number of slots for each staff member which are not marked as “false” in the “assignable matrix”. It represents how many days may be modified by the algorithm for each staff member. This data is calculable from the “assignable matrix”, but is cached in this array for maximum efficiency.
• The “open days” array
This is a 1D array of Booleans with one element for each day of the week. It indicates which days the ward is open. If the open days array contains false for any particular day, it can be said that the ward is not open that day, so no staff members can be assigned any shifts on that day. All cells for that day in the “assignable matrix” will be false.
This array also caches data calculable from the assignable matrix, but is present for maximum efficiency.
• The valid shifts collection
This is compiled from the valid shifts for each staff member. It’s main use is for setting up of classes to evaluate the fitness of the roster.
• The chromosomes array.
Holds the genetic representation associated with the roster. 7.3.4 UML Diagram
The information in the previous section is summarised here in a UML [17] diagram (Figure 35). RosterException RosterException() (from representation) Chromasone m_DaysFilled[] : boolean m_InvalidDays[] : boolean m_MaxHours : double m_dAllowedOwingHours : double = 0 m_dHours : double m_dInitialMaxHoursModifier : double = 0 m_dMaxHoursModifier : double = 0 m_nDays : int m_numberofTries : int clearGenes() getAttachedStaffMember() isChromasoneFull() makeDayIllegal() (from representation) Shift (from shifts) #m_GeneMatr...-m_ValidShifts[] ShiftType (from shifttypes) 1 1 Roster m_AllStaff : Logical View::java::util::ArrayList = null BuildChromasones() : void
BuildFromMyChromasones() : void RandomiseTimetable() : void
addStaffMember(s : StaffMember) : void checkWeekLengthFor(staffNo : int) : int countStaffMembers() : int
makeHardAssignment(sm : StaffMember, day : int, sh : Shift) : void mate(a : Roster, b : Roster, c : Roster) : void
mutate() : void mutateMethod1() : void mutateMethod2() : void mutateMethod3() : void mutateMethod4() : void (from representation) -m_myChromasones[] -m_ShiftMatrix... StaffMember (from staff) -m_attachedStaffMe... SkillsDescriptor
m_sName : Logical View::java::lang::String m_uid : int = this.hashCode()
SkillsDescriptor() equals() toString()
(from staff)