CAM: Add comprehensive TSP tunnel solver tests and wrapper function
Added extensive test coverage for the TSP tunnel solver including linear tunnels, pentagram diagonals, and complex wire geometries with various constraint combinations. Introduced a Python wrapper function for tunnel sorting that integrates with the C++ solver. src/Mod/CAM/CAMTests/TestTSPSolver.py: - Renumbered existing tests to run in sequential order (test_01_simple_tsp, test_02_start_point, etc.) - Added print_tunnels() helper function for displaying tunnel information with original indices - Added test_06_tunnels_tsp: Tests 7 linear tunnels with varying lengths, connectivity, and flipping behavior - Added test_07_pentagram_tunnels_tsp: Tests pentagram diagonal tunnels with no constraints, start+end constraints, and start-only constraints - Added test_08_open_wire_end_only: Tests end-only constraint on complex wire with 8 tunnels including crossings and diagonals src/Mod/CAM/PathScripts/PathUtils.py: - Added sort_tunnels_tsp() wrapper function that interfaces with the C++ tsp_solver.solveTunnels() - Supports allowFlipping, routeStartPoint, and routeEndPoint parameters
This commit is contained in:
@@ -637,6 +637,36 @@ def sort_locations_tsp(locations, keys, attractors=None, startPoint=None, endPoi
|
||||
return [locations[i] for i in order]
|
||||
|
||||
|
||||
def sort_tunnels_tsp(tunnels, allowFlipping=False, routeStartPoint=None, routeEndPoint=None):
|
||||
"""
|
||||
Python wrapper for the C++ TSP tunnel solver. Takes a list of dicts (tunnels),
|
||||
a list of keys for start/end coordinates, and optional parameters.
|
||||
|
||||
Parameters:
|
||||
- tunnels: List of dictionaries with tunnel data. Each tunnel dictionary should contain:
|
||||
- startX: X-coordinate of the tunnel start point
|
||||
- startY: Y-coordinate of the tunnel start point
|
||||
- endX: X-coordinate of the tunnel end point
|
||||
- endY: Y-coordinate of the tunnel end point
|
||||
- isOpen: Boolean indicating if the tunnel is open (optional, defaults to True)
|
||||
- allowFlipping: Whether tunnels can be reversed (entry becomes exit)
|
||||
- routeStartPoint: Optional starting point [x, y] for the entire route
|
||||
- routeEndPoint: Optional ending point [x, y] for the entire route
|
||||
|
||||
Returns the sorted list of tunnels in TSP order. Each returned tunnel dictionary
|
||||
will include the original keys plus:
|
||||
- flipped: Boolean indicating if the tunnel was reversed during optimization
|
||||
- index: Original index of the tunnel in the input list
|
||||
"""
|
||||
# Call C++ TSP tunnel solver directly - it handles all the processing
|
||||
return tsp_solver.solveTunnels(
|
||||
tunnels=tunnels,
|
||||
allowFlipping=allowFlipping,
|
||||
routeStartPoint=routeStartPoint,
|
||||
routeEndPoint=routeEndPoint,
|
||||
)
|
||||
|
||||
|
||||
def guessDepths(objshape, subs=None):
|
||||
"""
|
||||
takes an object shape and optional list of subobjects and returns a depth_params
|
||||
|
||||
Reference in New Issue
Block a user