# Vehicle

> Vehicles are the active resource being scheduled and aim to perform the tasks in the most efficient way.

Page: https://docs.icepack.ai/ivr/vehicle/

## Overview

Vehicles are the active resources in a schedule. The goal of the optimiser is to find an allocation of tasks to vehicles, and a sequence within each vehicle of the tasks assigned to it, that minimises the total cost. Without vehicles, there can be no schedule.

In the simplest case there may be a single vehicle. In a more complex case, there could be many vehicles, and our goal is to choose the most cost effective vehicles among them.

### Applicable models
* IVR7 `ivr7-kt461v8eoaif`
* IVR8 `ivr8-yni1c9k2swof`

<hr>

## Vehicle


### Schema definition 

```protobuf
message Vehicle {
  required string id = 1;
  required string classId = 2;
  required string costClassId = 3;
  required Shift shift = 4;
  repeated Capacity capacities = 5;
  repeated string transitRuleIds = 6;
  optional string compartmentSetId = 7; // IVR 8
}
```



### Fields

id
: The unqiue identifier for a vehicle. Duplicate vehicle id's within a model will result in an error being returned by the API.

classId
: The [vehicle class](/ivr/vehicle-class/) assigned to this vehicle. The class id should correspond to a provided [vehicle class](/ivr/vehicle-class/) object on the [model](/ivr/model/) instance.

costClassId
: The [vehicle cost class](/ivr/vehicle-cost-class/) assigned to this vehicle. The cost class id should correspond to a provided [vehicle cost class](/ivr/vehicle-cost-class/) object on the [model](/ivr/model/) instance.

shift
: The shift describes the start and end restrictions on this vehicle instance. It is typical to specify return time constraints on a vehicle which indicate the maximum duration of a particular vehicle-shift and the [location](/ivr/location/) where the vehicle is required to start and end its shift.

capacities
: The list of dimension capacities available to this vehicle instance. If empty, there are no capacity constraints on this particular vehicle.

transitRuleIds
: The optional [transit rule](/ivr/transit-rule/) assigned to this vehicle. If a [transit rule](/ivr/transit-rule/) has been associated with the [vehicle class](/ivr/vehicle-class) the specified [transit rule](/ivr/transit-rule/) on a vehicle level will override the [vehicle class](/ivr/vehicle-class/) [transit rule](/ivr/transit-rule/).

compartmentSetId
: The [compartment set](/ivr/compartment-set/) id assigned to this vehicle. If omitted, no compartment set is defined for the vehicle (default). If a [compartment set](/ivr/compartment-set/)  has been associated with the [vehicle class](/ivr/vehicle-class/), the specified [compartment set](/ivr/compartment-set/) on an individual vehicle level will override the [vehicle class](/ivr/vehicle-class/) [compartment set](/ivr/compartment-set/). 

### Examples

This example demonstrates how a two tonne vehicle (capacity dimension in Kg's) can be configured to begin and end its day at the Guinness Storehouse. The shift has a hard-constraint of starting no earlier than 07:00 and returning no later than 18:00 (time dimension measured in minutes).
```protobuf
id: "v-1"
classId: "vc1"
costClassId: "vcc1"
shift {
  shiftStart {
    locationId: "Guinness Storehouse"
    attributes {
      dimensionId: "time"
      quantity: 0
      windows {
        start: 420
        end: 1080
      }
    }
  }
  shiftEnd {
    locationId: "Guinness Storehouse"
    attributes {
      dimensionId: "time"
      quantity: 0
      windows {
        start: 420
        end: 1080
      }
    }
  }
}
capacities {
  dimensionId: "capacity"
  capacity: 2000
}
```



In this example there is a [vehicle class](/ivr/vehicle-class/) named `vc1` which determines the speed and interactions of this vehicle instance against the network. The costing of the vehicle movements are determined by `vcc1`, the [vehicle cost class](/ivr/vehicle-cost-class/) assigned to this vehicle instance. The [vehicle class](/ivr/vehicle-class/) and [cost class](/ivr/vehicle-cost-class/) are always required to correctly configure a vehicle. The capacity constraints for a vehicle are optional as well as the associated [transit rules](/ivr/transit-rules/) (advanced usage).

<hr> 

## Vehicle Shift
A vehicle shift provides a mechanism to define the start and end characteristics for a vehicle.

### Schema definition

```protobuf
message Shift {
  required Task shiftStart = 1;
  optional Task shiftEnd = 2;
}
```



### Fields

shiftStart
: The start of the vehicle shift.

shiftEnd
: The end of the vehicle shift. If omitted, the shiftStart is assumed to apply to the shiftEnd.

### Examples
This example illustrates a shift start that is at a different [location](/ivr/location/) to the end shift. This means that if the vehicle is used in the schedule, it should start at the Guinness Storehouse and end at St Stephen's Green.

```protobuf
shiftStart {
  locationId: "Guinness Storehouse"
  attributes {
    dimensionId: "time"
    quantity: 0
    windows {
      start: 420
      end: 480
    }
  }
}
shiftEnd {
  locationId: "St Stephen's Green"
  attributes {
    dimensionId: "time"
    quantity: 0
    windows {
      start: 0
      end: 1080
    }
  }
}
```



This next example illustrates a vehicle shift which omits the vehicle end shift. This means that the vehicle is required to return to the Guinness Storehouse after its last visit and return before 18:00 (time dimension measured in minutes).
```protobuf
shiftStart {
  locationId: "Guinness Storehouse"
  attributes {
    dimensionId: "time"
    quantity: 0
    windows {
      start: 420
      end: 1080
    }
  }
}
```



<hr> 

## Vehicle Task
The `vehicle.Task` definition is used to characterise the details of a vehicle shift.

### Schema definition 

```protobuf
message Task {
  required string locationId = 1;
  repeated Attribute attributes = 2;
}
```



### Fields

locationId
: The [location](/ivr/location/) id for the vehicle task.

attributes
: A list of attributes to be applied to the vehicle task. This may include aspects such as time or capacity [windows](/ivr/window/) which are specific to the vehicle-[location](/ivr/location/) combination.


### Examples

This example illustrates a valid shift (either start or end) which occurs at the Guinness Storehouse [location](/ivr/location/). There are no time [window](/ivr/window/) constraints on the shift. This would be the type of shift used to model a [TSP](/tsp/classic-tsp/) and is the minimum requirement for a shift:
```protobuf
locationId: "Guinness Storehouse"
```



<hr> 

## Vehicle Task Attibute
The `vehicle.Task.Attribute` definition is used to specify the attributes for a `vehicle.Task`.

### Schema definition 

```protobuf
message Attribute {
  required string dimensionId = 1;
  optional float quantity = 2;
  repeated Window windows = 3;
}
```



### Fields

dimensionId
: The [dimension](/ivr/dimension/) to which this attribute should be applied.

quantity
: The amount to be added to the associated dimension when executing the associated shift (typically zero or omitted).

windows
: An optional list of [window](/ivr/window/) objects applicable to this shift.

### Examples
This example illustrates a time window which begins at 07:00 and ends at 17:00 (time dimension measured in minutes) which can be applied as a set of attributes on a shift task.
```protobuf
attributes {
  dimensionId: "time"
  quantity: 0
  windows {
    start: 420
    end: 1020
  }
}
```



<hr> 

## Vehicle Capacity
The `vehicle.Capacity` definition is used to specify the global cumulative capacity limit for a vehicle. This is analogous to the maximum amount that can be carried by a vehicle at any point in the schedule.

### Schema definition 

```protobuf
message Capacity {
  required string dimensionId = 1;
  required float capacity = 2;
}
```



### Fields

dimensionId
: The id of the [dimension](/ivr/dimension/) to which the capacity limit should be applied. The dimension should be defined by the [dimension configuration](/ivr/dimension/) and quantities specified by [tasks](/ivr/task/) which contribute to the target dimension.

capacity
: The capacity limit for the associated [dimension](/ivr/dimension/) measured in the same base-units as the [dimension](/ivr/dimension/)

### Examples
This example illustrates two global maximum capacity constraints on the target vehicle across the `weight` dimension (measured in kilograms) and the `cubes` dimension (measured in metres cubed - a volumetric measurement) where the vehicle may not load more than 2 tonnes of product, or 8 "cubes" on the vehicle at any point in the schedule.

```protobuf
capacities {
  dimensionId: "weight"
  capacity: 2000
}
capacities {
  dimensionId: "cubes"
  capacity: 8
}
```



### Notes

* Currently capacitated dimensions are assumed to be independent of one another. If you're looking for behaviour which models the product of two dimensions (or some other arithmetic function between two or more dimensions), watch this space as there are some interesting use cases for this style of functionality.


<hr>

