1.6. Exemplo 3 - Integração com Trip API

A Planning API é responsável por retornar a ordenação dos pontos logísticos da forma mais otimizada possível, mas podemos utilizá-la com a Trip API para obter também a melhor rota entre os pontos.

Neste exemplo, temos uma requisição para Planning API com integração a Trip API para resolver um problema logístico de 2 veículos e 10 operações, partindo do centro de distribuição.


Parâmetros utilizados

Planning:

"optimizationProfile": "BRAZIL46". Para essa simulação, foi usado o perfil de otimização BRAZIL46. Para os tipos disponíveis, verifique em optimizationProfile.

"tripsProfile": "MAPLINK". Utilizamos o perfil que contém o mapa mais atualizado e configurado para utilizar o modo de cálculo para utilizar vias mais rápidas.

"startDate": "1620298800000". Horário de início de referência para o cálculo da otimização logística.

"legislationProfiles": Parâmetro com o nome do perfil que se aplica ao tempo de direção, duração de um dia de trabalho ou intervalo. Neste caso não há nenhuma característica definida.

"logisticConstraints": Restrições logísticas usadas para determinar o tempo fixo de carregamento e descarregamento da carga. Nesse exemplo, foi usado 1800 segundos (30 minutos) para o tempo de carregamento do caminhão e 300 segundos (5 minutos) para o descarregamento na entrega.

"products": Nome para referenciar o produto.

"sites": Localização onde ocorrerão as atividades de entregas, com definição do nome e a restrição logística com o tempo de entrega.

"depots": Localização do centro de distribuição, com definição do nome e a restrição logística com o tempo de carregamento do caminhão.

"vehicleTypes" : Neste parâmetro especificamos a capacidade de carga dos veículos da frota, como volume e peso máximos e o tamanho dentro de um intervalo de 1 a 9, e o nome da tipologia.

"vehicles": Foram especificados os veículos que estão disponíveis para executar a rota. Se define também o período de trabalho e o perfil de legislação aplicável ao motorista. Foi definido que os veículos sairão e retornarão ao centro de distribuição.

"operations" : São as características das operações de entregas, definindo o local, peso e volume, produto, tipo de atividade, centro de distribuição da origem do produto e o horário que o cliente irá receber. 

 Trip:

"calculationMode" : Foi definido que o módulo de cálculo da rota seria o mais rápido (“THE FASTEST”).

"crossedBorders": Indica o retorno das cidades que a rota cruzará.

"toll": Indica que a rota deverá informar o cálculo do pedágio.

"freight": Foram definidos os parâmetros que retornam os cálculos referente ao Piso Mínimo do Frete.

Request

{ "optimizationProfile": "BRAZIL46", "tripsProfile": "MAPLINK", "startDate": 1620298800000, "legislationProfiles": [ { "name": "DEFAULT" } ], "logisticConstraints": [ { "name": "P1Pickup", "siteLoadingFixedTime": 1800 }, { "name": "P1Delivery", "siteUnloadingFixedTime": 300 } ], "products": [ { "name": "DEFAULT" } ], "sites": [ { "name": "Cliente1", "coordinates": { "latitude": -23.507608, "longitude": -46.587145 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente2", "coordinates": { "latitude": -23.621059, "longitude": -46.756193 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente3", "coordinates": { "latitude": -23.44935, "longitude": -46.588822 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente4", "coordinates": { "latitude": -23.751801, "longitude": -46.698468 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente5", "coordinates": { "latitude": -23.520565, "longitude": -46.508478 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente6", "coordinates": { "latitude": -23.506592, "longitude": -46.524707 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente7", "coordinates": { "latitude": -23.646993, "longitude": -46.779077 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente8", "coordinates": { "latitude": -23.373816, "longitude": -46.57777 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente9", "coordinates": { "latitude": -23.476158, "longitude": -46.640241 }, "logisticConstraints": "P1Delivery" }, { "name": "Cliente10", "coordinates": { "latitude": -23.761565, "longitude": -46.655746 }, "logisticConstraints": "P1Delivery" } ], "depots": [ { "name": "CD", "coordinates": { "latitude": -23.503939, "longitude": -46.498419 }, "logisticConstraints": "P1Pickup" } ], "vehicleTypes": [ { "name": "3/4", "maxWeight": 15000, "maxVolume": 30, "size": 1 } ], "vehicles": [ { "name": "3/4_1", "vehicleType": "3/4", "legislationProfile": "DEFAULT", "availablePeriods": [ { "departureSite": "CD", "arrivalSite": "CD", "maxRoutesNumber": 1, "timeWindow": { "start": 1620298800000, "end": 1620334800000 } } ] }, { "name": "3/4_2", "vehicleType": "3/4", "legislationProfile": "DEFAULT", "availablePeriods": [ { "departureSite": "CD", "arrivalSite": "CD", "maxRoutesNumber": 1, "timeWindow": { "start": 1620298800000, "end": 1620334800000 } } ] } ], "operations": [ { "id": "P1", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente1", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P2", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente2", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P3", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente3", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P4", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente4", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P5", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente4", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P6", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente6", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P7", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente7", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P8", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente8", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P9", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente9", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] }, { "id": "P10", "weight": 2, "volume": 2, "product": "DEFAULT", "type": "DELIVERY", "depotSite": "CD", "customerSite": "Cliente10", "customerTimeWindows": [ { "start": 1620302400000, "end": 1620309600000 } ] } ], "trip": { "calculationMode": "THE_FASTEST", "crossedBorders": { "level": "CITY" }, "toll": { "vehicleType": "TRUCK_WITH_TWO_DOUBLE_AXLES" }, "freight": { "operationType": [ "A", "D" ], "goodsType": [ "GRANEL_LIQUIDO", "GRANEL_SOLIDO" ], "axis": [ "2", "4" ], "roundTrip": false, "backEmpty": false, "otherCosts": [ { "name": "ICMS", "type": "PERCENT", "value": "5" }, { "name": "Lucro", "type": "PERCENT", "value": "20" }, { "name": "TaxaFixa", "type": "FIXED", "value": "500" } ], "date": "2021-10-02" } } }


Response

Na resposta da API, em cada rota irá constar o tripId, que poderá ser consultada através do endpoint https://api.maplink.global/trip/v1/solutions/{{tripjobid}}.

A resposta abaixo encontra-se truncada para facilitar a leitura.

{     "id": "62ff87d0c19aa95741dfff68",     "clientId": "maplink",     "vehicleRoutes": [         {             "routes": [                 {                     "id": "NewRoute_1_1",                     "activities": [                         {                             "activity": "ROUTE_START",                             "timeWindow": {                                 "start": 1620298800000,                                 "end": 1620298800000                             },                             "type": "SITE",                             "site": "CD",                             "operations": []                         },                         ---- TRUNCADO                         {                             "activity": "ROUTE_END",                             "timeWindow": {                                 "start": 1620311708000,                                 "end": 1620311708000                             },                             "type": "SITE",                             "site": "CD",                             "operations": []                         }                     ],                     "tripId": "62ff87d4c007780a2ed8f7cb"                 }             ],             "vehicle": "3/4_1",             "period": {                 "timeWindow": {                     "start": 1620298800000,                     "end": 1620334800000                 },                 "departureSite": "CD",                 "arrivalSite": "CD",                 "maxRoutesNumber": 1             }         },         {             "routes": [                 {                     "id": "NewRoute_2_1",                     "activities": [                         {                             "activity": "ROUTE_START",                             "timeWindow": {                                 "start": 1620299268000,                                 "end": 1620299268000                             },                             "type": "SITE",                             "site": "CD",                             "operations": []                         },                         ---- TRUNCADO                         {                             "activity": "ROUTE_END",                             "timeWindow": {                                 "start": 1620308938000,                                 "end": 1620308938000                             },                             "type": "SITE",                             "site": "CD",                             "operations": []                         }                     ],                     "tripId": "62ff87d4eeeb972ff55c6f16"                 }             ],             "vehicle": "3/4_2",             "period": {                 "timeWindow": {                     "start": 1620298800000,                     "end": 1620334800000                 },                 "departureSite": "CD",                 "arrivalSite": "CD",                 "maxRoutesNumber": 1             }         }     ],     "indicators": {         "totalServiceTime": 6300,         "totalDeliveringTime": 2700,         "dayWorkingTotalTime": 22578,         "nightWorkingTotalTime": 0,         "totalUnloadingTime": 0,         "totalWorkingTime": 22578,         "totalCollectingTime": 0,         "timeWindowNumber": 2,         "totalDrivingTime": 16278,         "totalLoadingTime": 3600,         "totalTime": 22578,         "totalDistance": 191609,         "averageOccupancyRateVolume": 33.33,         "averageOccupancyRateWeight": 0.07,         "rejectOperationsNumber": 0,         "totalWaitingTime": 0,         "totalRestTime": 0,         "routesNumber": 2,         "tollCosts": 0     } }


A resposta completa pode ser obtida no arquivo em anexo.

 

Solução do problema logístico



Os seguintes indicadores globais são retornados:

Indicador

Resultado

Tempo total de serviço

01:45:00

Tempo total de entrega

00:45:00

Tempo total de trabalho diurno

06:16:18

Tempo total de trabalho noturno

00:00:00

Tempo total de descarregamento

00:00:00

Tempo total de trabalho

06:16:18

Tempo total de coleta

00:00:00

Número de janelas de horário

2

Tempo total de condução

04:31:18

Tempo total de carregamento

01:00:00

Tempo total

06:16:18

Distância total

191.61 km

Taxa de ocupação média em Volume

33.33

Taxa de ocupação média em Peso

0.07

Número de rejeições

0

Tempo total de espera

00:00:00

Tempo total de descanso

00:00:00

Número de rotas

2

A resposta também retorna a sequência temporal de atividades de cada veículo. Esse é um exemplo do veículo de nome “3/4_1”:

VEÍCULO

ATIVIDADE

ID DO LOCAL DE PARTIDA

ID DO LOCAL DE RETORNO

DISTÂNCIA

DURAÇÃO NOMINAL

JANELA DE HORÁRIO INICIAL

JANELA DE HORÁRIO FINAL

3/4_1

ROUTE_START

CD

 

 

 

06/05/21 08:00

06/05/21 08:00

3/4_1

LOADING

CD

 

 

 

06/05/21 08:00

06/05/21 08:30

3/4_1

DRIVING

CD

Cliente2

37.96 km

00:50:38

06/05/21 08:30

06/05/21 09:20

3/4_1

DELIVERY

Cliente2

 

 

 

06/05/21 09:20

06/05/21 09:25

3/4_1

DRIVING

Cliente2

Cliente7

4.77 km

00:07:27

06/05/21 09:25

06/05/21 09:33

3/4_1

DELIVERY

Cliente7

 

 

 

06/05/21 09:33

06/05/21 09:38

3/4_1

DRIVING

Cliente7

Cliente10

26.91 km

00:35:36

06/05/21 09:38

06/05/21 10:13

3/4_1

DELIVERY

Cliente10

 

 

 

06/05/21 10:13

06/05/21 10:18

3/4_1

DRIVING

Cliente10

Cliente4

5.47 km

00:10:25

06/05/21 10:18

06/05/21 10:29

3/4_1

DELIVERY

Cliente4

 

 

 

06/05/21 10:29

06/05/21 10:34

3/4_1

DRIVING

Cliente4

CD

45.25 km

01:01:02

06/05/21 10:34

06/05/21 11:35

3/4_1

ROUTE_END

CD

 

 

 

06/05/21 11:35

06/05/21 11:35