Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. help = False
  2.  
  3. conn_string = "host='localhost' dbname='slovakia' user='postgres' password='admin'"
  4. # print the connection string we will use to connect
  5. print("Connecting to database\n ->%s" % (conn_string))
  6.  
  7. # get a connection, if a connect cannot be made an exception will be raised here
  8. conn = psycopg2.connect(conn_string)
  9.  
  10. make_new_matrix_to_file("all_data_100_60_00.matrix", 100, 60, help)
  11.  
  12. new_m = load_matrix_from_file('all_data_120_00.matrix')
  13. # use when you want to show new grid at map ... make one
  14. #put_matrix_coordinates_into_json_file("matrix_" + str(len(new_m)) + "_cells.json", new_m)
  15.  
  16. matrix = []
  17. # delete cells which have less than 100 citizens in them
  18. for c in new_m:
  19.     if c.population > 100:
  20.         matrix.append(c)
  21.  
  22. matrix = set_ranking(matrix)
  23.  
  24. # load existing charging stations from json file
  25. existing_charging_stations = get_existing_stations_from_file("sk_stations.json")
  26.  
  27. # make array of Stations_in_cell type, so we will know how many stations should belong to the cell
  28. stations_in_cells_arr = set_count_of_stations_in_cell(matrix, existing_charging_stations)
  29.  
  30. # make new positions for stations
  31. # new_charging_stations = make_new_positions_of_stations_random(stations_in_cells_arr)
  32. new_charging_stations = make_new_positions_of_sations_parts(stations_in_cells_arr, 4)
  33. # new_charging_stations = make_new_positions_of_sations_distance(stations_in_cells_arr)
  34.  
  35. # make json files to store results of algorithm
  36. if len(existing_charging_stations) != len(new_charging_stations):
  37.     print("Count of new stations and existing stations is not equal")
  38.     print(len(existing_charging_stations), len(new_charging_stations))
  39. else:
  40.     make_files_with_positions(existing_charging_stations,
  41.                               new_charging_stations,
  42.                               "./results/existing_without_120_0_0_0_10_10_10_0_0_0_parts.json",
  43.                               "./results/new_without_120_0_0_0_10_10_10_0_0_0_parts.json")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement