-2

I'm currently working on an algorithm to schedule pub-crawling (it can be much more generic applied, though). This is what is known:

  • There is a certain number of teams and bars, the amount of teams never exceeding the amount of bars
  • The teams must visit all bars
  • The teams cannot be at the same bar at the same time
  • The whole process is temporal; teams are at the bars in the same discrete time intervals between the starting and ending time of the pub-crawl.

I'm thinking of this as a mix between the travelling salesman problem and some roster planning, but right now I've tried to implement it using brute force since I can't figure how to implement the mentioned mix. What I expect the result could look like:

Expected result

Brute force is working, but it's simply too slow. When all rows and columns are unique, a solution is found - just like Sudoku. The numbers can then be mapped to time intervals/arrival and departure time of specific bars. I'm looking for ideas and suggestion, but an implementation is very welcome as well (C#).

At the moment I'm brute forcing by doing:

  • Initializing a 2D array with as many rows as teams and columns as bars. The values are initialized as well ranging from 1-columns.
  • Checking whether the array is a solution, if not: Shuffle the array and check again.

Lastly, I need to mention that when this can be done fast enough one more layer of complexity will be introduced. The chosen route for a specific team must be optimal meaning that all groups must take the most optimal routes in regard to travel time - to do this I'll use the Google Maps API. I guess if this first part of the algorithm is relatively fast the distance optimization can be brute forced.

Looking forward to creative solutions!

zniwalla
  • 367
  • 4
  • 17
  • Far too broad for SO I'm afraid. – DavidG Jun 29 '17 at 10:37
  • "Shuffle the array and check again" => Randomness does not help with iteratively checking all possible combinations. It introduces the possibility of repeatedly checking the same array; and there's no increased chance of finding a correct array, regardless of whether you iterative over them in a logical sequence, or randomly. So using RNG adds a drawback, without adding a benefit. I wouldn't do that if I were you. – Flater Jun 29 '17 at 10:37
  • 1
    Why don't you simply go with shifting the occupations by one in each time step? Just like in your table? I don't see any constraints that would forbid that. That said, if I overlooked something, one solution, although maybe not the best one, would be to transform this into a linear optimization problem (should be possible) and then use some already existing solver for that. Edit: that is, a linear *integer* problem of course – Aziuth Jun 29 '17 at 10:40
  • @Aziuth This would clearly work, but this wouldn't be possible when introducing the need of finding almost optimal routes between bars - shuffling will be necessary. – zniwalla Jun 29 '17 at 10:43
  • @zniwalla the travelling salesman problem doesn't require shuffling, does it? – Timothy Groote Jun 29 '17 at 10:44
  • Personally, I think such a broad question is off-topic for SO as it is likely to turn into a discussion of opinions about "what's best". It would probably be best asked here: https://cs.stackexchange.com/ – spender Jun 29 '17 at 10:44
  • @spender Sure, will go ask there instead then. Thanks. – zniwalla Jun 29 '17 at 10:49
  • @zniwalla Then state the actual problem without anything omitted. Obviously, introducing constraints can radically change a solution. With distances, TSM can be solved by this by using only one team, therefore it's NPC. Which means that you have to think about if you are happy with an approximative solution with a known level of approximation (optimization value or probabilty) or if it even would suffice to find a *good* solution (that is, without guarantee of level of approximation). Solving NPC problems *exactly* is usually to be advised against. – Aziuth Jun 29 '17 at 10:50
  • I'm not sure I'm understanding the problem. Why don't you simply cycle 1 your team order on every pub and you'r done. Also, if number of pubs > number of teams, I'm guessing teams can repeate pubs, otherwise there is no solution, or is nºpubs%nºteams always zero? – InBetween Jun 29 '17 at 10:58
  • 1
    Find the optimal (or almost optimal) route through the bars. Then start the first team at the first bar (in the solution), second team at second bar, etc., as you did in your example. Basically, arrange things as in your example *after* you've determined the optimal path. – Jim Mischel Jun 29 '17 at 13:34
  • @Jim Mischel Well, this is exactly the solution my mind wasn't able to produce in the time of writing.. thanks a bunch, if I could mark it as an answer, I would. Don't know why I tried to over-engineer this, it's so simple. – zniwalla Jun 29 '17 at 14:18

1 Answers1

0

Seems like you should solve the optimal route problem first. If you do that, then you can start the first team at the first bar in the solution, second team at second bar, etc., just as you did in your example.

So if you determine the optimal (or almost optimal) path through the bars is B4,B3,B1,B2,B6,B5, then you just rearrange the order of bars in your table header to match. So during the first time period, team 1 would visit bar 4, etc.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351