Traffic Windows

Traffic windows refer to the time segments that have an effect on traffic costs. Obviously, heavy traffic will result in higher overall traffic costs.

The Optimization API returns all traffic windows by default. However, you can limit the size of the response by setting start and end times. With start and end times, the Optimization API will only return traffic windows which “touch” the start and end times. This example illustrates that use case.

Suppose you’re only interested in two-time windows that correspond to the morning commute. In this example, we set the start_local_time parameter to 9:00 am and the end_local_time parameter to 12:00.

In the response, the Optimization API has found two traffic windows (indexed 0 and 1) that intersect with these times. It uses this data to reduce the size of the matrix. You can review a sample traffic window below. Note that a single window consists of an index, a start time, and an end time. These windows are referenced by the travel cost object.

Note that the travel cost object refers to the actual matrix that the Optimization API calculates. It consists of the travel distance in meters and the travel cost for each window. The sample JSON provides comments to explain the output.

Sample Request

{
    "start_local_time": "09:00:00",
    "end_local_time": "12:00:00",
    "vehicle": {
        "type": "car"
    },
    "locations": [
        {
            "location_id": "a",
            "latitude": 33.937244,
            "longitude": -84.36947
        },
        {
            "location_id": "b",
            "latitude": 33.8875767,
            "longitude": -84.2613857
        },
        {
            "location_id": "c",
            "latitude": 33.8875767,
            "longitude": -84.2613857
        },
        {
            "location_id": "d",
            "latitude": 33.8968108,
            "longitude": -84.3276536
        },
        {
            "location_id": "e",
            "latitude": 33.8730743,
            "longitude": -84.3951042
        },
        {
            "location_id": "f",
            "latitude": 33.8940743,
            "longitude": -84.2151042
        }
    ]
}

Sample Response

{
    "locations": [
        {
            "location_id": "a",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "b",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "c",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "d",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "e",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "f",
            "time_zone": "America/New_York"
        }
    ],
    "status": "Ok",
    "traffic_windows": [
        {
            "traffic_window_end_times": [
                "09:30:00"
            ],
            "traffic_window_index": 0,
            "traffic_window_start_times": [
                "08:30:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "16:00:00"
            ],
            "traffic_window_index": 1,
            "traffic_window_start_times": [
                "09:30:00"
            ]
        }
    ],
    "travel_costs": {
        "a": {
            "a": [
                0,
                0,
                0
            ],
            "b": [
                16876.7,
                996.7,
                1057.6
            ],
            "c": [
                16876.7,
                996.7,
                1057.6
            ],
            "d": [
                9138.8,
                755,
                753.6
            ],
            "e": [
                9302.7,
                902.5,
                932.2
            ],
            "f": [
                22896.3,
                1342.3,
                1428.7
            ]
        },
        "b": {
            "a": [
                16409.7,
                1237,
                920.5
            ],
            "b": [
                0,
                0,
                0
            ],
            "c": [
                0,
                0,
                0
            ],
            "d": [
                8447.2,
                863.9,
                853.7
            ],
            "e": [
                20463,
                1483.7,
                1365
            ],
            "f": [
                7056.5,
                681.7,
                716.6
            ]
        },
        "c": {
            "a": [
                16409.7,
                1237,
                920.5
            ],
            "b": [
                0,
                0,
                0
            ],
            "c": [
                0,
                0,
                0
            ],
            "d": [
                8447.2,
                863.9,
                853.7
            ],
            "e": [
                20463,
                1483.7,
                1365
            ],
            "f": [
                7056.5,
                681.7,
                716.6
            ]
        },
        "d": {
            "a": [
                8524.2,
                723.5,
                679.5
            ],
            "b": [
                8447.2,
                810.4,
                846.3
            ],
            "c": [
                8447.2,
                810.4,
                846.3
            ],
            "d": [
                0,
                0,
                0
            ],
            "e": [
                8417.9,
                857.6,
                888
            ],
            "f": [
                17104.6,
                1164.3,
                1226.1
            ]
        },
        "e": {
            "a": [
                9405.1,
                946.2,
                953.6
            ],
            "b": [
                19974.8,
                1327,
                1374.5
            ],
            "c": [
                19974.8,
                1327,
                1374.5
            ],
            "d": [
                8340.7,
                858,
                884.8
            ],
            "e": [
                0,
                0,
                0
            ],
            "f": [
                25994.4,
                1672.6,
                1745.6
            ]
        },
        "f": {
            "a": [
                22056.7,
                1568.3,
                1246.3
            ],
            "b": [
                9776.1,
                679.8,
                703
            ],
            "c": [
                9776.1,
                679.8,
                703
            ],
            "d": [
                17708.8,
                1333.2,
                1179.5
            ],
            "e": [
                26110,
                1893.8,
                1690.8
            ],
            "f": [
                0,
                0,
                0
            ]
        }
    }
}