Location Classes with Force Containment

The meaning of "location classes with force containment" is requiring source location classes to be completely contained by the destination location classes. For example, if a skilled labor team has drywall and painting skills, we want that team to service job sites in need of drywall or painting skills, and not job sites in need of drywall, painting, AND electrical. The reason is obviously that a second team will have to cover the electrical work.

We abandon the vehicle-fueling station problem presented in the Sources and Destinations and Location Classes examples. Instead, let us consider three (3) teams of skilled technicians and six (6) job sites needing skilled labor. How would we submit a distance matrix to find which teams are closest to the job site most relevant to their skills? In this case, we’ll make use of the force_containment parameter.

Our teams can have one or all of the following skills:

Available SkillsClass
Painting0
Drywall1
Framing2
Concrete3
Electrical4
Plumbing5
HVAC6

To frame the problem further, listed below are our teams and their skills with associated classes for each:

TeamSkills
team-paint+concrete+hvacpaint (0), concrete (3), and hvac (6)
team-drywall+electricaldrywall (1) and electrical (4)
team-concrete+plumbingframing (2) and plumbing (5)

Our job sites in this example are:

Job SitesSkill Needs
jobsite-paint+hvacpaint (0) and hvac (6)
jobsite-paint+concrete+hvacpaint (0), concrete (3), hvac (6)
jobsite-drywalldrywall (1)
jobsite-drywall+electricaldrywall (1) and electrical (4)
jobsite-paint+framing+plumbingpaint (0), framing (2), plumbing (5)
jobsite-allAll

Unlike the prior examples where we broke down the problem into visual examples, the number of combinations here is too large to visualize simply. This is where the power of our Distance Matrix service shines!

To handle this complexity, all you need to do is apply the same location_class parameters as in the other examples, but this time we will add the force_containment parameter to ensure that when a job site needs multiple skills, ALL of those skill needs are met.

Sample Request

The complete request we will send to the Distance Matrix endpoint is given below.

{
    "force_containment": true,
    "sources": [
        0,
        1,
        2
    ],
    "destinations": [
        3,
        4,
        5,
        6,
        7,
        8
    ],
    "vehicle": {
        "type": "car"
    },
    "locations": [
        {
            "location_id": "team-paint+concrete+hvac",
            "latitude": 33.937244,
            "longitude": -84.36947,
            "location_class": [
                0,
                3,
                6
            ]
        },
        {
            "location_id": "team-drywall+electrical",
            "latitude": 33.887576,
            "longitude": -84.261385,
            "location_class": [
                1,
                4
            ]
        },
        {
            "location_id": "team-concrete+plumbing",
            "latitude": 33.887423,
            "longitude": -84.264241,
            "location_class": [
                2,
                5
            ]
        },
        {
            "location_id": "jobsite-paint+hvac",
            "latitude": 33.629444,
            "longitude": -84.527459,
            "location_class": [
                0,
                6
            ]
        },
        {
            "location_id": "jobsite-paint+concrete+hvac",
            "latitude": 33.936465,
            "longitude": -84.535648,
            "location_class": [
                0,
                3,
                6
            ]
        },
        {
            "location_id": "jobsite-drywall",
            "latitude": 33.242564,
            "longitude": -84.902184,
            "location_class": [
                1
            ]
        },
        {
            "location_id": "jobsite-drywall+electrical",
            "latitude": 33.253464,
            "longitude": -84.747494,
            "location_class": [
                1,
                4
            ]
        },
        {
            "location_id": "jobsite-paint+framing+plumbing",
            "latitude": 33.143353,
            "longitude": -84.938474,
            "location_class": [
                0,
                2,
                5
            ]
        },
        {
            "location_id": "jobsite-all",
            "latitude": 33.374749,
            "longitude": -84.389183,
            "location_class": [
                0,
                1,
                2,
                3,
                4,
                5,
                6
            ]
        }
    ]
}

Sample Response

The complete response we receive from the Distance Matrix endpoint is given below. As expected, we only have travel_costs which show going from sources to destinations where all of the destinations location_class needs are met. The results we get are:

  • team-concrete+plumbing is not eligible for any job site because the only job site in need of concrete and plumbing work also needs all the other types of skilled work (HVAC, paint, etc.), which this team does not possess. Thus there are no travel_costs returned for them.
  • team-drywall+electrical is eligible for the jobsite-drywall or jobsite-drywall+electrical because they are the only team which can handle both types of work.
  • team-paint+concrete+hvac is eligible for two job sites — jobsite-paint+concrete+hvac and jobsite-paint+hvac — because they have the overlapping skills needed.
  • The remaining job sites do not appear in the response because there are no teams which can fulfill all the skill needs and thus no viable solution is available.
{
    "locations": [
        {
            "location_id": "team-paint+concrete+hvac",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "team-drywall+electrical",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "team-concrete+plumbing",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "jobsite-paint+hvac",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "jobsite-paint+concrete+hvac",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "jobsite-drywall",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "jobsite-drywall+electrical",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "jobsite-paint+framing+plumbing",
            "time_zone": "America/New_York"
        },
        {
            "location_id": "jobsite-all",
            "time_zone": "America/New_York"
        }
    ],
    "status": "Ok",
    "traffic_windows": [
        {
            "traffic_window_end_times": [
                "06:30:00",
                "00:00:00"
            ],
            "traffic_window_index": 0,
            "traffic_window_start_times": [
                "00:00:00",
                "19:00:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "07:30:00"
            ],
            "traffic_window_index": 1,
            "traffic_window_start_times": [
                "06:30:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "08:30:00"
            ],
            "traffic_window_index": 2,
            "traffic_window_start_times": [
                "07:30:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "09:30:00"
            ],
            "traffic_window_index": 3,
            "traffic_window_start_times": [
                "08:30:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "16:00:00"
            ],
            "traffic_window_index": 4,
            "traffic_window_start_times": [
                "09:30:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "17:00:00"
            ],
            "traffic_window_index": 5,
            "traffic_window_start_times": [
                "16:00:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "18:00:00"
            ],
            "traffic_window_index": 6,
            "traffic_window_start_times": [
                "17:00:00"
            ]
        },
        {
            "traffic_window_end_times": [
                "19:00:00"
            ],
            "traffic_window_index": 7,
            "traffic_window_start_times": [
                "18:00:00"
            ]
        }
    ],
    "travel_costs": {
        "team-concrete+plumbing": {},
        "team-drywall+electrical": {
            "jobsite-drywall": [
                113724.2,
                4499.8,
                4491.5,
                4575.9,
                4619.7,
                4834.7,
                5953,
                6034.9,
                5340.7
            ],
            "jobsite-drywall+electrical": [
                101388.2,
                3766.8,
                3764.8,
                3839.4,
                3876.2,
                4083.6,
                5215.8,
                5300.1,
                4601.3
            ]
        },
        "team-paint+concrete+hvac": {
            "jobsite-paint+concrete+hvac": [
                19033.8,
                1260.7,
                1272.8,
                1372,
                1415.2,
                1446.4,
                1688.9,
                1730.4,
                1558.6
            ],
            "jobsite-paint+hvac": [
                44795.4,
                2125.7,
                2193.1,
                2375.6,
                2414.7,
                2686.2,
                4040.5,
                4097.6,
                3265.9
            ]
        }
    }
}