#!/usr/bin/env python3 ''' Python generator for MATSim plans. ''' import sys import lxml.etree as etree import plan_gen.plan_gen as pg if __name__ == '__main__': # command line arguments if len(sys.argv) != 2: print('usage:', sys.argv[0], '') sys.exit(-1) DICT_PARAMS = pg.parse_params(sys.argv[1]) NB_PERSONS = DICT_PARAMS['np'] INPUT_NETWORK = DICT_PARAMS['nw'] INPUT_HOME_CLUSTERS = DICT_PARAMS['hc'] if 'hc' in DICT_PARAMS else '' INPUT_WORK_CLUSTERS = DICT_PARAMS['wc'] if 'wc' in DICT_PARAMS else '' # get data NODES = pg.read_nodes(INPUT_NETWORK) HOME_CLUSTERS = [pg.read_nodes(cluster) for cluster in INPUT_HOME_CLUSTERS] WORK_CLUSTERS = [pg.read_nodes(cluster) for cluster in INPUT_WORK_CLUSTERS] # make xml PERSONS = [pg.rand_person(NODES, HOME_CLUSTERS, WORK_CLUSTERS) for _ in range(NB_PERSONS)] PLANS = pg.make_plans(PERSONS) # print XML print('') print('') print(etree.tostring(PLANS, pretty_print=True).decode('utf-8'))