Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimally Creating and Assigning Work Orders Based on Routes #99

Open
MVAC13 opened this issue Feb 22, 2022 · 2 comments
Open

Optimally Creating and Assigning Work Orders Based on Routes #99

MVAC13 opened this issue Feb 22, 2022 · 2 comments

Comments

@MVAC13
Copy link

MVAC13 commented Feb 22, 2022

Hello,
In the 'Optimally Creating and Assigning Work Orders Based on Routes' notebook there is the following code:

assignments_to_add = []
for _, row in routes.iterrows():
    worker = random.choice(workers)
    workers.remove(worker)
    route_stops = stops.loc[(stops['RouteName'] == row["RouteName"]) & stops['globalid'].notnull()]
    for _, stop in route_stops.iterrows():
        assignments_to_add.append(workforce.Assignment(
            project,
            assignment_type="Inspection",
            location=stop["name"],
            status="assigned",
            worker=worker,
            assigned_date=datetime.now(),
            due_date=stop["DepartTime"],
            geometry=stop["SHAPE"]
        ))
assignments = project.assignments.batch_add(assignments_to_add)

I think the line workers.remove(worker) should be removed because then in assignments_to_add.append() the worker=worker will give an error of empty list. Am I wrong?

Thanks

@apulverizer
Copy link
Contributor

@MVAC13 In the example, we create the same number or routes as workers.

results = arcgis.features.analysis.plan_routes(breweries_layer, # Feature Layer of Stops
                                    len(workers),               # Number of routes to generate
                                    5,                          # Maximum stops per route
                                    datetime.now(),             # Start time of route
                                    start_layer,                # The dictionary we created to represent the start location
                                    stop_service_time=60,       # How much time in minutes to spend at each stop
                                    max_route_time=480,         # The maximum time for the worker to complete the route
                                    )

We then iterate over each route and select a worker, and remove that worker from the possible list of workers to chose (so that a worker only is assigned one route). Then for each stop in the route we create an assignment and assign it to the selected worker.

Then after all assignments for all routes have been created, we add them to the project.

If workers.remove(worker) was removed, a worker could be assigned to multiple routes which doesn't make sense from a practical standpoint.

Does that help explain it?

@MVAC13
Copy link
Author

MVAC13 commented Feb 23, 2022

It does explain it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants