- Travelling Salesman Problem with Time Windows
- I’m trying to solve TSP problem with additional constraint — time windows.
- So here are my questions:
- Travelling salesman with time windows algorithm
- About
- Resources
- Releases
- Packages 0
- Languages
- Travelling salesman with repeat nodes & dynamic weights
- Travelling salesman with time windows algorithm
- About
- Resources
- Releases
- Packages 0
- Languages
- TSPTW with Genetic Algorithm
- 1 Answer 1
Travelling Salesman Problem with Time Windows
I’m trying to solve TSP problem with additional constraint — time windows.
All the standard assumptions apply:
- We start and end at given city.
- Each city is visited only once.
- We try to find the optimal path in terms of travel cost (here travel time).
Additionally each city has its own time window in format , which limits when a city can be visited:
- We cannot visit a city after its closing time.
- We can arrive at any city before it’s opening time and wait for it to open. If we do so, waiting time is added to overall time passed, but it is not added to time spent travelling. So time_spent_travelling and total_time_passed are two distinct things we need to keep track of.
I managed to write constraints that find optimal solution in terms of total_time_passed, but I need to find optimal time_spent_travelling.
Here is my logic:
And here sample data (Running it with clingo takes
I used MAX function to calculate arrival time at given cities by choosing from real arrival time or city’s opening time — whichever happened to be later. It worked nicely, so my first thought was to add additional field to location fact changing this line as follows:
This way location hold information about both time_spent_travelling and total_time_passed. While this works fine for 5 cities, with 20 cities it keeps calculating too long (I gave up after 15 minutes) — I expected the program to run roughly the same time at both situations, but apparently there is something I don’t understand here.
I also tried to store waiting times as separate facts, but it seemed to affect computing time the same way and introduced another issue of taking it into consideration in #minimize function which I couldn’t menage to solve.
So here are my questions:
- What can I do to calculate optimal value of time_spent_travelling, yet correctly considering waiting time?
- Why a small change in code, I’ve described above, has such a high computational impact on the solving process?
I’ve started using clingo recently and there is a good chance I don’t see a simple solution to this problem. It’s kind of hard to change the way you write your program, being so used to declarative programming.
The code I’ve provided can be simple run with clingo: clingo logic data
Here the result takes into consideration waiting time, which in this particular example is 9. (378 is time spent only on travelling).
Travelling salesman with time windows algorithm
Travelling Salesman Problem with time windows The code here uses a metaheuristic to come up with a solution to an NP-hard problem The code tries to solve the travelling salesman problem with time windows using the iterated greedy algorithm. The proposed algorithm makes use of the Variable Neighborhood Search (VNS) method to get a list of neighborhood solutions through destruction and construction of solution components. The problem described here refers to a salesman visiting different customers on his route in a particular order to optimize the cost of travel as well as minimize the loss due to seeing the customers outside the time windows described for each customer. The salesman must visit the customers inside the time windows or else bear the penalty associated with it. The algorithm consists of random parameters like NFT0, lambda and number of nodes cij is a matrix of distances between the i and j nodes in the salesman’s path ei represents the upper limit of the time window li represents the lower limit of the time window
Initially an infeasible solution is generated randomly and then the greedy algorithm is applied to the solution in order to get a feasible solution in the end.
About
Travelling Salesman Problem with time windows
Resources
Releases
Packages 0
Languages
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Travelling salesman with repeat nodes & dynamic weights
Given a list of cities and the cost to fly between each city, I am trying to find the cheapest itinerary that visits all of these cities. I am currently using a MATLAB solution to find the cheapest route, but I’d now like to modify the algorithm to allow the following:
- repeat nodes — repeat nodes should be allowed, since travelling via hub cities can often result in a cheaper route
- dynamic edge weights — return/round-trip flights have a different (usually lower) cost to two equivalent one-way flights
For now, I am ignoring the issue of flight dates and assuming that it is possible to travel from any city to any other city.
Does anyone have any ideas how to solve this problem? My first idea was to use an evolutionary optimisation method like GA or ACO to solve point 2, and simply adjust the edge weights when evaluating the objective function based on whether the itinerary contains return/round-trip flights, but perhaps somebody else has a better idea.
(Note: I am using MATLAB, but I am not specifically looking for coded solutions, more just high-level ideas about what algorithms can be used.)
Edit — after thinking about this some more, allowing «repeat nodes» seems to be too loose of a constraint. We could further constrain the problem so that, although nodes can be repeatedly visited, each directed edge can only be visited at most once. It seems reasonable to ignore any itineraries which include the same flight in the same direction more than once.
Travelling salesman with time windows algorithm
Travelling Salesman Problem with time windows The code here uses a metaheuristic to come up with a solution to an NP-hard problem The code tries to solve the travelling salesman problem with time windows using the iterated greedy algorithm. The proposed algorithm makes use of the Variable Neighborhood Search (VNS) method to get a list of neighborhood solutions through destruction and construction of solution components. The problem described here refers to a salesman visiting different customers on his route in a particular order to optimize the cost of travel as well as minimize the loss due to seeing the customers outside the time windows described for each customer. The salesman must visit the customers inside the time windows or else bear the penalty associated with it. The algorithm consists of random parameters like NFT0, lambda and number of nodes cij is a matrix of distances between the i and j nodes in the salesman’s path ei represents the upper limit of the time window li represents the lower limit of the time window
Initially an infeasible solution is generated randomly and then the greedy algorithm is applied to the solution in order to get a feasible solution in the end.
About
Travelling Salesman Problem with time windows
Resources
Releases
Packages 0
Languages
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
TSPTW with Genetic Algorithm
I am implementing TSPTW(Travelling salesman with time window) with Genetic Algorithm with 81 cities, I applied the following steps:
I can’t find a good result, and I run it to specific high time, but I found sometimes it stuck with solution and can’t get better result. I changed the
parameters(population size=20000 ,1000,100, mutation probability=0.03,0.02. )
I’ve also tested it with cycle crossover, and ordered crossover
I would like to know, are my steps right ? How I can specify population size and mutation probability correctly?
1 Answer 1
Your algorithm is probably too elitistic. It only allows better solutions to enter your population. I assume at some point it will consist of all similar individuals. With no diversity left and your elitistic replacement only the low amount of mutation could introduce new genetic material.
I would recommend using elitism only in that you only let the best individual from the previous generation survive. The rest of the individuals should all be replaced by the new generation.
Or you could go with the offspring selection approach that we invented. For each child to survive it must be better than the better of its parents. Otherwise they’re discarded and a new pair of parents is selected to produce a new child. You loop to produce new children until you have enough to fill a new population. Then you replace your population and start anew. The offspring selection genetic algorithm usually outperforms the genetic algorithm in terms of quality that it can achieve. It’s implemented in HeuristicLab. You should be able to model the TSPTW if you open a VRPTW and allow only one vehicle.