diff --git a/tspwplib/__init__.py b/tspwplib/__init__.py index 348a3a6..f5a32a5 100644 --- a/tspwplib/__init__.py +++ b/tspwplib/__init__.py @@ -59,6 +59,8 @@ LondonaqLocationShort, LondonaqTimestamp, LondonaqTimestampId, + NodeCoords, + NodeCoordType, OptimalSolutionTSP, SimpleEdgeFunction, SimpleEdgeList, @@ -102,6 +104,8 @@ "LondonaqLocationShort", "LondonaqTimestamp", "LondonaqTimestampId", + "NodeCoords", + "NodeCoordType", "NotSimpleException", "NotSimpleCycleException", "NotSimplePathException", diff --git a/tspwplib/problem.py b/tspwplib/problem.py index 40ef395..492a97a 100644 --- a/tspwplib/problem.py +++ b/tspwplib/problem.py @@ -273,29 +273,32 @@ def from_tsplib95(cls, problem: tsplib95.models.StandardProblem): if problem.node_coord_type else NodeCoordType.NO_COORDS ) - - node_coords = {i: problem.node_coords.get(i) for i in problem.get_nodes()} - if len(node_coords) == 0: - node_coord_type == NodeCoordType.NO_COORDS + if node_coord_type == NodeCoordType.NO_COORDS: node_coords = None - raise RuntimeWarning(f"Problem {problem.name} has no node co-ordinates.") - elif ( - len(node_coords.get(1)) == 3 - or node_coord_type == NodeCoordType.THREED_COORDS - ): - raise NotImplementedError("3D coords not yet supported") - elif ( - len(node_coords.get(1)) == 2 - and node_coord_type == NodeCoordType.THREED_COORDS - ) or ( - len(node_coords.get(1)) == 3 - and node_coord_type == NodeCoordType.TWOD_COORDS - ): - raise ValueError( - f"Problem {problem.name} has NODE_COORD_TYPE {node_coord_type.value}, but the length of the co-ordinates for node 1 is {len(node_coords.get(1))}." - ) - elif len(node_coords.get(1)) == 2: - node_coord_type = NodeCoordType.TWOD_COORDS + else: + # do verifcation on node coords + node_coords = {i: problem.node_coords.get(i) for i in problem.get_nodes()} + if len(node_coords) == 0: + node_coord_type == NodeCoordType.NO_COORDS + node_coords = None + raise RuntimeWarning(f"Problem {problem.name} has no node co-ordinates.") + elif ( + len(node_coords.get(1)) == 3 + or node_coord_type == NodeCoordType.THREED_COORDS + ): + raise NotImplementedError("3D coords not yet supported") + elif ( + len(node_coords.get(1)) == 2 + and node_coord_type == NodeCoordType.THREED_COORDS + ) or ( + len(node_coords.get(1)) == 3 + and node_coord_type == NodeCoordType.TWOD_COORDS + ): + raise ValueError( + f"Problem {problem.name} has NODE_COORD_TYPE {node_coord_type.value}, but the length of the co-ordinates for node 1 is {len(node_coords.get(1))}." + ) + elif len(node_coords.get(1)) == 2: + node_coord_type = NodeCoordType.TWOD_COORDS return cls( capacity=problem.capacity,