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

# Lock Assignments

> Pre-assign employees to shifts with optional locking for warm starts

Use assignments to set an initial schedule or lock specific employee-shift pairings that the solver cannot change.

## Use Cases

* **Warm start** - Provide an initial solution for faster optimization
* **Fixed assignments** - Lock confirmed shifts that cannot change
* **Partial planning** - Keep some assignments fixed while optimizing others
* **Incremental scheduling** - Add new shifts while preserving existing schedule

## Warm Start

Provide an initial schedule without locking to help the solver find better solutions faster:

```json theme={null}
{
  "employees": [
    { "name": "Alice" },
    { "name": "Bob" },
    { "name": "Carol" }
  ],
  "shifts": [
    { "name": "shift-1", "from": "2024-01-01T08:00:00", "to": "2024-01-01T16:00:00", "min": 1, "max": 1 },
    { "name": "shift-2", "from": "2024-01-02T08:00:00", "to": "2024-01-02T16:00:00", "min": 1, "max": 1 }
  ],
  "assignments": [
    { "employee": "Alice", "shift": "shift-1", "locked": false },
    { "employee": "Bob", "shift": "shift-2", "locked": false }
  ]
}
```

<Info>
  With `locked: false`, the solver uses these assignments as a starting point but may reassign them if a better solution exists.
</Info>

## Locked Assignments

Lock assignments that must not change:

```json theme={null}
{
  "employees": [
    { "name": "Alice" },
    { "name": "Bob" },
    { "name": "Carol" }
  ],
  "shifts": [
    { "name": "shift-1", "from": "2024-01-01T08:00:00", "to": "2024-01-01T16:00:00", "min": 1, "max": 1 },
    { "name": "shift-2", "from": "2024-01-02T08:00:00", "to": "2024-01-02T16:00:00", "min": 1, "max": 1 },
    { "name": "shift-3", "from": "2024-01-03T08:00:00", "to": "2024-01-03T16:00:00", "min": 1, "max": 1 }
  ],
  "assignments": [
    { "employee": "Alice", "shift": "shift-1", "locked": true },
    { "employee": "Bob", "shift": "shift-2", "locked": true }
  ]
}
```

<Warning>
  Locked assignments are treated as hard constraints. If they conflict with other hard constraints (e.g., skills, availability), the solution becomes infeasible.
</Warning>

## Assignment Properties

<ParamField body="shift" type="string" required>
  Name of the shift to assign
</ParamField>

<ParamField body="employee" type="string" required>
  Name of the employee to assign
</ParamField>

<ParamField body="locked" type="boolean" default="false">
  When `true`, the solver cannot modify this assignment
</ParamField>

## Mixed Locking

Combine locked and unlocked assignments for partial replanning:

```json theme={null}
{
  "assignments": [
    { "employee": "Alice", "shift": "shift-1", "locked": true },
    { "employee": "Bob", "shift": "shift-2", "locked": false },
    { "employee": "Carol", "shift": "shift-3", "locked": false }
  ]
}
```

<Check>
  Alice stays on `shift-1`. Bob and Carol's assignments serve as suggestions that the solver may improve.
</Check>

## Best Practices

<AccordionGroup>
  <Accordion title="When to use warm start">
    * Large problems where finding any solution is slow
    * Incremental changes to existing schedules
    * Testing "what-if" scenarios from a known state
  </Accordion>

  <Accordion title="When to lock assignments">
    * Employee has confirmed the shift
    * Contractual obligations require specific assignments
    * External constraints not modeled in the API
  </Accordion>

  <Accordion title="Avoid locking pitfalls">
    * Don't lock assignments that violate skills or availability
    * Leave flexibility for the solver to optimize
    * Use `locked: false` for preferences, `locked: true` only for requirements
  </Accordion>
</AccordionGroup>
