gt2.py (29462B)
1 #!/usr/bin/env python3 2 import igraph as ig 3 import matplotlib.pyplot as plt 4 import numpy as np 5 import math 6 import sys 7 import time 8 9 # I computed these magic constants for the price and time functions by 10 # collecting data from playing the game and using linear regression 11 12 def a_price( a, b ): 13 """ price function for air travel""" 14 return distance( a, b ) * 4107 + 611 15 16 def a_time( a, b ): 17 """ time function for air travel""" 18 return distance( a, b ) * 11.5 + 1 19 20 def r_price( a, b ): 21 """ price function for bus routes""" 22 return distance( a, b ) * 780 + 115 23 24 def r_time( a, b ): 25 """ time function for bus routes""" 26 return distance( a, b ) * 93 27 28 def b_price( a, b ): 29 """ price function for boats""" 30 return distance( a, b ) * 1364 + 205 31 32 def b_time( a, b ): 33 """ price function for boats""" 34 return distance( a, b ) * 130 + 1 35 36 def t_price( a, b ): 37 """ price function for trains""" 38 return distance( a, b ) * 1762 + 261 39 40 def t_time( a, b ): 41 """ time function for trains""" 42 return distance( a, b ) * 54 43 44 def distance( i, j ): 45 lon1 = c[i][1] 46 lat1 = c[i][2] 47 lon2 = c[j][1] 48 lat2 = c[j][2] 49 # Convert degrees to radians 50 coordinates = lat1, lon1, lat2, lon2 51 phi1, lambda1, phi2, lambda2 = [ 52 math.radians( c ) for c in coordinates 53 ] 54 # Apply the haversine formula 55 d = math.acos(math.cos(phi2-phi1) - math.cos(phi1) * math.cos(phi2) * 56 (1-math.cos(lambda2-lambda1))) 57 return d 58 59 def print_connections( bys ): 60 """ pretty prints the connections of given city""" 61 byi = d[bys] 62 63 for tr in s: 64 forb = tr.neighbors( byi ) 65 print("-- {} --".format( tr.title ) ) 66 for f in forb: 67 print( " ", c[f][0], ) 68 def ec( l ): 69 return [ c[b][0] for b in l ] 70 71 def plot_path(): 72 """ Plots a nice matplotlib graph of the travel network. 73 if invoked after calling best_paths() the cheapest and fastest routes are emphasized 74 """ 75 fig, ax = plt.subplots() 76 ig.plot( 77 transport, 78 target=ax, 79 vertex_color='bisque', 80 vertex_label=[ city[0] for city in c ], 81 #layout="", 82 #edge_width=transport.es['width'], 83 edge_color=edge_colors, 84 #edge_label=edge_prices, 85 #edge_color='#666', 86 edge_align_label=True, 87 edge_background='white' 88 ) 89 plt.show() 90 91 def bestpaths( source, destination ): 92 src = source 93 dest = destination 94 fastpath_edges, = transport.get_shortest_paths(src, to=dest, weights=edge_times, output="epath") 95 fastpath_verts, = transport.get_shortest_paths(src, to=dest, weights=edge_times, output="vpath") 96 cheappath_edges, = transport.get_shortest_paths(src, to=dest, weights=edge_prices, output="epath") 97 cheappath_verts, = transport.get_shortest_paths(src, to=dest, weights=edge_prices, output="vpath") 98 99 return fastpath_edges, fastpath_verts, cheappath_edges, cheappath_verts 100 101 102 103 # longitude and latitude data from cityinfo in the game files 104 105 c = [ #cities 106 # [ by, long, lat ] 107 [ "Alaska", -150, 61 ], 108 [ "Amazonas", -60, -3 ], 109 [ "Amsterdam", 6, 52 ], 110 [ "Athens", 23, 38 ], 111 [ "Bangkok", 101, 10 ], 112 [ "Berlin", 13, 52.5 ], 113 [ "Boston", -72, 42 ], 114 [ "Budapest", 16, 47.5 ], 115 [ "Costa Rica", -84, 8 ], 116 [ "El Mundo Maya", -89, 20 ], 117 [ "Galapagos", -90, 0 ], 118 [ "Havana", -82, 23 ], 119 [ "Hawaii", -155, 20 ], 120 [ "Irkutsk", 102, 53 ], 121 [ "Ireland", -8, 53 ] , 122 [ "Iceland", -18, 65 ], 123 [ "Lhasa", 91, 30 ], 124 [ "London", 0, 53 ], 125 [ "Maldives", 73, 4 ], 126 [ "Manila", 124, 15 ], 127 [ "Montreal", -73.5, 45.5], 128 [ "New Delhi", 87.5, 28 ], 129 [ "New Zealand", 177, -41 ], 130 [ "Paris", 2.5, 49 ], 131 [ "Sahara", 2, 22 ], 132 [ "Samarkand", 67, 39.5 ], 133 [ "San Francisco", -122.5, 38 ], 134 [ "Shanghai", 123, 28 ], 135 [ "St. Petersburg", 30.5, 62 ], 136 [ "Sydney", 152, -37 ], 137 [ "Tanzania", 33, -7 ], 138 [ "The Wild West", -106, 41 ], 139 [ "Tokyo", 140, 36 ], 140 [ "Washington", -77, 39 ], 141 [ "Yemen", 48, 14 ], 142 [ "Zanzibar", 43, -9 ], 143 [ "Mount Everest", 87.5, 28 ], 144 [ "Thimphu", 91, 26 ], 145 [ "Copenhagen", 12.5, 55.5 ] 146 ] 147 148 d = dict( [ ( c[i][0], i ) for i in range( len( c ) ) ] ) 149 150 # adjacencies from the travel planner 151 # no, these following adjacency matrices were no particular fun to enter 152 153 a = np.array([ #adjacency matrix for flyforbindelser 154 # | | | | | | | | | | | | | | | | | | | | | | | | | | | | g| | | | | | | | | | 155 # | | | | | | | | | a| | | | | | | | | | | | | | | | | o| | r| | | t| | | | | t| | 156 # | | | | | | | | | y| | | | | | | | | | | | | | | | | c| | u| | | s| | | | | s| | 157 # | | | | | | | | | a| | | | | | | | | | | | | d| | | | s| | b| | | e| | | | | e| | 158 # | | | | | | | | a| M| | | | | | | | | | | | | n| | | | i| | s| | | W| | n| | | r| | n 159 # | | m| | | | | | c| | s| | | | | | | | | | | i| a| | | d| c| | r| | | | | o| | | e| | e 160 # | s| a| | | | | t| i| o| o| | | | | | | | s| | l| h| l| | | n| n| i| e| | a| d| | t| | r| v| | g 161 # | a| d| | k| | | s| R| d| g| | | k| d| d| | | e| | a| l| a| | | a| a| a| t| | i| l| | g| | a| E| u| a 162 # a| n| r| s| o| n| n| e| | n| a| a| i| s| n| n| | n| v| a| e| e| e| | a| k| r| h| e| y| n| i| | n| | b| | h| h 163 # k| o| e| n| k| i| o| p| a| u| p| n| i| t| a| a| a| o| i| l| r| D| Z| s| r| r| F| g| P| e| a| W| o| i| n| i| t| p| n 164 # s| z| t| e| g| l| t| a| t| M| a| a| a| u| l| l| s| d| d| i| t| | | i| a| a| | n| | n| z| | y| h| e| z| n| m| e 165 # a| a| s| h| n| r| s| d| s| | l| v| w| k| e| e| a| n| l| n| n| w| w| r| h| m| n| a| .| d| n| e| k| s| m| n| u| i| p 166 # l| m| m| t| a| e| o| u| o| l| a| a| a| r| r| c| h| o| a| a| o| e| e| a| a| a| a| h| t| y| a| h| o| a| e| a| o| h| o 167 # A| A| A| A| B| B| B| B| C| E| G| H| H| I| I| I| L| L| M| M| M| N| N| P| S| S| S| S| S| S| T| T| T| W| Y| Z| M| T| C 168 [ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ], # Alaska 169 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Amazonas 170 [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ], # Amsterdam 171 [ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ], # Athens 172 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 ], # Bangkok 173 [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 ], # Berlin 174 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]]) # Copenhagen 207 208 b = np.array([ #adjacency matrix for bådforbindelser 209 # | | | | | | | | | | | | | | | | | | | | | | | | | | | | g| | | | | | | | | | 210 # | | | | | | | | | a| | | | | | | | | | | | | | | | | o| | r| | | t| | | | | t| | 211 # | | | | | | | | | y| | | | | | | | | | | | | | | | | c| | u| | | s| | | | | s| | 212 # | | | | | | | | | a| | | | | | | | | | | | | d| | | | s| | b| | | e| | | | | e| | 213 # | | | | | | | | a| M| | | | | | | | | | | | | n| | | | i| | s| | | W| | n| | | r| | n 214 # | | m| | | | | | c| | s| | | | | | | | | | | i| a| | | d| c| | r| | | | | o| | | e| | e 215 # | s| a| | | | | t| i| o| o| | | | | | | | s| | l| h| l| | | n| n| i| e| | a| d| | t| | r| v| | g 216 # | a| d| | k| | | s| R| d| g| | | k| d| d| | | e| | a| l| a| | | a| a| a| t| | i| l| | g| | a| E| u| a 217 # a| n| r| s| o| n| n| e| | n| a| a| i| s| n| n| | n| v| a| e| e| e| | a| k| r| h| e| y| n| i| | n| | b| | h| h 218 # k| o| e| n| k| i| o| p| a| u| p| n| i| t| a| a| a| o| i| l| r| D| Z| s| r| r| F| g| P| e| a| W| o| i| n| i| t| p| n 219 # s| z| t| e| g| l| t| a| t| M| a| a| a| u| l| l| s| d| d| i| t| | | i| a| a| | n| | n| z| | y| h| e| z| n| m| e 220 # a| a| s| h| n| r| s| d| s| | l| v| w| k| e| e| a| n| l| n| n| w| w| r| h| m| n| a| .| d| n| e| k| s| m| n| u| i| p 221 # l| m| m| t| a| e| o| u| o| l| a| a| a| r| r| c| h| o| a| a| o| e| e| a| a| a| a| h| t| y| a| h| o| a| e| a| o| h| o 222 # A| A| A| A| B| B| B| B| C| E| G| H| H| I| I| I| L| L| M| M| M| N| N| P| S| S| S| S| S| S| T| T| T| W| Y| Z| M| T| C 223 [ 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0 ], # The Wild West 255 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Tokyo 256 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Washington 257 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ], # Yemen 258 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Zanzibar 259 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Mount Everest 260 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Thimphu 261 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]]) # Copenhagen 262 263 t = np.array([ #adjacency matrix for togforbindelser 264 # | | | | | | | | | | | | | | | | | | | | | | | | | | | | g| | | | | | | | | | 265 # | | | | | | | | | a| | | | | | | | | | | | | | | | | o| | r| | | t| | | | | t| | 266 # | | | | | | | | | y| | | | | | | | | | | | | | | | | c| | u| | | s| | | | | s| | 267 # | | | | | | | | | a| | | | | | | | | | | | | d| | | | s| | b| | | e| | | | | e| | 268 # | | | | | | | | a| M| | | | | | | | | | | | | n| | | | i| | s| | | W| | n| | | r| | n 269 # | | m| | | | | | c| | s| | | | | | | | | | | i| a| | | d| c| | r| | | | | o| | | e| | e 270 # | s| a| | | | | t| i| o| o| | | | | | | | s| | l| h| l| | | n| n| i| e| | a| d| | t| | r| v| | g 271 # | a| d| | k| | | s| R| d| g| | | k| d| d| | | e| | a| l| a| | | a| a| a| t| | i| l| | g| | a| E| u| a 272 # a| n| r| s| o| n| n| e| | n| a| a| i| s| n| n| | n| v| a| e| e| e| | a| k| r| h| e| y| n| i| | n| | b| | h| h 273 # k| o| e| n| k| i| o| p| a| u| p| n| i| t| a| a| a| o| i| l| r| D| Z| s| r| r| F| g| P| e| a| W| o| i| n| i| t| p| n 274 # s| z| t| e| g| l| t| a| t| M| a| a| a| u| l| l| s| d| d| i| t| | | i| a| a| | n| | n| z| | y| h| e| z| n| m| e 275 # a| a| s| h| n| r| s| d| s| | l| v| w| k| e| e| a| n| l| n| n| w| w| r| h| m| n| a| .| d| n| e| k| s| m| n| u| i| p 276 # l| m| m| t| a| e| o| u| o| l| a| a| a| r| r| c| h| o| a| a| o| e| e| a| a| a| a| h| t| y| a| h| o| a| e| a| o| h| o 277 # A| A| A| A| B| B| B| B| C| E| G| H| H| I| I| I| L| L| M| M| M| N| N| P| S| S| S| S| S| S| T| T| T| W| Y| Z| M| T| C 278 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Alaska 279 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Washington 312 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Yemen 313 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Zanzibar 314 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Mount Everest 315 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # Thimphu 316 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]]) # Copenhagen 317 318 fly = ig.Graph.Adjacency( 319 a + a.T, 320 mode="undirected" 321 ) 322 323 båd = ig.Graph.Adjacency( 324 b + b.T, 325 mode="undirected" 326 ) 327 328 tog = ig.Graph.Adjacency( 329 t + t.T, 330 mode="undirected" 331 ) 332 333 bus = ig.Graph() 334 bus.add_vertices( len( c ) ) 335 bus.add_edges( 336 [ 337 ( d["Alaska"], d["San Francisco"] ), 338 ( d["San Francisco"], d["Washington"] ), 339 ( d["Boston"], d["Washington"] ), 340 ( d["The Wild West"], d["El Mundo Maya"] ), 341 ( d["Costa Rica"], d["El Mundo Maya"] ), 342 ( d["Costa Rica"], d["Amazonas"] ), 343 ( d["Yemen"], d["Budapest"] ), 344 ( d["St. Petersburg"], d["Budapest"] ), 345 ( d["St. Petersburg"], d["Irkutsk"] ), 346 ( d["London"], d["Amsterdam"] ), 347 ( d["Paris"], d["Amsterdam"] ), 348 ( d["Paris"], d["Athens"] ), 349 ( d["Lhasa"], d["Mount Everest"] ), 350 ( d["Thimphu"], d["Mount Everest"] ), 351 ( d["Thimphu"], d["Bangkok"] ), 352 ( d["Tanzania"], d["Sahara"] ), 353 ( d["Samarkand"], d["Sahara"] ), 354 ( d["Samarkand"], d["New Delhi"] ) 355 ] 356 ) 357 358 s = [ fly, tog, båd, bus ] 359 titles = [ "flyforbindelser", "togforbindelser", "bådforbindelser", "busforbindelser" ] 360 colors = [ "darkgreen", "darkorange", "darkblue", "darkred" ] 361 midler = [ "fly", "tog", "båd", "bus" ] 362 pf = [ a_price, t_price, b_price, r_price ] # price functions 363 tf = [ a_time, t_time, b_time, r_time ] # time functions 364 pl = [] # prices lists 365 tl = [] # time lists 366 edges = [] 367 368 for i in range( 4 ): 369 s[i].title = titles[i] 370 s[i].p = pf[i] 371 s[i].t = tf[i] 372 edges.append( s[i].get_edgelist() ) 373 pl.append( [ round( s[i].p( j, k ), -1 ) for j, k in edges[i] ] ) 374 tl.append( [ round( s[i].t( j, k ) ) for j, k in edges[i] ] ) 375 s[i].es["color"] = colors[i] 376 s[i].es["middel"] = midler[i] 377 378 transport = ig.Graph( len( c ) ) 379 380 edge_prices = [ p for ps in pl for p in ps ] 381 edge_times = [ t for ts in tl for t in ts ] 382 edge_colors = fly.es["color"] + tog.es["color"] + båd.es["color"] + bus.es["color"] 383 edge_middel = fly.es["middel"] + tog.es["middel"] + båd.es["middel"] + bus.es["middel"] 384 385 for i in range( 4 ): 386 transport.add_edges( s[i].get_edgelist() ) 387 388 transport.es["width"] = 0.5 389 390 #for i in epath: 391 # edge_colors[i] = "deeppink" 392 393 if __name__ == "__main__": 394 if len( sys.argv ) == 3: 395 source = d[sys.argv[1]] 396 dest = d[sys.argv[2]] 397 else: 398 source = 0 399 dest = 0 400 401 fastpath_edges, fastpath_verts, cheappath_edges, cheappath_verts = bestpaths( source, dest ) 402 403 transport.es[ fastpath_edges ]["width"] = 2 404 transport.es[ cheappath_edges ]["width"] = 4 405 406 print( "----------- fastpath -----------" ) 407 print( "price, time" ) 408 print( sum( [ edge_prices[i] for i in fastpath_edges] ), "DKK", sum( [ edge_times[i] for i in fastpath_edges] ), "H" ) 409 print( c[ fastpath_verts[0] ][0] ) 410 for i in range( len( fastpath_edges ) ): 411 print( " ", edge_middel[ fastpath_edges[i] ], edge_prices[ fastpath_edges[i] ], "DKK", edge_times[ fastpath_edges[i] ], "H" ) 412 print( c[ fastpath_verts[i+1] ][0] ) 413 414 print( "----------- cheappath ----------" ) 415 print( "price, time" ) 416 print( sum( [ edge_prices[i] for i in cheappath_edges] ), "DKK", sum( [ edge_times[i] for i in cheappath_edges] ), "H" ) 417 print( c[ cheappath_verts[0] ][0] ) 418 for i in range( len( cheappath_edges ) ): 419 print( " ", edge_middel[ cheappath_edges[i] ], edge_prices[ cheappath_edges[i] ], "DKK", edge_times[ cheappath_edges[i] ], "H" ) 420 print( c[ cheappath_verts[i+1] ][0] ) 421 422 plot_path()