The travelling salesman problem is an np-hard problem with application in supply chain and computer science.
tsp_exact uses PuLP module to formulate the problem and CPLEX, GUROBI, COIN_CMD, and PULP_solver to find the exact solution of the TSP. To setup an external solver follow this link.
- matrix: is a NxN cost matrix between the points that have to be visited by the nodes with 2 requirements:
a. The row and column index of this matrix should be INTEGER
b. Depot is indexed by 0, i.e. Row 0 represents the Depot.
0 1 2 3 4
0 0 21.0 15 21.0 10
1 21 0.0 5 0.5 11
2 15 5.0 0 5.0 5
3 21 0.5 5 0.0 10
4 10 11.0 5 10.0 0
- method: The type of solver to use. Default is "PULP_CBC_CMD". Other solvers available are: "CPLEX_CMD", "GUROBI_CMD", and "COIN_CMD".
- message: PuLP will display calculation summary if message is set to 1. Default value is 0 (suppress summary).
- route: Initial route estimate (only for improvement heuristics & metaheuristics)
- trials: Number of local search to be made, default is 5000 (only for improvement heuristics & metaheuristics)
-
time_window: a Nx1 matrix containing the time by which node has to be visited by the truck. If
$tw_{i}=0$ the solution will assume that there is no time constraint for customer$i$
- route[List]: The shortest route coving all the nodes. (The route starts from the depot and ends at the depot)
- route_sum[Scalar]: Total cost incurred by the route.
Below is the mathematical formulation for the exact solution of tsp with time window which is executed by tsp_exact() function
We will use binary variable
Other variables are:
Objective: Minimize the total time to visit all nodes
Constraint 1: All nodes have to be visited by truck exactly once
Constraint 2: Truck leaves depot D and comes back to depot D' exactly once
Constraint 3: If truck arrives at node j then it should also leave node j.
Constraint 4: Avoiding sub-tours for truck
Constraint 5: We will add travel time
Constraint 6: Each node has to be visited before the time specified