plan_gen_cli.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. ''' Python generator for MATSim plans. '''
  3. import sys
  4. import lxml.etree as etree
  5. import plan_gen.plan_gen as pg
  6. if __name__ == '__main__':
  7. # command line arguments
  8. if len(sys.argv) != 2:
  9. print('usage:', sys.argv[0], '<params>')
  10. sys.exit(-1)
  11. DICT_PARAMS = pg.parse_params(sys.argv[1])
  12. NB_PERSONS = DICT_PARAMS['np']
  13. INPUT_NETWORK = DICT_PARAMS['nw']
  14. INPUT_HOME_CLUSTERS = DICT_PARAMS['hc'] if 'hc' in DICT_PARAMS else ''
  15. INPUT_WORK_CLUSTERS = DICT_PARAMS['wc'] if 'wc' in DICT_PARAMS else ''
  16. # get data
  17. NODES = pg.read_nodes(INPUT_NETWORK)
  18. HOME_CLUSTERS = [pg.read_nodes(cluster) for cluster in INPUT_HOME_CLUSTERS]
  19. WORK_CLUSTERS = [pg.read_nodes(cluster) for cluster in INPUT_WORK_CLUSTERS]
  20. # make xml
  21. PERSONS = [pg.rand_person(NODES, HOME_CLUSTERS, WORK_CLUSTERS) for _ in range(NB_PERSONS)]
  22. PLANS = pg.make_plans(PERSONS)
  23. # print XML
  24. print('<?xml version="1.0" ?>')
  25. print('<!DOCTYPE plans SYSTEM "http://www.matsim.org/files/dtd/plans_v4.dtd">')
  26. print(etree.tostring(PLANS, pretty_print=True).decode('utf-8'))