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

export const ConsecutiveMetricRows = () => <tr>
    <td><code className="whitespace-nowrap">CONSECUTIVE.MIN_VIOLATIONS</code></td>
    <td>Number of consecutive-work groups that are shorter than the configured minimum.</td>
  </tr>;

This rule 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="Rule schema">
  <ResponseField name="consecutiveRule" 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 rule.
      </ResponseField>

      <ResponseField name="labels" type="array of string">
        Labels for the rule. Labels can be used to group rules together. For example, if multiple rules 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 rule. The higher the importance, the more it will be taking the rule into account. Under strict importance, the rule may never be violated.
      </ResponseField>

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

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

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

          <ResponseField name="labels" type="array of string">
            List of employee labels that the rule 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 rule should be applied to. If not specified, the rule applies to all shifts.
        </ResponseField>

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

          <ResponseField name="labels" type="array of string">
            List of shift labels that the rule 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>
        Defines targets and limits on the number of consecutive shifts that an employee works.
      </ResponseField>

      <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](/v2/rules/index#rule-importance), meaning the solver will never violate it.

<Tip>
  The rule below 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 rule below 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 rule to create a preferred range of consecutive work periods. Note that when using `max`, the [importance](/v2/rules/index#rule-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 rule below 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](/v2/rules/index#filters) to create very specific rules for certain groups of employees working certain types of shifts.

<Tip>
  The rule below 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>

## Metrics

The following [status metric](/v2/concepts/metrics) is available for tracking on Consecutive rules:

<table>
  <thead><tr><th>Metric key</th><th>Description</th></tr></thead>

  <tbody>
    <ConsecutiveMetricRows />
  </tbody>
</table>
