Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sumo-user] Unterminated comment error when using the route file generated by duarouter

I can confirm that the file has no unterminated comments and I have no issue with fully loading it into a simulation.
My recommendation is to run sumo with option --log log.txt and then provide the log file.


Am Mo., 13. Jan. 2025 um 01:38 Uhr schrieb Bon Choe via sumo-user <sumo-user@xxxxxxxxxxx>:
Hi all,


I ran several simulations with the route file generated by duarouter but I have encountered the error intermittently as a following terminal message:

```
200.00 vehicles loaded.
0.00 vehicles discarded.
200.00 vehicles written.
Success.
Success.up to time step: 200.02
OV routes are randomly generated with weighted od matrix
Error: unterminated comment
 In file '/home/bon/LaneRPM/Trip/ODTrip/OVODroute_crowded.rou.xml'
 At line/column 21/1.
Traceback (most recent call last):
  File "/home/bon/LaneRPM/DQN/LaneRPM_RouteDQN_train.py", line 489, in <module>
    state, info = env.reset() # dict state
  File "/home/bon/LaneRPM/LaneRPM/rl/maskedRouteEnv.py", line 276, in reset
    traci.start(TRACI_CMD,label=self._env_config['label'])
  File "/home/bon/LaneRPM/.venv/lib/python3.10/site-packages/traci/main.py", line 147, in start
    result = init(sumoPort, numRetries, "localhost", label, sumoProcess, doSwitch, traceFile, traceGetters)
  File "/home/bon/LaneRPM/.venv/lib/python3.10/site-packages/traci/main.py", line 119, in init
    return con.getVersion()
  File "/home/bon/LaneRPM/.venv/lib/python3.10/site-packages/traci/connection.py", line 382, in getVersion
    result = self._sendCmd(command, None, None)
  File "/home/bon/LaneRPM/.venv/lib/python3.10/site-packages/traci/connection.py", line 232, in _sendCmd
    return self._sendExact()
  File "/home/bon/LaneRPM/.venv/lib/python3.10/site-packages/traci/connection.py", line 137, in _sendExact
    raise FatalTraCIError("Connection closed by SUMO.")
traci.exceptions.FatalTraCIError: Connection closed by SUMO.
Quitting (on error).
```

First of all, line 21, column 1 in the `.xml` route file generated by duarouter seems to have no trouble in terms of comment rule. (See the cursor position on below capture. This `.xml` file is also attached in this mail.) This is why I get trouble in debugging.
image.png

Though I thought the very immediate cause of my error was the `duarouter` that generated the `.xml` file, I will attach the method that I used for generating the route file for your information.
```
def OVRoute_crowded(
    n=500,
    pois = {
        '1_3': 0.3,
        '3_1': 0.3,
    },
    crowdedTo=True, # pois are destination if True, origin otherwise
):
    now = datetime.datetime.now()
   
    # Check p1 and p2 are properly set
    assert (isinstance(pois,dict)),\
        "Input argument `pois` should be a form of dict"
    assert (p >= 0 for p in pois.values()), \
        "All given probabilities should be non-negative"
    assert (sum(pois.values()) < 1), \
        "Given probabilities p1 or p2 is too high. They should be low such that p1 + p2 > 1"
   
    tazs = []
    for i in range(5):
        for j in range(5):
            tazs.append(f'{i}_{j}')
   
    tazWeights = {taz: \
        (pois[taz] if taz in pois.keys() \
         else (1 - sum(pois.values())) / (len(tazs) - len(pois))) \
        for taz in tazs}
   
    ods = {od: 0 for od in product(tazs, repeat=2)}
   
    for i in range(n):
        taz1 = random.choice(tazs)
        taz2 = random.choices(list(tazWeights.keys()),
                             weights=tazWeights.values())[0]
        while taz1 == taz2:
            taz1 = random.choice(tazs)
        if crowdedTo == True: # treat taz2 as destination
            ods[(taz1, taz2)] += 1
        else: # treat taz1 as destination
            ods[(taz2, taz1)] += 1
       
    with open(OD_CROWDED_FILE, 'w') as f:
            f.write(f'''<?xml version="1.0" encoding="UTF-8"?>

        <!-- generated on {now.strftime('%Y-%m-%d %H:%M:%S')} by OVRoute_crowded() from LaneRPM/utils.py -->

        <data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/datamode_file.xsd">
        ''')
            f.write('    <interval id="DEFAULT_VEHTYPE" begin="0" end="1">\n')
            for od, value in ods.items():
                f.write(f'        <tazRelation from="{od[0]}" to="{od[1]}" count="{value}"/>\n')
            f.write(f'''    </interval>
        </data>''')
   
    cmds = [
        f'od2trips -v --taz-files {TAZ_FILE} --tazrelation-files {OD_CROWDED_FILE} -o {ODTRIP_FILE}',
        f'duarouter --net-file {NET_FILE} --route-files {ODTRIP_FILE} --routing-algorithm "CH" --output-file {OV_ODROUTE_CROWDED_FILE}',
    ]
   
    for cmd in cmds:
        subprocess.run(cmd,shell=True)
    custom_print('OV routes are randomly generated with weighted od matrix')
   
    return OV_ODROUTE_CROWDED_FILE
```

I am eager to resolve this error that kept disrupting my simulation.


Thank you for reading this lengthy mail.

Looking forward to hearing from you soon.


Best regards,
Bon
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user

Back to the top