- updated the code in camlib.CNCJob.generate_from_excellon_by_tools() to work with the new API from Google OR-Tools
This commit is contained in:
parent
faf92ff3d9
commit
6775c3f3da
|
@ -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
|
- 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
|
- 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
|
- 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
|
25.04.2019
|
||||||
|
|
||||||
|
|
25
camlib.py
25
camlib.py
|
@ -5288,8 +5288,13 @@ class CNCjob(Geometry):
|
||||||
y2 = locations[to_node][1]
|
y2 = locations[to_node][1]
|
||||||
self.matrix[from_node][to_node] = distance_euclidian(x1, y1, x2, y2)
|
self.matrix[from_node][to_node] = distance_euclidian(x1, y1, x2, y2)
|
||||||
|
|
||||||
def Distance(self, from_node, to_node):
|
# def Distance(self, from_node, to_node):
|
||||||
return int(self.matrix[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.
|
# Create the data.
|
||||||
def create_data_array():
|
def create_data_array():
|
||||||
|
@ -5327,8 +5332,9 @@ class CNCjob(Geometry):
|
||||||
depot = 0
|
depot = 0
|
||||||
# Create routing model.
|
# Create routing model.
|
||||||
if tsp_size > 0:
|
if tsp_size > 0:
|
||||||
routing = pywrapcp.RoutingModel(tsp_size, num_routes, depot)
|
manager = pywrapcp.RoutingIndexManager(tsp_size, num_routes, depot)
|
||||||
search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()
|
routing = pywrapcp.RoutingModel(manager)
|
||||||
|
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
|
||||||
search_parameters.local_search_metaheuristic = (
|
search_parameters.local_search_metaheuristic = (
|
||||||
routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)
|
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.
|
# arguments (the from and to node indices) and returns the distance between them.
|
||||||
dist_between_locations = CreateDistanceCallback()
|
dist_between_locations = CreateDistanceCallback()
|
||||||
dist_callback = dist_between_locations.Distance
|
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.
|
# Solve, returns a solution if any.
|
||||||
assignment = routing.SolveWithParameters(search_parameters)
|
assignment = routing.SolveWithParameters(search_parameters)
|
||||||
|
@ -5432,14 +5439,16 @@ class CNCjob(Geometry):
|
||||||
|
|
||||||
# Create routing model.
|
# Create routing model.
|
||||||
if tsp_size > 0:
|
if tsp_size > 0:
|
||||||
routing = pywrapcp.RoutingModel(tsp_size, num_routes, depot)
|
manager = pywrapcp.RoutingIndexManager(tsp_size, num_routes, depot)
|
||||||
search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()
|
routing = pywrapcp.RoutingModel(manager)
|
||||||
|
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
|
||||||
|
|
||||||
# Callback to the distance function. The callback takes two
|
# Callback to the distance function. The callback takes two
|
||||||
# arguments (the from and to node indices) and returns the distance between them.
|
# arguments (the from and to node indices) and returns the distance between them.
|
||||||
dist_between_locations = CreateDistanceCallback()
|
dist_between_locations = CreateDistanceCallback()
|
||||||
dist_callback = dist_between_locations.Distance
|
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.
|
# Solve, returns a solution if any.
|
||||||
assignment = routing.SolveWithParameters(search_parameters)
|
assignment = routing.SolveWithParameters(search_parameters)
|
||||||
|
|
Loading…
Reference in New Issue