ml4co_kit.task.routing.tsp.atsp

Asymmetric Traveling Salesman Problem (ATSP)

ATSP is a variant of the classic TSP where the distance from one city to another may not be the same in both directions. It aims to find the shortest possible route that visits each city once and returns to the starting point in a directed graph.

Classes

ATSPTask(distance_type, round_type, precision)

class ml4co_kit.task.routing.tsp.atsp.ATSPTask(distance_type: ~ml4co_kit.task.routing.base.DISTANCE_TYPE = DISTANCE_TYPE.EUC_2D, round_type: ~ml4co_kit.task.routing.base.ROUND_TYPE = ROUND_TYPE.NO, precision: ~numpy.float32 | ~numpy.float64 = <class 'numpy.float32'>)[source]

Bases: RoutingTaskBase

check_constraints(sol: ndarray) bool[source]

Check if the solution is valid.

evaluate(sol: ndarray, check_constr: bool = True) floating[source]

Evaluate the total distance of the TSP solution.

from_data(dists: ndarray | None = None, sol: ndarray | None = None, ref: bool = False, normalize: bool = False, name: str | None = None)[source]

Create a problem instance from raw data. To be implemented by subclasses.

from_tsplib(atsp_file_path: Path | None = None, tour_file_path: Path | None = None, ref: bool = False, normalize: bool = False)[source]

Load ATSP data from a TSPLIB file.

render()[source]

Render the ATSP problem instance with or without solution.

to_tsplib(atsp_file_path: Path | None = None, tour_file_path: Path | None = None)[source]

Save ATSP data to a TSPLIB file.