def get_clean_links(nodes=None, delaytype = 'Polynomial', parameters = matrix([0.0, 0.0, 0.0, 0.15])): links = np.genfromtxt('Data/Network/CSV/LA_big_box_arterials/links_qgis_cap.csv', delimiter = ',', skiprows = 1) tmp = links links = [] speed_limit_freeway = 33.33 #unit: m/s dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22} if delaytype=='None': for startnode, endnode, category in tmp: arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1]) if category == 1: ffdelay = arc/speed_limit_freeway if category == 2: ffdelay = arc/16.67 if category !=0: links.append((startnode, endnode, 1, ffdelay, None)) if delaytype=='Polynomial': theta = parameters degree = len(theta) for startnode, endnode, category, cap in tmp: arc = distance_on_unit_sphere(nodes[startnode-1][1], nodes[startnode-1][0], nodes[endnode-1][1], nodes[endnode-1][0]) if category == 1: ffdelay, slope = arc/speed_limit_freeway, 1/cap if category == 2: if dict_cap2speed.has_key(cap): ffdelay, slope = arc/dict_cap2speed[cap], 1/cap else : ffdelay, slope = arc/16.67, 1/cap coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))] links.append((startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) return links
def get_clean_links(nodes=None, delaytype='Polynomial', parameters=matrix([0.0, 0.0, 0.0, 0.15])): links = np.genfromtxt( 'Data/Network/CSV/LA_big_box_arterials/links_qgis_cap.csv', delimiter=',', skiprows=1) tmp = links links = [] speed_limit_freeway = 33.33 #unit: m/s dict_cap2speed = { 600: 12.5, 1000: 16.67, 2000: 16.67, 4000: 16.67, 5000: 16.67, 1500: 16.67, 3000: 22.22, 6000: 22.22, 9000: 22.22, 4500: 22.22, 7500: 22.22, 10500: 22.22 } if delaytype == 'None': for startnode, endnode, category in tmp: arc = distance_on_unit_sphere(nodes[startnode - 1][2], nodes[startnode - 1][1], nodes[endnode - 1][2], nodes[endnode - 1][1]) if category == 1: ffdelay = arc / speed_limit_freeway if category == 2: ffdelay = arc / 16.67 if category != 0: links.append((startnode, endnode, 1, ffdelay, None)) if delaytype == 'Polynomial': theta = parameters degree = len(theta) for startnode, endnode, category, cap in tmp: arc = distance_on_unit_sphere(nodes[startnode - 1][1], nodes[startnode - 1][0], nodes[endnode - 1][1], nodes[endnode - 1][0]) if category == 1: ffdelay, slope = arc / speed_limit_freeway, 1 / cap if category == 2: if dict_cap2speed.has_key(cap): ffdelay, slope = arc / dict_cap2speed[cap], 1 / cap else: ffdelay, slope = arc / 16.67, 1 / cap coef = [ ffdelay * a * b for a, b in zip(theta, np.power(slope, range(1, degree + 1))) ] links.append( (startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) return links
def los_angeles_2(parameters=None, delaytype='None'): """Generate larger map of L.A. with 664 links and 194 nodes """ nodes = np.genfromtxt('LA_medium_data/nodes_LA_toy.csv', delimiter = ',', skip_header = 1) nodes = nodes[:,1:3] links = np.genfromtxt('LA_medium_data/links_qgis_cap.csv', delimiter = ',', skip_header = 1) tmp = links links = [] speed_limit_freeway = 33.33 #unit: m/s dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22} if delaytype=='None': for startnode, endnode, category in tmp: arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1]) if category == 1: ffdelay = arc/speed_limit_freeway if category == 2: ffdelay = arc/16.67 if category !=0: links.append((startnode, endnode, 1, ffdelay, None)) if delaytype=='Polynomial': theta = parameters degree = len(theta) for startnode, endnode, category, cap in tmp: arc = distance_on_unit_sphere(nodes[startnode-1][1], nodes[startnode-1][0], nodes[endnode-1][1], nodes[endnode-1][0]) if category == 1: ffdelay, slope = arc/speed_limit_freeway, 1/cap if category == 2: if dict_cap2speed.has_key(cap): ffdelay, slope = arc/dict_cap2speed[cap], 1/cap else : ffdelay, slope = arc/16.67, 1/cap coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))] links.append((startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) dest1 = 50 dest2 = 100 ODs=[] #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 10, 10, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 20, nodes, 6000.0) #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 30, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 40, nodes, 6000.0) #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 50, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 60, nodes, 6000.0) #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 70, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 80, nodes, 6000.0) #ODs = [[ 57. , 50. , 4. ],[ 20. , 162. , 56.4]] ODs = Create_ODs_nodes_unique(nodes) ODs = ODs[1:5] print ODs return g.create_graph_from_list(nodes, links, delaytype, ODs, 'Larger map of L.A.')
def notify_fb_friends(self, oauth_token, trip): graph = GraphAPI(oauth_token) profile = graph.get_object("me") friends = graph.get_connections("me", "friends") friend_list = [friend['id'] for friend in friends['data']] pton_in_friends = User.query.filter(User.fbid.in_(friend_list)).all() for friend in pton_in_friends: # i bet this won't scale trips = Trip.query.filter_by(user_id=friend.id) for friend_trip in trips: if friend_trip.start_date < trip.end_date and \ friend_trip.end_date > trip.start_date: d = distance_on_unit_sphere( trip.location_lat, trip.location_long, friend_trip.location_lat, friend_trip.location_long) max_dist_in_miles = 50 if d <= max_dist_in_miles: send_notif( to_user_firstname=friend.first_name, friend_fullname="%s %s" % (self.first_name, self.last_name), friend_loc=trip.location_name, startdate=trip.start_date, enddate=trip.end_date, to_email=friend.email) """
def dist_to_I210box(lat, lng, box = [34.124918, 34.1718, -118.1224, -118.02524]): if lat > box[1]: if lng < box[2]: return distance_on_unit_sphere(lat, lng, box[1], box[2]) if lng > box[3]: return distance_on_unit_sphere(lat, lng, box[1], box[3]) else : return distance_on_unit_sphere(lat, lng, box[1], lng) if lat < box[0]: if lng < box[2]: return distance_on_unit_sphere(lat, lng, box[0], box[2]) if lng > box[3]: return distance_on_unit_sphere(lat, lng, box[0], box[3]) else : return distance_on_unit_sphere(lat, lng, box[0], lng) elif lng < box[2]: return distance_on_unit_sphere(lat, lng, lat, box[2]) elif lng > box[3]: return distance_on_unit_sphere(lat, lng, lat, box[3]) else : return 0
def get_json_list(self, _filter, get_data=False): data = [] feeds = self.objects.filter(likes__gte=_filter['likes']) for feed in feeds: if distance_on_unit_sphere( feed.latitude, feed.longitude, _filter['latitude'], _filter['longitude'] ) < _filter['_range'] and feed.reply_set.count() >= _filter['num_reply']: data.append(feed.get_json(get_data=True)) if get_data: return data return json.dumps(data)
def test_LA(datapath='', parameters=None, delaytype='None'): nodes = np.genfromtxt(datapath+'Data/Network/CSV/test_LA/test_nodes.csv', delimiter = ',', skip_header = 1) nodes = nodes[:,1:3] #link_data = np.genfromtxt('Data/Network/CSV/test_LA/test_links.csv', delimiter = ',', skip_header = 1) link_data = np.genfromtxt(datapath+'Data/Network/CSV/test_LA/test_links_C.csv', delimiter = ',', skip_header=1) if delaytype=='None': links = [] speed_limit_freeway = 30.00 #unit: m/s dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22} for startnode, endnode, category in link_data: arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1]) if category == 1: ffdelay = arc/speed_limit_freeway if category == 2: ffdelay = arc/16.67 if category !=0: links.append((startnode, endnode, 1, ffdelay, None)) if delaytype=='Polynomial': #theta = parameters #degree = len(theta) #for startnode, endnode, category, cap in tmp: #arc = distance_on_unit_sphere(nodes[startnode-1][1], nodes[startnode-1][0], nodes[endnode-1][1], nodes[endnode-1][0]) #if category == 1: ffdelay, slope = arc/speed_limit_freeway, 1./cap #if category == 2: #if dict_cap2speed.has_key(cap): #ffdelay, slope = arc/dict_cap2speed[cap], 1./cap #else : ffdelay, slope = arc/16.67, 1./cap #coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))] #links.append((startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) theta = parameters degree = len(theta) links=[] for link_entry in link_data: startnode = int(link_entry[1]) endnode = int(link_entry[2]) length = link_entry[3] cap = link_entry[5] freespeed = link_entry[6] ff_d=length/freespeed #change a capacity (slop=1) to simulate an accident #slope= 2000 / cap slope= 1. / cap coef = [ff_d*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))] links.append((startnode, endnode, 1, ff_d, (ff_d, slope, coef), cap, length,freespeed)) ODs = Create_ODs_nodes_unique(nodes, datapath) #ODs = ODs[1:5] #print ODs return g.create_graph_from_list(nodes, links, delaytype, ODs, 'test L.A.')
def filter_ODs_whithin_I210_box(ODs_list, nodes_list): nodes = nodes_list temp = ODs_list ODs_sorted = [] for od in temp: startnode = nodes[od[0]-1] endnode = nodes[od[1]-1] ODs_sorted.append([od[0], od[1], od[2], distance_on_unit_sphere(nodes[od[0]-1][1], nodes[od[0]-1][0], nodes[od[1]-1][1], nodes[od[1]-1][0]), Is_in_I210box(startnode[1], startnode[0], 'medium'), Is_in_I210box(endnode[1], endnode[0], 'medium')]) ODs_sorted = np.asarray(ODs_sorted) print ODs_sorted[0:20] temp = ODs_sorted ODs_sorted = [] for od in temp: if od[4]+od[5]>1 : ODs_sorted.append(od[0:4]) return np.asarray(ODs_sorted)
def Get_links_from_csv(Nodes): data = np.genfromtxt('Data/links_qgis.csv', delimiter = ',', skiprows=1) Links_table=[] theta = matrix([0.0, 0.0, 0.0, 0.15]) degree=len(theta) for i in range(len(data)): startnode, endnode, type= int(data[i][0]), int(data[i][1]), data[i][2] length = distance_on_unit_sphere(Nodes[startnode-1][2], Nodes[startnode-1][1], Nodes[endnode-1][2], Nodes[endnode-1][1]) if type==1: ffdelay=length / 32 slope = 0.2 else: ffdelay, slope = length / 17, 0.75 coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))] Links_table.append((startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) return Links_table
def getAverageStopCloseness(self, refdata): all_data = self.getList() value = 0 stopPoints = self.getStopPlace() num_stop = len(stopPoints) for point in all_data: latitude = point.getLatitude() longtitude = point.getLongtitude() closeness = 10000000 if point.getPointNumber() in stopPoints: for stop in refdata.getStopList(): temp_close = distance_on_unit_sphere(stop.getLatitude(), stop.getLongtitude(), latitude, longtitude) if temp_close < closeness: closeness = temp_close value = value + closeness value = value / num_stop return value
def dist_to_I210box(lat, lng, box=[34.124918, 34.1718, -118.1224, -118.02524]): if lat > box[1]: if lng < box[2]: return distance_on_unit_sphere(lat, lng, box[1], box[2]) if lng > box[3]: return distance_on_unit_sphere(lat, lng, box[1], box[3]) else: return distance_on_unit_sphere(lat, lng, box[1], lng) if lat < box[0]: if lng < box[2]: return distance_on_unit_sphere(lat, lng, box[0], box[2]) if lng > box[3]: return distance_on_unit_sphere(lat, lng, box[0], box[3]) else: return distance_on_unit_sphere(lat, lng, box[0], lng) elif lng < box[2]: return distance_on_unit_sphere(lat, lng, lat, box[2]) elif lng > box[3]: return distance_on_unit_sphere(lat, lng, lat, box[3]) else: return 0
def filter_ODs_whithin_I210_box(ODs_list, nodes_list): nodes = nodes_list temp = ODs_list ODs_sorted = [] for od in temp: startnode = nodes[od[0] - 1] endnode = nodes[od[1] - 1] ODs_sorted.append([ od[0], od[1], od[2], distance_on_unit_sphere(nodes[od[0] - 1][1], nodes[od[0] - 1][0], nodes[od[1] - 1][1], nodes[od[1] - 1][0]), Is_in_I210box(startnode[1], startnode[0], 'medium'), Is_in_I210box(endnode[1], endnode[0], 'medium') ]) ODs_sorted = np.asarray(ODs_sorted) print ODs_sorted[0:20] temp = ODs_sorted ODs_sorted = [] for od in temp: if od[4] + od[5] > 1: ODs_sorted.append(od[0:4]) return np.asarray(ODs_sorted)
def Get_links_from_csv(Nodes): data = np.genfromtxt('Data/links_qgis.csv', delimiter=',', skiprows=1) Links_table = [] theta = matrix([0.0, 0.0, 0.0, 0.15]) degree = len(theta) for i in range(len(data)): startnode, endnode, type = int(data[i][0]), int(data[i][1]), data[i][2] length = distance_on_unit_sphere(Nodes[startnode - 1][2], Nodes[startnode - 1][1], Nodes[endnode - 1][2], Nodes[endnode - 1][1]) if type == 1: ffdelay = length / 32 slope = 0.2 else: ffdelay, slope = length / 17, 0.75 coef = [ ffdelay * a * b for a, b in zip(theta, np.power(slope, range(1, degree + 1))) ] Links_table.append( (startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) return Links_table
def LA_county(datapath='', parameters=None, delaytype='None', cur_gis=None): nodes = np.genfromtxt(datapath+'Data/Network/CSV/LA_county/nodes.csv', delimiter = ',', skip_header = 1) nodes = nodes[:,:2] link_data = np.genfromtxt('Data/Network/CSV/LA_county/links.csv', delimiter = ',', skip_header = 1) link_data = np.hstack((link_data[:,[-1]], link_data[:,:-1])) if delaytype=='None': links = [] speed_limit_freeway = 30.00 #unit: m/s dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22} for startnode, endnode, category in link_data: arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1]) if category == 1: ffdelay = arc/speed_limit_freeway if category == 2: ffdelay = arc/16.67 if category !=0: links.append((startnode, endnode, 1, ffdelay, None)) if delaytype=='Polynomial': theta = parameters degree = len(theta) links=[] for link_entry in link_data: startnode = int(link_entry[1]) endnode = int(link_entry[2]) length = link_entry[3] cap = link_entry[5] freespeed = link_entry[6] ff_d=length/freespeed #change a capacity (slop=1) to simulate an accident #slope= 2000 / cap slope= 1. / cap coef = [ff_d*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))] links.append((startnode, endnode, 1, ff_d, (ff_d, slope, coef), cap, length,freespeed)) ODs = Create_ODs_nodes_unique(nodes, datapath, cur_gis) #ODs = ODs[ODs[:,-1]>np.sum(ODs[:,-1])/1000.,:] return g.create_graph_from_list(nodes, links, delaytype, ODs, 'LA county')
def test6(): """Test distance_on_unit_sphere()""" arc = util.distance_on_unit_sphere(34.049240, -118.238456, 34.073238, -118.284118) print 'distance in miles', 3960.0*arc print 'distance in km', 6373.0*arc
def __init__(self): Gtk.ApplicationWindow.__init__(self) self.set_title('GeoCaching Details') self.set_default_size(400, 650) self.set_icon_from_file(ICON_FILE) mycache = json.loads(util.get_json_row(cacheid)) header = Gtk.HeaderBar(title=mycache['cachename']) header.set_show_close_button(False) self.set_titlebar(header) button = Gtk.MenuButton() header.pack_end(button) menumodel = Gio.Menu() menumodel.append("Log Visit", "win.log_visit") menumodel.append("Open in Browser", "win.browser") # menumodel.append("Quit", "win.quit") button.set_menu_model(menumodel) log_visit_action = Gio.SimpleAction.new("log_visit", None) log_visit_action.connect("activate", self.log_visit_callback) self.add_action(log_visit_action) browser_action = Gio.SimpleAction.new("browser", None) browser_action.connect("activate", self.browser_callback) self.add_action(browser_action) button = Gtk.Button(label="<") button.connect("clicked", self.on_button_clicked) header.pack_start(button) grid1 = Gtk.Grid() row = 0 mystr = "<big><b>" + mycache['cachename'] + "</b></big>" row = self.add_grid_row("Cache Name:", mystr, grid1, row) mystr = "<big>" + mycache['cachetype'] + "</big>" row = self.add_grid_row("Cache Type:", mystr, grid1, row) mystr = "<big>" + mycache['cachesize'] + "</big>" row = self.add_grid_row("Cache Size:", mystr, grid1, row) mystr = "<big>" + mycache['cacheid'] + "</big>" row = self.add_grid_row("Cache ID:", mystr, grid1, row) fwd_az = util.get_azimuth(lat, lon, mycache['lat'], mycache['lon']) dist = util.distance_on_unit_sphere(lat, lon, mycache['lat'], mycache['lon']) mystr = "<big>" + str(int(round(dist * 1000, 0))) + "m @ " + \ str(int(round(fwd_az, 0))) + "°</big>" row = self.add_grid_row("Distance:", mystr, grid1, row) mystr = "<big>" + str(float(mycache['diff'])) + "/5.0</big>" row = self.add_grid_row("Difficulty:", mystr, grid1, row) mystr = "<big>" + str(float(mycache['terr'])) + "/5.0</big>" row = self.add_grid_row("Terrain:", mystr, grid1, row) mystr = "<big>" + mycache['cacheowner'] + "</big>" row = self.add_grid_row("Owner:", mystr, grid1, row) mystr = time.strftime('%d %b %Y', time.localtime(mycache['hidden'])) row = self.add_grid_row("Hidden:", mystr, grid1, row) date = time.strftime('%d %b %Y', time.localtime(mycache['lastfound'])) mystr = "<big>" + date + "</big>" row = self.add_grid_row("Last Found:", mystr, grid1, row) mystr = util.from_decimal(mycache['lat'], 'lat') + " - " + \ util.from_decimal(mycache['lon'], 'lon') row = self.add_grid_row("Cache Location:", mystr, grid1, row) row = self.show_icons(grid1, row) label = Gtk.Label() label.set_halign(Gtk.Align.START) label.set_hexpand(True) agetext = util.stored_age(mycache['dltime']) label.set_markup("Stored in Device: " + agetext) grid1.attach(label, 0, row, 2, 1) row += 1 logdesc = "<html><body>" logdesc += mycache['short'] + mycache['body'] + "<br/>\n<br/>\n" if mycache['hint'] != "": logdesc += "<b><big>Hint:</big></b><br/>\n" logdesc += "<div id='enc_hint' onClick='update()'>" + mycache[ 'hint'] + "</div>" logdesc += "<div id='dec_hint' onClick='update()' style='display:none'>" logdesc += codecs.encode(mycache['hint'], 'rot_13') + "</div>" logdesc += "<br/><br/>" logdesc += """ <script type="text/javascript"> function update() { if(document.getElementById('enc_hint').style.display == '') { document.getElementById('enc_hint').style.display = 'none'; document.getElementById('dec_hint').style.display = ''; } else { document.getElementById('enc_hint').style.display = ''; document.getElementById('dec_hint').style.display = 'none'; } } </script> """ logdesc += "</body></html>" base_uri = "file:///" webkit1 = WebKit2.WebView() webkit1.load_html(logdesc, base_uri) logs = util.get_html_logs(cacheid) # print(logs) self.webkit = WebKit2.WebView() self.webkit.load_html(logs, base_uri) self.notebook = Gtk.Notebook() self.notebook.set_scrollable(True) self.dlabel = Gtk.Label(label="Details") self.desclabel = Gtk.Label(label="Description") self.lblabel = Gtk.Label(label="Logbook") self.notebook.append_page(grid1, self.dlabel) self.notebook.append_page(webkit1, self.desclabel) self.notebook.append_page(self.webkit, self.lblabel) self.add(self.notebook)
dict_unique[(od[0], od[1])] += od[2]/5. #We divide by 5 because peak hour lasts 5 hours else : dict_unique[(od[0], od[1])] = od[2]/5. for od, value in dict_unique.iteritems(): ODs_unique.append([od[0], od[1], value]) return ODs_unique if __name__ == "__main__": nodes = np.genfromtxt('Data/Network/CSV/LA_big_box_arterials/nodes_LA_toy.csv', delimiter = ',', skiprows = 1) nodes = nodes[:,1:3] ODs = Create_ODs_nodes_unique(nodes) def Get_key(item): return item[2] M = m.Manips() ODs_sorted = np.asarray(sorted(ODs, key = Get_key)) temp = ODs_sorted ODs_sorted = [] for od in temp: startnode = nodes[od[0]-1] endnode = nodes[od[1]-1] ODs_sorted.append([od[0], od[1], od[2], distance_on_unit_sphere(nodes[od[0]-1][1], nodes[od[0]-1][0], nodes[od[1]-1][1], nodes[od[1]-1][0]), m.Is_in_I210box(startnode[1], startnode[0], 'medium'), m.Is_in_I210box(endnode[1], endnode[0], 'medium')]) ODs_sorted = np.asarray(ODs_sorted) temp = ODs_sorted ODs_sorted = [] for od in temp: if od[4]+od[5]>1 : ODs_sorted.append(od[0:4]) ODs_sorted = np.asarray(ODs_sorted)
def test6(): """Test distance_on_unit_sphere()""" arc = util.distance_on_unit_sphere(34.049240, -118.238456, 34.073238, -118.284118) print 'distance in miles', 3960.0 * arc print 'distance in km', 6373.0 * arc
def los_angeles_2(parameters=None, delaytype='None'): """Generate larger map of L.A. with 664 links and 194 nodes """ nodes = np.genfromtxt('LA_medium_data/nodes_LA_toy.csv', delimiter=',', skiprows=1) nodes = nodes[:, 1:3] links = np.genfromtxt('LA_medium_data/links_qgis_cap.csv', delimiter=',', skiprows=1) tmp = links links = [] speed_limit_freeway = 33.33 #unit: m/s dict_cap2speed = { 600: 12.5, 1000: 16.67, 2000: 16.67, 4000: 16.67, 5000: 16.67, 1500: 16.67, 3000: 22.22, 6000: 22.22, 9000: 22.22, 4500: 22.22, 7500: 22.22, 10500: 22.22 } if delaytype == 'None': for startnode, endnode, category in tmp: arc = distance_on_unit_sphere(nodes[startnode - 1][2], nodes[startnode - 1][1], nodes[endnode - 1][2], nodes[endnode - 1][1]) if category == 1: ffdelay = arc / speed_limit_freeway if category == 2: ffdelay = arc / 16.67 if category != 0: links.append((startnode, endnode, 1, ffdelay, None)) if delaytype == 'Polynomial': theta = parameters degree = len(theta) for startnode, endnode, category, cap in tmp: arc = distance_on_unit_sphere(nodes[startnode - 1][1], nodes[startnode - 1][0], nodes[endnode - 1][1], nodes[endnode - 1][0]) if category == 1: ffdelay, slope = arc / speed_limit_freeway, 1 / cap if category == 2: if dict_cap2speed.has_key(cap): ffdelay, slope = arc / dict_cap2speed[cap], 1 / cap else: ffdelay, slope = arc / 16.67, 1 / cap coef = [ ffdelay * a * b for a, b in zip(theta, np.power(slope, range(1, degree + 1))) ] links.append( (startnode, endnode, 1, ffdelay, (ffdelay, slope, coef))) dest1 = 50 dest2 = 100 ODs = [] #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 10, 10, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 20, nodes, 6000.0) #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 30, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 40, nodes, 6000.0) #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 50, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 60, nodes, 6000.0) #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 70, nodes, 6000.0) #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 80, nodes, 6000.0) #ODs = [[ 57. , 50. , 4. ],[ 20. , 162. , 56.4]] ODs = Create_ODs_nodes_unique(nodes) ODs = ODs[1:5] print ODs return g.create_graph_from_list(nodes, links, delaytype, ODs, 'Larger map of L.A.')
def Dist_between_TAZ(self, tazi, tazj): return distance_on_unit_sphere(self.List_TAZ[self.dict_TAZ[tazi]][1], self.List_TAZ[self.dict_TAZ[tazi]][2], self.List_TAZ[self.dict_TAZ[tazj]][1], self.List_TAZ[self.dict_TAZ[tazj]][2])
def Dist_between_TAZ(self, tazi, tazj): return distance_on_unit_sphere(self.List_TAZ[self.dict_TAZ[tazi]][1], self.List_TAZ[self.dict_TAZ[tazi]][2], self.List_TAZ[self.dict_TAZ[tazj]][1], self.List_TAZ[self.dict_TAZ[tazj]][2])