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

# Job Complexity

> Balance workload across resources using job complexity scoring

# Job Complexity

Job complexity allows you to assign difficulty scores to jobs and ensure fair workload distribution across resources. This feature helps balance not just the number of jobs or time spent, but the actual difficulty and mental/physical load on workers.

## Overview

The complexity feature enables:

* Assigning complexity scores to jobs based on difficulty
* Fair distribution of complex work across resources
* Setting min/max complexity limits per resource period
* Balancing complexity per trip or per resource

## Basic Complexity Configuration

### Setting Job Complexity

Assign complexity values to jobs on a scale that makes sense for your business:

```json theme={null}
{
  "jobs": [
    {
      "name": "simple-delivery",
      "location": {"latitude": 52.520, "longitude": 13.405},
      "duration": 1800,
      "complexity": 1  // Simple task
    },
    {
      "name": "technical-installation",
      "location": {"latitude": 52.523, "longitude": 13.401},
      "duration": 3600,
      "complexity": 5  // Complex task requiring expertise
    },
    {
      "name": "hazardous-material-handling",
      "location": {"latitude": 52.517, "longitude": 13.388},
      "duration": 2700,
      "complexity": 8  // High complexity due to safety requirements
    }
  ],
  "resources": [
    {
      "name": "senior-tech",
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    },
    {
      "name": "junior-tech",
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ]
}
```

<Tip>
  Choose a complexity scale that reflects your business needs. Common scales include:

  * 1-10 (simple to very complex)
  * 1-100 (fine-grained difficulty)
  * 1-5 (basic categorization)
</Tip>

## Fair Complexity Distribution

### Balancing Complexity Per Trip

Ensure each trip has a balanced mix of complex and simple jobs:

```json theme={null}
{
  "options": {
    "fairComplexityPerTrip": true
  },
  "jobs": [
    {
      "name": "complex-repair",
      "complexity": 8,
      "duration": 3600
    },
    {
      "name": "routine-check-1",
      "complexity": 2,
      "duration": 1200
    },
    {
      "name": "routine-check-2",
      "complexity": 2,
      "duration": 1200
    },
    {
      "name": "moderate-task",
      "complexity": 5,
      "duration": 2400
    }
  ]
}
```

### Balancing Complexity Per Resource

Distribute total complexity fairly across all resources:

```json theme={null}
{
  "options": {
    "fairComplexityPerResource": true
  },
  "weights": {
    "fairComplexityPerResourceWeight": 100  // Importance of fair distribution
  }
}
```

<Info>
  The solver will try to ensure each resource gets a similar total complexity score across their shifts, preventing burnout from consistently handling difficult tasks.
</Info>

## Resource Period Complexity Limits

Set minimum and maximum complexity constraints per period:

```json theme={null}
{
  "resources": [
    {
      "name": "experienced-tech",
      "periods": [
        {
          "name": "weekly-limit",
          "period": "WEEK",
          "maxComplexity": 100,  // Max 100 complexity points per week
          "minComplexity": 20    // At least 20 points (avoid underutilization)
        }
      ],
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    },
    {
      "name": "new-tech",
      "periods": [
        {
          "name": "training-period",
          "period": "DAY",
          "maxComplexity": 15  // Limited complexity during training
        }
      ],
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ]
}
```

## Use Cases

### Skill-Based Workload Management

Balance complex technical work across skilled technicians:

```json theme={null}
{
  "jobs": [
    {
      "name": "server-migration",
      "complexity": 10,  // Highest complexity
      "tags": [{"name": "senior-only", "hard": true}]
    },
    {
      "name": "cable-installation",
      "complexity": 3,
      "tags": [{"name": "certified-tech", "hard": true}]
    },
    {
      "name": "routine-maintenance",
      "complexity": 1
    }
  ],
  "options": {
    "fairComplexityPerResource": true
  }
}
```

### Physical Demand Balancing

Distribute physically demanding tasks fairly:

```json theme={null}
{
  "jobs": [
    {
      "name": "heavy-lifting-delivery",
      "complexity": 8,  // High physical demand
      "load": [200]     // 200kg
    },
    {
      "name": "document-delivery",
      "complexity": 1,  // Low physical demand
      "load": [5]       // 5kg
    }
  ],
  "resources": [
    {
      "name": "driver-1",
      "periods": [{
        "period": "DAY",
        "maxComplexity": 40  // Limit daily physical strain
      }]
    }
  ]
}
```

### Mental Load Distribution

Balance cognitively demanding tasks:

```json theme={null}
{
  "jobs": [
    {
      "name": "security-audit",
      "complexity": 9,  // High mental load
      "duration": 14400 // 4 hours
    },
    {
      "name": "routine-inspection",
      "complexity": 2,  // Low mental load
      "duration": 3600  // 1 hour
    }
  ],
  "options": {
    "fairComplexityPerTrip": true  // Mix complex and simple in each trip
  }
}
```

## Integration with Other Features

### With Tags and Skills

Combine complexity with skill requirements:

```json theme={null}
{
  "jobs": [
    {
      "name": "advanced-repair",
      "complexity": 8,
      "tags": [
        {"name": "certified", "hard": true},
        {"name": "experienced", "weight": 50}
      ]
    }
  ]
}
```

### With Time Windows

Complex jobs during optimal hours:

```json theme={null}
{
  "jobs": [
    {
      "name": "precision-work",
      "complexity": 10,
      "windows": [
        ["2024-03-15T09:00:00Z", "2024-03-15T12:00:00Z"]  // Morning when fresh
      ]
    }
  ]
}
```

## Best Practices

<Steps>
  <Step title="Define Clear Complexity Scale">
    Create a documented scale that all planners understand and apply consistently
  </Step>

  <Step title="Consider Multiple Factors">
    Include physical demand, mental load, risk level, and skill requirements in complexity scores
  </Step>

  <Step title="Monitor Distribution">
    Use the solution's complexity distribution to ensure fairness over time
  </Step>

  <Step title="Adjust Weights">
    Fine-tune `fairComplexityPerResourceWeight` and `fairComplexityPerTripWeight` based on your priorities
  </Step>
</Steps>

## Constraints and Violations

The following constraints relate to complexity:

| Constraint                       | Description                             | Type   |
| -------------------------------- | --------------------------------------- | ------ |
| `RESOURCE_PERIOD_MAX_COMPLEXITY` | Exceeded maximum complexity in period   | hard   |
| `RESOURCE_PERIOD_MIN_COMPLEXITY` | Below minimum complexity in period      | medium |
| `FAIR_COMPLEXITY_PER_TRIP`       | Uneven complexity distribution in trips | soft   |
| `FAIR_COMPLEXITY_PER_RESOURCE`   | Uneven complexity across resources      | soft   |

## Tips for Implementation

<Warning>
  **Start Conservative**: Begin with optional complexity (soft constraints) before making them mandatory. This helps identify appropriate limits.
</Warning>

<Tip>
  **Review Regularly**: Analyze complexity distribution in solutions to refine your scoring system and limits.
</Tip>

<Info>
  **Combine with Fairness**: Use complexity alongside the general work fairness features for comprehensive workload balancing.
</Info>

## Related Features

<CardGroup cols={2}>
  <Card title="Resource Management" icon="users" href="/guides/vrp/features/resource-management">
    Configure resource capabilities and periods
  </Card>

  <Card title="Fair Work Distribution" icon="balance-scale" href="/guides/vrp/features/advanced-constraints#fairness-constraints">
    General work fairness features
  </Card>

  <Card title="Tag & Ranking" icon="tags" href="/guides/vrp/features/tag-ranking">
    Skill-based job assignment
  </Card>

  <Card title="Time Scheduling" icon="clock" href="/guides/vrp/features/time-scheduling-advanced">
    Coordinate complex jobs with timing
  </Card>
</CardGroup>
