Skip to content

Instantly share code, notes, and snippets.

@burke
Created September 2, 2009 11:45
Show Gist options
  • Save burke/179667 to your computer and use it in GitHub Desktop.
Save burke/179667 to your computer and use it in GitHub Desktop.
# Jumps to Jita!
jumps = {}
puts "processing database..."
File.open('jumps.dump','r') do |f|
until f.eof?
line = f.readline.strip
if line == "/*!40000 ALTER TABLE `mapSolarSystemJumps` DISABLE KEYS */;"
until ((line=f.readline.strip).size<20)
data = line.split(',')
(jumps[data[2].to_i] ||= []) << data[3].to_i
end
end
end
end
puts jumps.size
puts "calculating optimal routes..."
JITA = 30000142
paths = {}
paths[JITA] = 0
400000.times do |ii|
pd1 = paths.dup
jumps.keys.each do |src|
pd2 = paths.dup
pd2.each do |dest,dist|
# dest has found its shortest path to Jita, src has not, or this one is shorter.
if jumps[src].include?(dest) && (!paths[src] || dist+1 < paths[src])
paths[src] = dist+1 # we can get to jita by jumping through this system.
end
end
end
break if paths == pd1
puts "iteration #{ii} complete"
end
File.open('paths.marshal','w'){|f|f.puts Marshal.dump(paths)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment