예제 #1
0
def export_matrices(prefix, num_rows, num_cols, num_routes_per_od_pair, num_nonzero_routes_per_o):
  # G = (V,E,w)
  graph, routes, sensors = small_graph.generate_small_graph(num_cols=num_cols,
          num_rows=num_rows, num_routes_per_od_pair=num_routes_per_od_pair)
  # (O,D),R,alpha
  (flow_portions,flow_portions_OD,flow_OD) = flows.annotate_with_flows(graph, 
          routes, 1.0, num_nonzero_routes_per_o)
  
  # static matrix considering origin flows
  phi, alpha, mu, f, num_routes = generate_static_matrix(graph, routes,
          sensors, flow_portions)
  scipy.io.savemat(prefix + 'small_graph.mat', {'phi': phi, 'real_a': alpha, 'w': mu,
          'f': f, 'block_sizes': num_routes}, oned_as='column')

  # static matrix considering origin-destination flows
  phi, alpha, mu, f, num_routes = generate_static_matrix_OD(graph, routes,
          sensors, flow_portions_OD, flow_from_each_node=flow_OD)
  scipy.io.savemat(prefix + 'small_graph_OD.mat', {'phi': phi, 'real_a': alpha, 'w': mu,
          'f': f, 'block_sizes': num_routes}, oned_as='column')
          
  # random matrix 'considering origin flows'
  phi, alpha, mu, f, num_routes = generate_random_matrix(graph, routes,
          sensors, flow_portions)
  scipy.io.savemat(prefix + 'small_graph_random.mat', {'phi': phi, 'real_a': alpha, 'w': mu,
          'f': f, 'block_sizes': num_routes}, oned_as='column')
예제 #2
0
        for j in xrange(len(route_indices_from_node)):
            for i in xrange(len(f)):
                info = where_did_f_come_from[i]
                if  route_indices_from_node[j] in info:
                    phi[i, j] = flow_from_each_node
        phis.append(phi)

    print ":end"

    print where_did_f_come_from

    return np.hstack(phis), f

if __name__ == '__main__':
  graph, routes, sensors = small_graph.generate_small_graph()
  (flow_portions,_,_) = flows.annotate_with_flows(graph, routes)
  
  phi, alpha, mu, f, num_routes = static_matrix.generate_static_matrix(graph, routes, sensors, flow_portions)

#  print len(routes)

#  print len(f)

  phi2, f2 = generate_augmented_matrix(graph, routes, sensors, flow_portions)
  np.savetxt('phi.txt', phi2)
#  print sum(np.transpose(phi2))
#  print len(f2)
#  print phi2.shape

#  print phi.shape