plan_gen_cli.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. ''' Python generator for MATSim plans. '''
  3. import sys
  4. import lxml.etree as etree
  5. import numpy as np
  6. import plan_gen.plan_gen as pg
  7. # TODO: make these constants as user params
  8. D_CENTERS = [(27, 40), (32, 8)]
  9. D_RADIUS = [10, 10]
  10. if __name__ == '__main__':
  11. # command line arguments
  12. if len(sys.argv) != 2:
  13. print('usage:', sys.argv[0], '<params>')
  14. sys.exit(-1)
  15. DICT_PARAMS = pg.parse_params(sys.argv[1])
  16. NB_CLUSTERS = DICT_PARAMS['nc']
  17. NB_PERSONS = DICT_PARAMS['np']
  18. INPUT_NETWORK = DICT_PARAMS['nw']
  19. # prepare data
  20. NODES = pg.get_nodes(INPUT_NETWORK)
  21. CLUSTERS = pg.make_clusters(NB_CLUSTERS, NODES)
  22. H_DENSITIES = pg.make_densities(NB_CLUSTERS, D_CENTERS, D_RADIUS)
  23. W_DENSITIES = pg.make_densities(NB_CLUSTERS)
  24. # make xml
  25. PERSONS = [pg.rand_person(NODES, CLUSTERS, H_DENSITIES, W_DENSITIES) for _ in range(NB_PERSONS)]
  26. PLANS = pg.make_plans(PERSONS)
  27. # print XML
  28. print('<?xml version="1.0" ?>')
  29. print('<!DOCTYPE plans SYSTEM "http://www.matsim.org/files/dtd/plans_v4.dtd">')
  30. print(etree.tostring(PLANS, pretty_print=True).decode('utf-8'))