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

In this example we will show you how to use job relations. Job relations are defined on jobs. They can be used to
express different links between jobs:

* `SEQUENCE`: the jobs need to be visited in the given order
* `DIRECT_SEQUENCE`: the jobs need to be visited in the given order, one after the other
* `SAME_TRIP`: the jobs need to be visited in the same trip, the sequence does not matter
* `SAME_TIME`: the jobs need to be visited at the same time, the assigned resource will be different
* `PICKUP_AND_DELIVERY`: the jobs need to be in the same trip and the pickup needs to happen before the dropoff. (special case of job relation)
* `SAME_RESOURCE`: the jobs need to be visited by the same resource (could be another day)

## Sequence relation

```mermaid theme={null}
%%{init: {'theme':'neutral'}}%%
graph LR
    JOB1[Job 1] --> JOB2[Job 2] --> JOB3[Job 3]
```

```json sequence theme={null}
{
  "resources": [
    {
      "name": "R-1"
    },
    {
      "name": "R-2"
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "duration": 3600
    },
    {
      "name": "JOB-3",
      "duration": 3600
    }
  ],
  "relations": [
    {
      "type": "SEQUENCE",
      "jobs": [
        "JOB-1",
        "JOB-2",
        "JOB-3"
      ]
    }
  ]
}
```

## Direct Sequence relation

```mermaid theme={null}
%%{init: {'theme':'neutral'}}%%
graph LR
    JOB1[Job 1] --> JOB2[Job 2]
```

```json direct sequence theme={null}
{
  "resources": [
    {
      "name": "R-1"
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "duration": 3600
    },
    {
      "name": "JOB-3",
      "duration": 3600
    }
  ],
  "relations": [
    {
      "type": "DIRECT_SEQUENCE",
      "jobs": [
        "JOB-1",
        "JOB-2"
      ]
    }
  ]
}
```

## Same time relation

If there are Jobs that need multiple resources assigned to it,
you should duplicate those jobs and add the requirement that they should start at the same time.

```mermaid theme={null}
%%{init: {'theme':'neutral'}}%%
graph LR
    R1 --> JOB1[Job 1]
    R2 --> JOB2[Job 2]
```

```json same time theme={null}
{
  "resources": [
    {
      "name": "R-1"
    },
    {
      "name": "R-2"
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "duration": 3600
    },
    {
      "name": "JOB-3",
      "duration": 3600
    }
  ],
  "relations": [
    {
      "type": "SAME_TIME",
      "jobs": [
        "JOB-1",
        "JOB-2"
      ]
    }
  ]
}
```

## Pickup and delivery relation

A very specific case of a `SAME_TRIP` relation in combination with a `SEQUENCE` relation that requires first to do the pickup and then the delivery.
The shortcut is the `PICKUP_AND_DELIVERY` job relation for maximum two jobs, the first is the pickup, the second is the delivery.

```mermaid theme={null}
%%{init: {'theme':'neutral'}}%%
graph LR
    R1 --> J["Job 1 (pickup)"] --> A["Job x"] --> J2["Job 2 (delivery)"]
```

```json pickup and delivery theme={null}
{
  "resources": [
    {
      "name": "R-1"
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "duration": 3600
    },
    {
      "name": "JOB-3",
      "duration": 3600
    }
  ],
  "relations": [
    {
      "type": "PICKUP_AND_DELIVERY",
      "jobs": [
        "JOB-1",
        "JOB-2"
      ]
    }
  ]
}
```

## Same trip relation

If the sequence is independent but they need to be done in the same tour or trip or day, then you can use a `SAME_TRIP` relation.

```mermaid theme={null}
%%{init: {'theme':'neutral'}}%%
graph LR
    R1 --> JOB-1 --> JOB-2
    R2 --> JOB-3
```

```json same trip theme={null}
{
  "resources": [
    {
      "name": "R-1"
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "duration": 3600
    },
    {
      "name": "JOB-3",
      "duration": 3600
    }
  ],
  "relations": [
    {
      "type": "SAME_TRIP",
      "jobs": [
        "JOB-1",
        "JOB-2"
      ]
    }
  ]
}
```

## Same resource relation

If a job needs to be done by the same resource throughout the planning period, then set the `SAME_RESOURCE` relation.

```mermaid theme={null}
%%{init: {'theme':'neutral'}}%%
graph LR
    R1["R1(2025-01-01)"] --> JOB-1 --> JOB-3
    R2["R1(2025-01-03)"] --> JOB-2
```

```json same resource theme={null}
{
  "resources": [
    {
      "name": "R-1"
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "duration": 3600
    },
    {
      "name": "JOB-3",
      "duration": 3600
    }
  ],
  "relations": [
    {
      "type": "SAME_RESOURCE",
      "jobs": [
        "JOB-1",
        "JOB-2"
      ]
    }
  ]
}
```
