From 6775c3f3da72df364f9134f6c4cbf7e7410ae293 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 27 Apr 2019 00:02:21 +0300 Subject: [PATCH] - updated the code in camlib.CNCJob.generate_from_excellon_by_tools() to work with the new API from Google OR-Tools --- README.md | 1 + camlib.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d5486bab..70bb18ea 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ CAD program, and create G-Code for Isolation routing. - made sure that the Project Tab is disabled while one of the Editors is active and it is restored after returning to app - fixed some bugs recently introduced in Editors due of the changes done to the way mouse panning is detected - cleaned up the context menu's when in Editors; made some structural changes +- updated the code in camlib.CNCJob.generate_from_excellon_by_tools() to work with the new API from Google OR-Tools 25.04.2019 diff --git a/camlib.py b/camlib.py index 13ff1b60..8270add1 100644 --- a/camlib.py +++ b/camlib.py @@ -5288,8 +5288,13 @@ class CNCjob(Geometry): y2 = locations[to_node][1] self.matrix[from_node][to_node] = distance_euclidian(x1, y1, x2, y2) - def Distance(self, from_node, to_node): - return int(self.matrix[from_node][to_node]) + # def Distance(self, from_node, to_node): + # return int(self.matrix[from_node][to_node]) + def Distance(self, from_index, to_index): + # Convert from routing variable Index to distance matrix NodeIndex. + from_node = manager.IndexToNode(from_index) + to_node = manager.IndexToNode(to_index) + return self.matrix[from_node][to_node] # Create the data. def create_data_array(): @@ -5327,8 +5332,9 @@ class CNCjob(Geometry): depot = 0 # Create routing model. if tsp_size > 0: - routing = pywrapcp.RoutingModel(tsp_size, num_routes, depot) - search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters() + manager = pywrapcp.RoutingIndexManager(tsp_size, num_routes, depot) + routing = pywrapcp.RoutingModel(manager) + search_parameters = pywrapcp.DefaultRoutingSearchParameters() search_parameters.local_search_metaheuristic = ( routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH) @@ -5343,7 +5349,8 @@ class CNCjob(Geometry): # arguments (the from and to node indices) and returns the distance between them. dist_between_locations = CreateDistanceCallback() dist_callback = dist_between_locations.Distance - routing.SetArcCostEvaluatorOfAllVehicles(dist_callback) + transit_callback_index = routing.RegisterTransitCallback(dist_callback) + routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index) # Solve, returns a solution if any. assignment = routing.SolveWithParameters(search_parameters) @@ -5432,14 +5439,16 @@ class CNCjob(Geometry): # Create routing model. if tsp_size > 0: - routing = pywrapcp.RoutingModel(tsp_size, num_routes, depot) - search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters() + manager = pywrapcp.RoutingIndexManager(tsp_size, num_routes, depot) + routing = pywrapcp.RoutingModel(manager) + search_parameters = pywrapcp.DefaultRoutingSearchParameters() # Callback to the distance function. The callback takes two # arguments (the from and to node indices) and returns the distance between them. dist_between_locations = CreateDistanceCallback() dist_callback = dist_between_locations.Distance - routing.SetArcCostEvaluatorOfAllVehicles(dist_callback) + transit_callback_index = routing.RegisterTransitCallback(dist_callback) + routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index) # Solve, returns a solution if any. assignment = routing.SolveWithParameters(search_parameters)