Ejemplo n.º 1
0
def test():
  scenario = [log(1.2), log(10), log(0.01), log(1)]

  global master_transit_dict
  global master_dict
  master_dict = {}
  master_transit_dict = {}
  master_dict['1'] = {'new_id': 1, 'ext_lnSa': 0.8}
  master_dict['12'] = {'new_id': 2, 'ext_lnSa': 0.8}
  master_dict['13'] = {'new_id': 3, 'ext_lnSa': 0.8}
  master_transit_dict['13'] = {'new_id': 4, 'beta': 1, 'ext_lnSa': 1.6}

  for thing in range(50):
    br_int, br, num = damage_bridges(scenario)
    print 'bridges out in terms of new ids: ', br
    assert len(br) >= 1, 'at least one bridge should fail'
    assert len(br) <= 3, 'no more than 3 bridges fail'
  print 'now let us try to test if we change the capacity, it fails'
  master_dict['13']['ext_lnSa'] = 0.001
  br_int, br, num = damage_bridges(scenario)
  assert 3 in br, 'now that bridge new id 3 has almost no structural demand capacity, it should fail'
  G = nx.read_gpickle("input/graphMTC_CentroidsLength6int.gpickle")
  num_nodes = len(G.nodes())
  G = add_superdistrict_centroids(G)
  assert len(G.nodes()) == 34 + 2 + num_nodes, 'nodes should have changed'
  print compute_flow(G)
Ejemplo n.º 2
0
def compute_performance(scenario, G, index, demand, no_damage_travel_time, no_damage_vmt):
  import time
  import pickle
  import pdb
  import networkx 
  import util
  from travel_main_simple_simplev3 import damage_bridges
  from travel_main_simple_simplev3 import measure_performance
  from travel_main_simple_simplev3 import damage_network
  from travel_main_simple_simplev3 import get_graph
  start_time = time.time()

  if G == None:
    G = get_graph()

  #figure out bridge damage for each scenario
  damaged_bridges_internal, damaged_bridges_new, num_damaged_bridges = damage_bridges(scenario) #e.g., [1, 89, 598] #num_bridges_out is highway bridges only

  # #figure out network damage and output Cube files to this effect
  G = damage_network(damaged_bridges_internal, damaged_bridges_new, G, time.strftime("%Y%m%d")+'_filesForCube/', index)

  # #figure out impact (performance metrics)
  flow, shortest_paths, travel_time, vmt = measure_performance(G, num_damaged_bridges, demand, no_damage_travel_time, no_damage_vmt)
  G = util.clean_up_graph(G)
  print 'total scenario time: ', time.time() - start_time
  return damaged_bridges_internal, damaged_bridges_new, num_damaged_bridges, flow, shortest_paths, travel_time, vmt