ScheduleSolver modelling faqs

Please contact us with questions not answered here.


General questions

How do I model the constraints relating to previous planning periods

The schedule for each employee in the current planning period is usually 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.
  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 Sequence or Expressions) to this scheduling period which ensures that only a night shift or day off is assigned on the first day.

Both options can be used together by including some of the previous schedules (fixed in place) and then adding additional constraints for the ones which would require long sections of the previous schedules.

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 to not penalise the solution too much if it only breaks the constraint by 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 Sequence constraints a function attribute may be used in the weight element to specify the penalty function for that constraint. In the Expressions constraint a custom penalty function can be defined.

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

By default the model allows employees to be assigned a maximum of one task per shift. To allow more than one task per shift to be assigned use the MultipleTasksPerShift constraint.

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 constraint.

Can I create new, custom constraints and penalty functions?

Yes. See Expressions.

How do I leave employee(s) unscheduled if possible?

This can be modelled using the UseIfNeeded constraint in <Contract>.


Employee work constraints

How do I model a minimum or maximum total number of work time between two dates in the planning period e.g. a particular week, two weeks, month etc?

These constraints can be modelled using Workload. It sets a minimum or maximum number of minutes between any two dates in the planning period It could also be modelled using Expressions.

How do I model a minimum rest time between shifts?

See the MinRestTime constraint.

How do I model a minimum amount of continuous rest (non-work) time required within a defined period?

See the MinRestInPeriod constraint.

How do I model a minimum amount of continuous rest (non-work) time required during 24 hours?

See the DailyRest constraint.

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

See FixedAssignments and/or Requests.

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 Sequence constraint. Define a sequence which matches a single day on (or off) and impose a maximum or minimum number of matches of that sequence.

Example

<Sequence>
  <Max count="18" weight="1000" label="Max 18 days on"/>  
  <Min count="16" weight="1000" label="Min 16 days on"/> 
  <Pattern>
    <Shift>All</Shift>
  </Pattern>
</Sequence>
  
<Sequence>
  <Max count="10" weight="1000" label="Max 10 days off"/>  
  <Pattern>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

It could also be modelled using Expressions.

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 Sequence constraint.

Example

<Sequence>
  <Max count="4" weight="100" label="Max 4 night shifts between days 0 to 6"/>  
  <PeriodStart>0</PeriodStart>
  <PeriodEnd>6</PeriodEnd>
  <Pattern>
    <Shift>N</Shift>
  </Pattern>
</Sequence>

It could also be modelled using Expressions.

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

See 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 Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="1000" label="Max 6 consecutive working days"/>  
  <Pattern>
    <Shift>All</Shift>
    <Shift>All</Shift>
    <Shift>All</Shift>
    <Shift>All</Shift>
    <Shift>All</Shift>
    <Shift>All</Shift>
    <Shift>All</Shift>
  </Pattern>
</Sequence>
  
<Sequence>
  <Max count="0" weight="5" label="Min 2 consecutive working days"/>  
  <Pattern> <!-- Include this pattern if the last day of the previous schedule was off -->
    <Start>0</Start>
    <Shift>All</Shift>
    <Shift>-</Shift>
  </Pattern> 
  <Pattern>
    <Shift>-</Shift>
    <Shift>All</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

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

See 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 Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="20" label="Max 3 consecutive days off"/>  
  <Pattern>
    <Shift>-</Shift>
    <Shift>-</Shift>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

<Sequence>
  <Max count="0" weight="10" label="Min 2 consecutive days off"/>  
  <Pattern> <!-- Include this pattern if the last day of the previous schedule was on -->
    <Start>0</Start>
    <Shift>-</Shift>
    <Shift>All</Shift>
  </Pattern> 
  <Pattern>
    <Shift>All</Shift>
    <Shift>-</Shift>
    <Shift>All</Shift>
  </Pattern>
</Sequence>

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

See 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 Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="100" label="Min 2 consecutive N shifts"/>
  <Pattern>
    <NotShift>N</NotShift>
    <Shift>N</Shift>
    <NotShift>N</NotShift>
  </Pattern>
</Sequence>

<Sequence>
  <Max count="0" weight="1000" label="Max 4 consecutive N shifts"/>  
  <Pattern>
    <Shift>N</Shift>
    <Shift>N</Shift>
    <Shift>N</Shift>
    <Shift>N</Shift>
    <Shift>N</Shift>
  </Pattern>
</Sequence>

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

The simplest way to model this is using the Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="1000" label="No E after N"/>  
  <Pattern>
    <Shift>N</Shift>
    <Shift>E</Shift>
  </Pattern>
</Sequence>
<Sequence>
  <Max count="0" weight="1000" label="No D after E"/>  
  <Pattern>
    <Shift>E</Shift>
    <Shift>D</Shift>
  </Pattern>
</Sequence>

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

This can be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="1000" label="Saturday and Sunday on or off"/>        
  <Pattern>
    <Start>Saturday</Start>
    <Shift>All</Shift>
    <Shift>-</Shift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>-</Shift>
    <Shift>All</Shift>
  </Pattern>
</Sequence>

It could also be modelled using Expressions.

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

This can be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="10" label="No N shift before a weekend off"/>  
  <Pattern>
    <Start>Friday</Start>
    <Shift>N</Shift>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

It could also be modelled using Expressions.

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

This can be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="1000" label="Identical shift types during weekends"/>  
  <Pattern>
    <Start>Saturday</Start>
    <Shift>N</Shift>
    <NotShift>N</NotShift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <NotShift>N</NotShift>
    <Shift>N</Shift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>D</Shift>
    <NotShift>D</NotShift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <NotShift>D</NotShift>
    <Shift>D</Shift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>E</Shift>
    <NotShift>E</NotShift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <NotShift>E</NotShift>
    <Shift>E</Shift>
  </Pattern>
</Sequence>

It could also be modelled using Expressions.

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

This can be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="1000" label="At least two free days after N shift"/>  
  <Pattern>
    <Shift>N</Shift>
    <Shift>-</Shift>
    <Shift>All</Shift>
  </Pattern>
</Sequence>

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

This can be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="2" weight="100" label="Max 2 Fridays"/> 
  <Pattern>
    <Start>Friday</Start>
    <Shift>All</Shift>
  </Pattern>
</Sequence>

<Sequence>
  <Max count="2" weight="100" label="Max 2 Mondays"/> 
  <Pattern>
    <Start>Monday</Start>
    <Shift>All</Shift>
  </Pattern>
</Sequence>

It could also be modelled using Expressions.

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

For weekends with work, see MaxTotWeekends and MinTotWeekends.

For weekends without work, it can also be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="2" weight="100" label="Max 2 weekends off"/>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

<Sequence>
  <Max count="2" weight="100" label="Max 2 weekends off (night shift on Friday counts as weekend work)"/>
  <Pattern>
    <Start>Friday</Start>
    <NotShift>N</NotShift>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

<Sequence> 
  <Min count="1" weight="1000" label="Min 1 weekend off"/>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>
          
<Sequence>
  <Max count="3" weight="1000" label="Max 3 weekends on"/>        
  <Pattern>
    <Start>Saturday</Start>
    <Shift>All</Shift>
    <Shift>-</Shift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>-</Shift>
    <Shift>All</Shift>
  </Pattern>
  <Pattern>
    <Start>Saturday</Start>
    <Shift>All</Shift>
    <Shift>All</Shift>
  </Pattern>    
</Sequence>

It could also be modelled using Expressions.

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

See MaxSeqWeekends and MinSeqWeekends.

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

Example

<Sequence>
  <Max count="2" weight="1000" label="Max 2 consecutive working weekends"/>  
  <PeriodStart>5</PeriodStart>
  <PeriodEnd>20</PeriodEnd> <!-- Only match within the first three weeks -->
  <Pattern>
    <Start>Saturday</Start>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>
<Sequence>
  <Max count="2" weight="1000" label="Max 2 consecutive working weekends"/>  
  <PeriodStart>12</PeriodStart>
  <PeriodEnd>27</PeriodEnd> <!-- Only match within the second three week period -->
  <Pattern>
    <Start>Saturday</Start>
    <Shift>-</Shift>
    <Shift>-</Shift>
  </Pattern>
</Sequence>

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

This can be modelled using the Sequence constraint.

Example

<Sequence>
  <Max count="0" weight="100" label="Max 6 days between D shifts"/>
  <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>
</Sequence>

<Sequence>
  <Max count="0" weight="100" label="Min 6 days between N shifts"/>
  <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>
</Sequence>

How do I model a minimum or maximum total number minutes at a specific facility/location?

This can be modelled using the Workload constraint with the Resource option.

Example

<Workload>    
  <TimeUnits>
    <Max> 
      <Count>100</Count> 
      <Label>Max 10 hours at facility A in the first two weeks</Label>
      <Resource>FacilityA</Resource>
    </Max>
    <PeriodStart>0</PeriodStart>
    <PeriodEnd>13</PeriodEnd> 
  </TimeUnits>
</Workload>

It could also be modelled using Expressions.

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?

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

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

They can be modelled using Expressions.

How do I model constraints on shift start times, end times and durations?

See <ShiftStartTimes>, <ShiftEndTimes>, <ShiftStartEndTimes> and <ShiftLengths> in Contract

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

This can be modelled using Expressions.

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

This can be modelled using Expressions.

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 Sequence constraint or Expressions.


Task/shift constraints

How do I model tasks that require specific skills?

See the Skills option in Task.

How do I define tasks which should not be assigned if possible?

See the AssignedWeight option in Task.

How do I set different priorities for assigning different tasks?

See the UnassignedWeight option in Task.

How do I define a group of tasks which must all be assigned to the same person?

See LinkedTask.