> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automaticrostering.visma.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Consecutive

> Control the number of consecutive shifts or days that employees can work.

This constraint allows you to control how many consecutive shifts or days employees can work. It can be used to set both minimum and maximum limits on consecutive work periods, helping you balance employee workload and prevent burnout.

<Card title="Constraint schema">
  <ResponseField name="consecutiveConstraint" type="object">
    Used to set targets and limits on the number of consecutive shifts that an employee works.

    <Expandable title="properties">
      <ResponseField name="id" type="string" required>
        Unique identifier for the constraint.
      </ResponseField>

      <ResponseField name="labels" type="array of string">
        Labels for the constraint. Labels can be used to group constraints together. For example, if multiple constraints are related to the same shift type, they can all be labeled with the same label.
      </ResponseField>

      <ResponseField name="importance" type="string (enum: NONE | VERY_LOW | LOW | MEDIUM | HIGH | ...)" required>
        The importance of the constraint. The higher the importance, the more the solver will take the constraint into account. Under strict importance, the constraint may never be violated.
      </ResponseField>

      <ResponseField name="filters" type="object">
        Filters to determine the scope of the constraint. Used to indicate what the constraint should be applied to (which employees, which shifts, etc). Leaving this empty means that the constraint always applies.
      </ResponseField>

      <Expandable title="filters – properties">
        <ResponseField name="employees" type="object">
          Used to filter which employees the constraint should be applied to. If not specified, the constraint applies to all employees.
        </ResponseField>

        <Expandable title="employees – properties">
          <ResponseField name="ids" type="array of string">
            List of employee ids that the constraint should be applied to.
          </ResponseField>

          <ResponseField name="labels" type="array of string">
            List of employee labels that the constraint should be applied to.
          </ResponseField>

          <ResponseField name="matchTypes" type="object" />

          <Expandable title="matchTypes – properties">
            <ResponseField name="ids" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the id filters. For example, if set to NONE, entities with the specified ids will be excluded. Default: "ANY".
            </ResponseField>

            <ResponseField name="labels" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the label filters. For example, if set to ANY, entities that have any of the specified labels will be included. Default: "ANY".
            </ResponseField>
          </Expandable>
        </Expandable>

        <ResponseField name="shifts" type="object">
          Used to filter which shifts the constraint should be applied to. If not specified, the constraint applies to all shifts.
        </ResponseField>

        <Expandable title="shifts – properties">
          <ResponseField name="ids" type="array of string">
            List of shift ids that the constraint should be applied to.
          </ResponseField>

          <ResponseField name="labels" type="array of string">
            List of shift labels that the constraint should be applied to.
          </ResponseField>

          <ResponseField name="matchTypes" type="object" />

          <Expandable title="matchTypes – properties">
            <ResponseField name="ids" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the id filters. For example, if set to NONE, entities with the specified ids will be excluded. Default: "ANY".
            </ResponseField>

            <ResponseField name="labels" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the label filters. For example, if set to ANY, entities that have any of the specified labels will be included. Default: "ANY".
            </ResponseField>
          </Expandable>
        </Expandable>
      </Expandable>

      <ResponseField name="targets" type="object" required />

      <Expandable title="targets – properties">
        <ResponseField name="min" type="integer">
          The minimum number of consecutive entities that an employee should ideally work. This cannot be set as a strict limit and will be treated as a target instead.
        </ResponseField>

        <ResponseField name="max" type="integer">
          The maximum number of consecutive entities that an employee can work. Currently only supports importance STRICT.
        </ResponseField>
      </Expandable>
    </Expandable>
  </ResponseField>
</Card>

## Maximum consecutive shifts

To limit the maximum number of consecutive shifts or days an employee can work, use the `max` property in the `targets` object. This limit can only be enforced with [`STRICT` importance](/constraints/index#constraint-importance), meaning the solver will never violate it.

<Tip>
  The below constraint strictly prevents employees from working more than 4 consecutive days. If an employee works on Monday, Tuesday, Wednesday, and Thursday, they must have at least one day off before working again.

  ```json theme={null}
  {
    "id": "cc-max-4-days",
    "importance": "STRICT",
    "targets": {
      "max": 4
    }
  }
  ```
</Tip>

## Minimum consecutive shifts

To encourage employees to work a minimum number of consecutive shifts, use the `min` property in the `targets` object. This is treated as a target rather than a strict requirement, so the solver will try to achieve it but may not always succeed.

<Tip>
  The below constraint encourages employees to work at least 3 consecutive shifts when they do work. This helps create more predictable work patterns and reduces fragmentation.

  ```json theme={null}
  {
    "id": "cc-min-3-shifts",
    "importance": "MEDIUM",
    "targets": {
      "min": 3
    }
  }
  ```
</Tip>

## Combining minimum and maximum

You can combine both `min` and `max` targets in a single constraint to create a preferred range of consecutive work periods. Note that when using `max`, the [importance](/constraints/index#constraint-importance) must be `STRICT` for the maximum limit to be enforced. The minimum target will be treated as a target that the solver will try to achieve.

<Tip>
  The below constraint encourages employees to work between 3 and 5 consecutive days when they do work. The solver will try to achieve at least 3 consecutive days (as a target), and will strictly prevent more than 5 consecutive days.

  ```json theme={null}
  {
    "id": "cc-3-to-5-days",
    "importance": "STRICT",
    "targets": {
      "min": 3,
      "max": 5
    }
  }
  ```
</Tip>

## Filtering by employees and shifts

You can combine both employee and shift [filters](/constraints/index#filters) to create very specific rules for certain groups of employees working certain types of shifts.

<Tip>
  The below constraint strictly limits senior employees to a maximum of 2 consecutive intensive shifts, while other employees are not affected.

  ```json theme={null}
  {
    "id": "cc-senior-intensive-max-2",
    "importance": "STRICT",
    "filters": {
      "employees": {
        "labels": ["senior"]
      },
      "shifts": {
        "labels": ["intensive"]
      }
    },
    "targets": {
      "max": 2
    }
  }
  ```
</Tip>
