plan_gen_cli.py 1.3 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. if __name__ == '__main__':
  8. # command line arguments
  9. if len(sys.argv) != 2:
  10. print('usage:', sys.argv[0], '<params>')
  11. sys.exit(-1)
  12. DICT_PARAMS = pg.parse_params(sys.argv[1])
  13. NB_CLUSTERS = DICT_PARAMS['nc']
  14. NB_PERSONS = DICT_PARAMS['np']
  15. INPUT_NETWORK = DICT_PARAMS['nw']
  16. H_CENTERS = DICT_PARAMS['hc'] if 'hc' in DICT_PARAMS else None
  17. W_CENTERS = DICT_PARAMS['wc'] if 'wc' in DICT_PARAMS else None
  18. H_RADIUS = DICT_PARAMS['hr'] if 'hr' in DICT_PARAMS else None
  19. W_RADIUS = DICT_PARAMS['wr'] if 'wr' in DICT_PARAMS else None
  20. # prepare data
  21. NODES = pg.get_nodes(INPUT_NETWORK)
  22. CLUSTERS = pg.make_clusters(NB_CLUSTERS, NODES)
  23. H_DENSITIES = pg.make_densities(NB_CLUSTERS, H_CENTERS, H_RADIUS)
  24. W_DENSITIES = pg.make_densities(NB_CLUSTERS, W_CENTERS, W_RADIUS)
  25. # make xml
  26. PERSONS = [pg.rand_person(NODES, CLUSTERS, H_DENSITIES, W_DENSITIES) for _ in range(NB_PERSONS)]
  27. PLANS = pg.make_plans(PERSONS)
  28. # print XML
  29. print('<?xml version="1.0" ?>')
  30. print('<!DOCTYPE plans SYSTEM "http://www.matsim.org/files/dtd/plans_v4.dtd">')
  31. print(etree.tostring(PLANS, pretty_print=True).decode('utf-8'))