AutoRoster modelling faqs

Please contact us if you have a question which is not answered here.


General questions

Can I define shift types that won't be assigned by the solvers?

Yes. See Shift in the format documentation.

How do I model the constraints at boundaries between planning periods?

The schedule for each employee in the current planning period is clearly also affected by the employee's schedule in the previous planning period. To model this there are two options:

  1. Include the previous planning period (or as much of it as is relevant) in the current planning period (by making the start date earlier) and then fix all these assignments in place using FixedAssignments so they cannot be changed. (See the example instance Ikegami-3Shift-DATA1 for an example of this method).
  2. The second option is to add constraints which are based on the assignments made in the previous schedules. For example, if a night shift can only followed by a night shift or a day off and the last day of the previous schedule has a night shift, then add a constraint (e.g. using Patterns or Rule) to this scheduling period which ensures that only a night shift or day off is assigned on the first day.

The second method may be slightly more efficient for the solver but may be more effort to model. One solution is to include some of the previous roster (fixed in place) and then add additional constraints for the ones which would require long sections of the previous schedule.

Can I assign different priorities to each constraint?

Yes. Weights can be set for each constraint which reflect the priority of the constraint. The higher the weight the more important it is to satisfy that constraint.

Can I choose linear, quadratic and constant penalty functions?

Yes. By default most soft constraints use linear penalty functions. This means if a maximum constraint is exceeded (or a minimum is not reached) then the solution's penalty is increased by the amount over the maximum (or the amount under the minimum) multiplied by the weight. In some circumstances it may be preferable however to not penalise the solution too much if it only breaks the constraint a small amount but penalise it more heavily as the excess (or deficit) increases. This can be done by using a quadratic function. It means that if a constraint is broken the solution's penalty is increased by the excess (or deficit) squared and then multiplied by the weight.
In the Workload and Patterns constraints a function attribute may be used in the weight element to specify the penalty function for that constraint. In the Rule constraint a custom penalty function can be defined.

How do I model scenarios where employees may work more than one shift per day

By default the model allows employees to be assigned a maximum of one shift per day. To allow more than one shift per day to be assigned use the <MultipleShiftsPerDay> tag in Contract.

Can I create new, custom constraints and penalty functions?

Yes. See Rules.


Employee Constraints

How do I model a minimum or maximum total number of working hours or minutes (or whatever time unit I choose) between two dates in the planning period e.g. a particular week, two weeks, month etc?

These constraints can be modelled using Workload. It imposes a minimum or maximum number of time units between any two dates in the planning period (each shift type has an associated number of time units). It could also be modelled using the Rule constraint.

How do I model a minimum rest time between shifts?

The simplest way is to use the MinRestTime constraint. This constraint is a shortcut which automatically generates Pattern constraints which ensure the specified minimum rest time is satisfied. The constaint can also be used to specify different minimum rest times for different shifts/shift groups by using a shift and shiftGroup attribute. If an employee is allowed to work more than one shift per day then there is also a MinRestTime shortcut in the MultipleShiftsPerDay constraint.

How do I model requests to work (or not work) particular days or shifts on particular days?

These requests can be modelled using the Patterns or Rule constraint but it is generally easier and more efficient to model them using DayOffRequests, DayOnRequests, ShiftOffRequests and ShiftOnRequests.

How do I fix in place, shifts and days off in the roster so they cannot be changed?

See FixedAssignments.

How do I model "maximum or minimum days on/off" constraints?

This can be modelled using the MaxTot constraint.

Example

  <MaxTot label="Max 18 days on" value="18" shift="$" weight="1000"/>
  
  <MaxTot label="Max 10 days off" value="10" shift="-" weight="1000"/>
  
  <MinTot label="Min 16 days on" value="16" shift="$" weight="1000"/>

It can also be modelled using the Patterns constraint. Define a pattern which matches a single day on (or off) and impose a maximum or minimum number of matches of that pattern.

Example

  <Match>
    <Max>
      <Count>18</Count>
      <Weight>1000</Weight>
      <Label>Max 18 days on</Label>
    </Max>  
    <Min>
      <Count>16</Count>
      <Weight>1000</Weight>
      <Label>Min 16 days on</Label>
    </Min> 
    <Pattern>
      <ShiftGroup>All</ShiftGroup>
    </Pattern>
  </Match>
  
  <Match>
    <Max>
      <Count>10</Count>
      <Weight>1000</Weight>
      <Label>Max 10 days off</Label>
    </Max>  
    <Pattern>
      <Shift>-</Shift>
    </Pattern>
  </Match>

It could also be modelled using the Rule constraint.

How do I model "maximum or minimum shift types (optionally between two dates)" constraints?

This can be modelled using the MaxTot constraint.

Example

  <MaxTot label="Max 4 night shifts between days 0 to 6" value="4" shift="N" start="0" end="6" weight="100"/>

It can also be modelled using the Patterns constraint.

Example

  <Match>
    <Max>
      <Count>4</Count>
      <Weight>100</Weight>
      <Label>Max 4 night shifts between days 0 to 6</Label>
    </Max>  
    <RegionStart>0</RegionStart>
    <RegionEnd>6</RegionEnd>
    <Pattern>
      <Shift>N</Shift>
    </Pattern>
  </Match>

It could also be modelled using the Rule constraint.

How do I model "maximum or minimum consecutive days on" constraints?

The easiest way to model this is using the MaxSeq constraint.

Example

  <MaxSeq label="Max 6 consecutive working days" value="6" shift="$" weight="1000"/>
  
  <MinSeq label="Min 2 consecutive working days" value="2" shift="$" weight="5"/>

It can also be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>1000</Weight>
    <Label>Max 6 consecutive working days</Label>
  </Max>  
  <Pattern>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>
  
<Match>
  <Max>
    <Count>0</Count>
    <Weight>5</Weight>
    <Label>Min 2 consecutive working days</Label>
  </Max>  
  <Pattern> <!-- Include this pattern if the last day of the previous schedule was off -->
    <Start>0</Start>
    <ShiftGroup>All<ShiftGroup>
    <Shift>-</Shift>
  </Pattern> 
  <Pattern>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
    <Shift>-</Shift>
  </Pattern>
</Match>

How do I model "maximum or minimum consecutive days off" constraints?

The easiest way to model this is using the MaxSeq constraint.

Example

  <MaxSeq label="Max 3 consecutive days off" value="3" shift="-" weight="20"/>
  
  <MinSeq label="Min 2 consecutive days off" value="2" shift="-" weight="10"/>

It can also be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>20</Weight>
    <Label>Max 3 consecutive days off</Label>
  </Max>  
  <Pattern>
    <Shift>-</Shift>
    <Shift>-</Shift>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Match>

<Match>
  <Max>
    <Count>0</Count>
    <Weight>10</Weight>
    <Label>Min 2 consecutive days off</Label>
  </Max>  
  <Pattern> <!-- Include this pattern if the last day of the previous schedule was on -->
    <Start>0</Start>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern> 
  <Pattern>
    <ShiftGroup>All</ShiftGroup>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>

How do I model "maximum or minimum consecutive shift types" constraints?

The easiest way to model this is using the MaxSeq constraint.

Example

  <MaxSeq label="Max 4 consecutive N shifts" value="4" shift="N" weight="1000"/>
  
  <MinSeq label="Min 2 consecutive N shifts" value="2" shift="N" weight="100"/>

It can also be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>100</Weight>
    <Label>Min 2 consecutive N shifts</Label>
  </Max>
  <Pattern>
    <NotShift>N</NotShift>
    <Shift>N</Shift>
    <NotShift>N</NotShift>
  </Pattern>
</Match>

<Match>
  <Max>
    <Count>0</Count>
    <Weight>1000</Weight>
    <Label>Max 4 consecutive N shifts</Label>
  </Max>  
  <Pattern>
    <Shift>N</Shift>
    <Shift>N</Shift>
    <Shift>N</Shift>
    <Shift>N</Shift>
    <Shift>N</Shift>
  </Pattern>
</Match>

How do I model "illegal shift transitions/sequences" constraints?

The easiest way to model this is using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>1000</Weight>
    <Label>No N-E</Label>
  </Max>  
  <Pattern>
    <Shift>N</Shift>
    <Shift>E</Shift>
  </Pattern>
</Match>
<Match>
  <Max>
    <Count>0</Count>
    <Weight>1000</Weight>
    <Label>No E-D</Label>
  </Max>  
  <Pattern>
    <Shift>E</Shift>
    <Shift>D</Shift>
  </Pattern>
</Match>

How do I model "both Saturday and Sunday on or off" constraints?

This can be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>1000</Weight>
    <Label>No half weekends</Label>
  </Max>        
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <Shift>-</Shift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>

It could also be modelled using the Rule constraint.

How do I model "no night shift before a weekend off" constraints?

This can be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>10</Weight>
    <Label>No night shift before a weekend off</Label>
  </Max>  
  <Pattern>
    <StartDay>Friday</StartDay>
    <Shift>N</Shift>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Match>

It could also be modelled using the Rule constraint.

How do I model "no shift changes during a weekend" constraints?

This can be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>10</Weight>
    <Label>Identical shift types during weekend</Label>
  </Max>  
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>N</Shift>
    <NotShift>N</NotShift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <NotShift>N</NotShift>
    <Shift>N</Shift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>D</Shift>
    <NotShift>D</NotShift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <NotShift>D</NotShift>
    <Shift>D</Shift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>E</Shift>
    <NotShift>E</NotShift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <NotShift>E</NotShift>
    <Shift>E</Shift>
  </Pattern>
</Match>

It could also be modelled using the Rule constraint.

How do I model "minimum days off after night shifts" constraints?

The easiest way to model this is using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>1000</Weight>
    <Label>At least two free days after a night shift</Label>
  </Max>  
  <Pattern>
    <Shift>N</Shift>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>

How do I model "maximum or minimum specific days of the week worked" constraints?

This can be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>2</Count>
    <Weight>100</Weight>
    <Label>Max 2 Fridays</Label>
  </Max> 
  <Pattern>
    <StartDay>Friday</StartDay>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>

<Match>
  <Max>
    <Count>2</Count>
    <Weight>100</Weight>
    <Label>Max 2 Mondays</Label>
  </Max> 
  <Pattern>
    <StartDay>Monday</StartDay>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>

It could also be modelled using the Rule constraint.

How do I model "maximum or minimum weekends with (or without) work" constraints?

This can be modelled using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>2</Count>
    <Weight>100</Weight>
    <Label>Max 2 weekends off</Label>
  </Max>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Match>

<Match>
  <Max>
   <Count>2</Count>
   <Weight>100</Weight>
   <Label>Max 2 weekends off (night shift on Friday counts as weekend work)</Label>
  </Max>
  <Pattern>
    <StartDay>Friday</StartDay>
    <NotShift>N</NotShift>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Match>

<Match> 
  <Min>
    <Count>1</Count>
    <Weight>1000</Weight>
    <Label>Min 1 weekend off</Label>
    </Min> 
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Match>
          
<Match>
  <Max>
    <Count>3</Count>
    <Weight>1000</Weight>
    <Label>Max 3 weekends on</Label>
  </Max>        
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <Shift>-</Shift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>    
</Match>

It could also be modelled using the Rule constraint.

How do I model "maximum or minimum consecutive weekends with (or without) work" constraints?

This can be modelled using the Patterns constraint. For example, if there must be a maximum of two consecutive weekends with work then it is equivalent to a maximum of two weekends with work in every three week period.

Example

<Match>
  <Max>
    <Count>2</Count>
    <Weight>1000</Weight>
    <Label>Max 2 consecutive working weekends</Label>
  </Max>  
  <RegionStart>5</RegionStart>
  <RegionEnd>20</RegionEnd> <!-- Only match within the first three weeks -->
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <Shift>-</Shift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>
<Match>
  <Max>
    <Count>2</Count>
    <Weight>1000</Weight>
    <Label>Max 2 consecutive working weekends</Label>
  </Max>  
  <RegionStart>12</RegionStart>
  <RegionEnd>27</RegionEnd> <!-- Only match within the second three week period -->
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <Shift>-</Shift>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <Shift>-</Shift>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
  <Pattern>
    <StartDay>Saturday</StartDay>
    <ShiftGroup>All</ShiftGroup>
    <ShiftGroup>All</ShiftGroup>
  </Pattern>
</Match>

How do I model "maximum or minimum days between shift types" constraints?

The easiest way to model this is using the Patterns constraint.

Example

<Match>
  <Max>
    <Count>0</Count>
    <Weight>100</Weight>
    <Label>Max 6 days between D shifts</Label>
  </Max>
  <Pattern>
    <Shift>D</Shift>
    <NotShift>D</NotShift>
    <NotShift>D</NotShift>
    <NotShift>D</NotShift>
    <NotShift>D</NotShift>
    <NotShift>D</NotShift>
    <NotShift>D</NotShift>
    <NotShift>D</NotShift>
  </Pattern>
</Match>

<Match>
  <Max>
    <Count>0</Count>
    <Weight>100</Weight>
    <Label>Min 6 days between N shifts</Label>
  </Max>
  <Pattern>
    <Shift>N</Shift>
    <Shift>*</Shift>
    <Shift>N</Shift>
  </Pattern>
  <Pattern>
    <Shift>N</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>N</Shift>
  </Pattern>
  <Pattern>
    <Shift>N</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>N</Shift>
  </Pattern>
  <Pattern>
    <Shift>N</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>N</Shift>
  </Pattern>
  <Pattern>
    <Shift>N</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>*</Shift>
    <Shift>N</Shift>
  </Pattern>
</Match>

How do I model a minimum or maximum total number of working hours or minutes (or whatever time unit I choose) at a particular facility/location?

This can be modelled using the Workload constraint. First define a ShiftGroup which contains all the shift types which are associated with the particular facility/location and then use the ShiftGroup's ID in the constraint as below. This ensures that only work preformed during one of the shift types in the group is counted by the constraint.

Example

<Workload>    
  <TimeUnits>
    <Max> 
      <Count>100</Count> 
      <Label>Max 10 hours at facility A in the first two weeks</Label>
    </Max>
    <RegionStart>0</RegionStart>
    <RegionEnd>13</RegionEnd> 
    <ShiftGroup>FacilityA</ShiftGroup>
  </TimeUnits>
</Workload>

It could also be modelled using the Rule constraint.

How do I model "Employee A must have the same shifts as Employee B" or "Employee X must have different shifts to Employee Y" constraints?

These constraints arise in the form of car sharing, employee tutorship, couples with children to look after, employees with same skill sets, employees not working well together etc. They can be modelled using the EmployeePairings constraint.

Example

<EmployeePairings>
  <Pair>
    <Label>If A has a shift then B should have the same shift. 
    That is,
    If A has an E shift then B must have an E shift.
    If A has an L shift then B must have an L shift.
    If A has an N shift then B must have an N shift.</Label>
    <Weight>1000</Weight>
    <Matches>
      <Match>
        <Assignment><Employee>A</Employee><Shift>E</Shift></Assignment>
        <Assignment><Employee>B</Employee><Shift>E</Shift></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>A</Employee><Shift>L</Shift></Assignment>
        <Assignment><Employee>B</Employee><Shift>L</Shift></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>A</Employee><Shift>N</Shift></Assignment>
        <Assignment><Employee>B</Employee><Shift>N</Shift></Assignment>
      </Match>
    </Matches>
  </Pair>
  
  <Pair>
    <Label>If C has a shift then D should have the same shift 
    (only applies on day zero)</Label>
    <Matches>
      <Match>
        <Assignment><Employee>C</Employee><Shift>E</Shift></Assignment>
        <Assignment><Employee>D</Employee><Shift>E</Shift></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>C</Employee><Shift>L</Shift></Assignment>
        <Assignment><Employee>D</Employee><Shift>L</Shift></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>C</Employee><Shift>N</Shift></Assignment>
        <Assignment><Employee>D</Employee><Shift>N</Shift></Assignment>
      </Match>
    </Matches>
    <Cell>0</Cell>
    <Weight>1000</Weight>
  </Pair>

  <Pair>
    <Label>
    If E1 works a shift from group S1 then E2 must work a shift from group UPG_1_4_7_8.
    If E1 works a shift from group S7 then E2 must work a shift from group UPG_1_4_7.
    If E1 works a shift from group S8 then E2 must work a shift from group UPG_2_5_8 
       or work a shift from group UPG_3_6 on day+1.
    If E1 works a shift from group S3 then E2 must work a shift from group UPG_6 
       or work a shift from group S8 on day-1.
    If E1 works a shift from group S6 then E2 must work a shift from group UPG_3 
       or work a shift from group S8 on day-1.
    (E2 should work shifts which overlap with E1's shifts by at least two hours).
    </Label>
    <Matches>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S1</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>UPG_1_4_7_8</ShiftGroup></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S7</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>UPG_1_4_7</ShiftGroup></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S8</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>UPG_2_5_8</ShiftGroup>
                                           <ShiftGroup offset="1">UPG_3_6</ShiftGroup></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S3</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>UPG_6</ShiftGroup>
                                           <ShiftGroup offset="-1">S8</ShiftGroup></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S6</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>UPG_3</ShiftGroup>
                                           <ShiftGroup offset="-1">S8</ShiftGroup></Assignment>
      </Match>
    </Matches>
    <Weight>250</Weight>
  </Pair>

  <Pair>
    <Label>
    If E1 works a shift S1 then E2 must work a shift from group G2 and 
    E3 must work a shift from group G3 or shift S1
    </Label>
    <Matches>
      <Match>
        <Assignment><Employee>E1</Employee><Shift>S1</Shift></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>G2</ShiftGroup></Assignment>
        <Assignment><Employee>E3</Employee><ShiftGroup>G3</ShiftGroup><Shift>S1</Shift></Assignment>
      </Match>
    </Matches>
    <Weight>250</Weight>
  </Pair>
  
  <NotPair>
    <Label>If X has a shift then Y should NOT have the same shift
    That is,
    If X has an E shift then B must NOT have an E shift.
    If X has an L shift then B must NOT have an L shift.
    If X has an N shift then B must NOT have an N shift.</Label>
    <Matches>
      <Match>
        <Assignment><Employee>X</Employee><Shift>E</Shift></Assignment>
        <Assignment><Employee>Y</Employee><Shift>E</Shift></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>X</Employee><Shift>L</Shift></Assignment>
        <Assignment><Employee>Y</Employee><Shift>L</Shift></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>X</Employee><Shift>N</Shift></Assignment>
        <Assignment><Employee>Y</Employee><Shift>N</Shift></Assignment>
      </Match>
    </Matches>
    <Weight>1000</Weight>
  </NotPair>
  
  <NotPair>
    <Label>
    A violation occurs if :
    E1 has a shift from group S1 
    AND (E2 has shift from group S2 or has a shift from S2b on day-1)
    AND E3 has a shift from S3 
    AND E4 has a shift from S4.
    
    Or a violation occurs if :
    If E1 has a shift from shift group S5 and E2 has a shift from 
    group S6 on the same day.
    </Label>
    <Matches>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S1</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>S2</ShiftGroup>
                                           <ShiftGroup offset="-1">S2b</ShiftGroup></Assignment>
        <Assignment><Employee>E3</Employee><ShiftGroup>S3</ShiftGroup></Assignment>
        <Assignment><Employee>E4</Employee><ShiftGroup>S4</ShiftGroup></Assignment>
      </Match>
      <Match>
        <Assignment><Employee>E1</Employee><ShiftGroup>S5</ShiftGroup></Assignment>
        <Assignment><Employee>E2</Employee><ShiftGroup>S6</ShiftGroup></Assignment>
      </Match>
    </Matches>
    <Weight>250</Weight>
  </NotPair>
</EmployeePairings>

How do I model "IF ... THEN ... " rules and constraints?

They can be modelled using the Conditional constraint or the more general Rule constraint. The example below shows the Conditional constraint.

Example

<Contract ID="Example">

  <Conditionals>
    <Conditional>
      <Label>If at least one night shift then no early 
      or day shifts (nights only or early and days only)</Label>
      <If>Nights</If>
      <Then>NoEDs</Then>
      <Weight>10000</Weight>
    </Conditional>
  
    <Conditional>
      <Label>If 75+ hours over week one and two and 75+ hours 
      over week three and four then no more than five night shifts</Label>
      <If>Over75hrsWks1_2 AND Over75hrsWks3_4</If>
      <Then>Max5Nights</Then>
      <Weight>1000</Weight>
    </Conditional>
  
    <Conditional>
      <Label>If three weekends worked then at least ten days 
      off and max four early shifts or max five nights</Label>
      <If>3Weekends</If>
      <Then>Max5Nights OR (Min10DaysOff AND Max4Early)</Then>
      <Weight>100</Weight>
    </Conditional>
  </Conditionals>

  <!-- The variables are defined below -->

  <Workload>
    <TimeUnits>
      <Min>
        <Count>750</Count>
        <Var>Over75hrsWks1_2</Var>
        <Label>75 hours or more over week1 and week2</Label>
      </Min>
      <RegionStart>0</RegionStart>
      <RegionEnd>13</RegionEnd> 
    </TimeUnits>
  
    <TimeUnits>
      <Min>
        <Count>750</Count>
        <Var>Over75hrsWks3_4</Var>
        <Label>75 hours or more over week3 and week4</Label>
      </Min>
      <RegionStart>14</RegionStart>
      <RegionEnd>27</RegionEnd>
    </TimeUnits>
  </Workload>
    
  <Patterns>    
    <Match>
      <Min>
        <Count>1</Count>
        <Var>Nights</Var>
        <Label>Min 1 Night</Label>
      </Min>  
      <Pattern><ShiftGroup>N</ShiftGroup></Pattern>
    </Match>

    <Match>
      <Max>
        <Count>0</Count>
        <Var>NoEDs</Var>
        <Label>Max zero E or D</Label>
      </Max>  
      <Pattern><ShiftGroup>E</ShiftGroup></Pattern>
      <Pattern><ShiftGroup>D</ShiftGroup></Pattern>
    </Match>

    <Match>
      <Max>
        <Count>5</Count>
        <Var>Max5Nights</Var>
        <Label>Max 5 N</Label>
      </Max>  
      <Pattern><ShiftGroup>N</ShiftGroup></Pattern>
    </Match>
  
    <Match>
      <Max>
        <Count>4</Count>
        <Var>Max4Early</Var>
        <Label>Max 4 E</Label>
      </Max>  
      <Pattern><ShiftGroup>E</ShiftGroup></Pattern>
    </Match>
  
    <Match>
      <Min>
        <Count>10</Count>
        <Var>Min10DaysOff</Var>
        <Label>Min 10 days off</Label>
      </Min>  
      <Pattern><Shift>-</Shift></Pattern>
    </Match>
  
    <Match>
      <Min> 
        <Count>3</Count>
        <Var>3Weekends</Var>
        <Label>At least three weekends</Label>
      </Min>  
      <Pattern>
        <StartDay>Saturday</StartDay>
        <ShiftGroup>All</ShiftGroup>
        <Shift>-</Shift>
      </Pattern>
      <Pattern>
        <StartDay>Saturday</StartDay>
        <Shift>-</Shift>
        <ShiftGroup>All</ShiftGroup>
      </Pattern>
      <Pattern>
        <StartDay>Saturday</StartDay>
        <ShiftGroup>All</ShiftGroup>
        <ShiftGroup>All</ShiftGroup>
      </Pattern>
    </Match>
  </Patterns>

</Contract>

How do I model "All shifts should be the same type between two dates"?

This can be modelled using the Patterns and Conditional constraints or the Rule constraint. For an example, see the example instance HED01.

How do I model "Shift types worked should rotate from one week to another"?

This can be modelled using the Patterns and Conditional constraints or the Rule constraint. For an example, see the example instance HED01.

How do I model "Assign nights in blocks of three (although a four block is allowed if otherwise there is a night before a free Saturday)"?

This can be modelled using the Patterns or Rule constraint. For an example, see the example instance BCDT-Sep.


Shift cover/employee demand constraints

How do I model the shift coverage/employee demand constraints?

See CoverRequirements.

How do I model cover constraints that include skills?

There are two different ways of modelling cover requirements which includes skills. The best method to use depends on what you really want to model.

Sometimes there will be constraints such as: "I need three people on shift X on Monday and among those three people there must be at least one person with skill Y and skill Z. This can be satisfied by one person having skill Y and one person having skill Z or by one person having both skill Y and skill Z". In this case it is best to model the constraint using the <Skill> tag in <Cover> and assigning the appropriate skills to each <Employee>.

Alternatively if you want one person with any skills, one with skill Y and one with skill Z then it is best to model it by creating separate shifts for each skill. For example define: Shift X (Any Skill), Shift X (Skill Y) and Shift X (Skill Z) and then model cover constraints for each new shift type. Restricting which employee can be assigned to each shift type can then be done by using the <ValidShifts> tag in <Contract>. For an example instance which uses this type of modelling see Example-E in the examples section.

Can I model the cover requirements by time periods in the day rather than by shift types?

Yes. See CoverRequirements.

Can I specify different cover constraints for each day in the scheduling period?

Yes. See CoverRequirements.