I am new to the whole traveling salesman problem, as well as to stackoverflow, so let me know if I say something that is not entirely correct.
Introduction:
I am trying to code a multiple trading algorithm with profit / time optimization for a game that includes several cities (nodes) in several countries (regions), where:
- The physical time required to move between two connected cities is always the same:
- Cities are not linearly connected (you can teleport between some cities at the same time);
- Some countries (areas) have teleport routes that make the shortest route accessible through other countries.
- The traveler (or merchant) has a limit on his wallet, the weight of his goods and the amount sold on a particular route. A trade route can span several cities.
Question parameters:
There is already a memory database (python: sqlite) that holds transactions based on their source and destination cities, the shortest paths between them as an array and quantity, as well as the limiting factor with its% return on total capital (or in the case when none of the factors is limited, and then just a method that gives the maximum return on total capital).
- I am trying to find the optimal profit for a specific given piece of time (i.e. 30 minutes)
- The act of crossing into a new city is actually simultaneous
- Usually it takes a certain amount of time (i.e. 2 minutes) to go on a city map.
- The act of initiating the first or any new transaction occurs at the same time as the intersection of one city map (i.e. 2 minutes).
- My starting point may actually not have valid trading (I would have to go to first / nearest / best)
Pseudo-solution so far
Optimization
First of all, I understand that since I have a limit on the time it takes and I know how long it takes for each jump (including -1 to enter the trade), I can limit the schedule for all transactions whose transitions are under or equal to max_hops=int(max_time/route_time) -1 . I cut out the elements of the trading database that do not fall under this time limit, trimming the cities with the shortest path lengths longer than max_hops .
I make another entry in the trade database, which includes the shortest paths between my current city and the starting cities of all existing transactions that are not my current city, and give them a 0% refund. I would limit them to where the number of city flights is less than max_hops , and I would also calculate whether the current city in the start city plus which shortest-path-hops trades will exceed max_hops and remove those that exceed this limit.
Then I take the remaining trades that are not (current_city->starting_city) and add trade routes with a 0% return between the entire destination and the starting cities if hops fail max_hops
Then I make the last prune for all cities that are not in the auction database, either as the starting city, destination city, or part of the shortest urban massifs.
Scheduled Search I am left with a (much) lesser deal schedule valid for the duration (i.e. 30 minutes).
Since all nodes that are connected are contiguous, by default all connections are weighted 1. I divide the% return by the number of transitions in the trade, then take it back and add +1 (this will mean weight 1.01 for a 100% return route). In the case where the yield is 0%, I add ... 2?
Then he must return the most profitable route ...
Question:
Mostly,
How to add the ability to accept multiple routes when I left money or space, and continue to search for a route along the path discretely to individual trade routes? Due to the nature of the goods sold at several prices and quantities within the city, there would be many overlapping routes.
How do I penalize a new trade route?
Is graph search really useful in this situation?
On the side
- What types of drafts / optimizations for the diagram should I (or should not) do?
- Is my weighing method correct? I have a feeling that this will give me disproportionate weights. Should I use actual income instead of interest return?
- If I code in python, are there libraries like python-graph suitable for my needs? Or will it save me a lot of overhead (as I understand it, graph search algorithms can be computationally intensive) to write a specialized function?
- Is it better to use A * search?
- Should I predict the shortest waypoints in the trading database and maximize the optimization, or should I leave it all to search on the chart?
- Can you spot anything that I could improve?
python algorithm routing heuristics traveling-salesman
Sleepingrock
source share