Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sumo-user] Generate ticket data while simulating public transit line (route)

Hi Jackob,
I want to point out to your comments at github link- "when calling traci.person.getNextStage(personID, nextStageIndex) with a negative index, if the vehicle has already left the simulation, traci crashes when trying access the vehicle type".

You may be right that it happened due to the fact the vehicle has left. However, the error is due to accessing the previous stage and the properties of previous stage (not the vehicle type or ID of the current stage).

I am attaching a modified TraCI file for your reference. It raises exception on line 66, and a customized error is as follows:
    Error in Previous Stage retrieval, so, skip this personID: 2229
Interestingly, when I followed the person in persontrip.rou.xml, I found the following information.
   <person id="2229" depart="891.60" color="red">
        <walk edges="13 104 24 22 59 53cd 53[0] 78[1][1] 189[0] 189[1][0]+20000" busStop="busStop#31"/>
        <ride busStop="busStop#32" lines="14"/>
        <ride busStop="busStop#21" lines="89"/>
        <walk edges="134b 31 201 201c 204a[0] 204b[0] 204[1][0] 55b 55" busStop="busStop#35"/>
        <ride busStop="busStop#36" lines="13"/>
        <walk edges="114"/>
    </person>

It means that the error occurred when 2229 waiting for his second ride (lines="89"), and I am trying to get the previous stage information, his first ride (lines="14"), possibly, the corresponding vehicle of his first ride has left the simulation. Hence, we are unable to fetch the previous stage information.

Roughly, I guess that this situation might arise whenever there is a consecutive ride (public transit lines) for a passengers, in his plan.

thanks and regards,
Dillip Rout


On Mon, 25 May 2020 at 12:52, Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:
Thank you for the example files. The issue has been fixed (https://github.com/eclipse/sumo/issues/7060)
You can download the updated sumo version tomorrow at https://sumo.dlr.de/docs/Downloads.php#sumo_-_latest_development_version

regards,
Jakob

Am Mo., 25. Mai 2020 um 07:50 Uhr schrieb Tripplanner Mumbai <tripplanner.dr@xxxxxxxxx>:
It is not clear from the log files what error it has. The program stops by stating that "FatalTraCIError: connection closed by SUMO". I am sending the files as attachment with the following details.

  • SUMO-version - 1.6.0  and operating system - Ubuntu 18.04 LTS
  • screenshot attached
  • input files attached
  • line 65 in demo.py (attached) creates FatalTraCIError
Kindly try to resolve it.
thanks and regards,
Dillip Rout

On Sun, 24 May 2020 at 21:27, Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:
Hello,
the FatalTraCIError can mean one of two things:
1) Sumo had an error (you will find a reason in the log file if you run sumo with option --log)
2) Sumo encountered a bug and crashed. In that case please send me input files for reproducing the issue (https://sumo.dlr.de/docs/FAQ.html#how_do_i_report_erroneous_behavior_of_a_sumo_application)
you can send the files directly to me or you can create an issue on github and attach the files there.

regards,
Jakob

Am Fr., 22. Mai 2020 um 08:07 Uhr schrieb Tripplanner Mumbai <tripplanner.dr@xxxxxxxxx>:
As per the discussion, I tried to extract the stage information using TraCI and combine the log files to generate the ticket data. However, for some of the cases, I get fatal errors as follows.
 
File "/home/dhrien/Documents/sumos/Bologna/acosta_persontrips/demo.py", line 86, in run  prevStage = traci.person.getStage(peopleIDs[i],-1)
File "/usr/share/sumo/tools/traci/_person.py", line 192, in getStage tc.VAR_STAGE, personID))
File "/usr/share/sumo/tools/traci/connection.py", line 158, in _checkResult result = self._sendExact()
File "/usr/share/sumo/tools/traci/connection.py", line 101, in _sendExact raise FatalTraCIError("connection closed by SUMO")
FatalTraCIError: connection closed by SUMO

The above error is due the following code segment written inside run method of TraCI program.
            currStage = traci.person.getStage(peopleIDs[i])
            if currStage.type == 3: #record only if driving or riding                
                try:
                    prevStage = traci.person.getStage(peopleIDs[i],-1)
                except FatalTraCIError:
                    print("Previous Stage Error for Person",peopleIDs[i])
                    continue

Note that previous stage is retrieved only if a person is boarded into a vehicle. Also, l am trying handle the exception but the program stops. Further, I do check if previous stage is null (None) and then operate but unfortunately nothing works at this moment.

Please suggest.

thanks and regards,
Dillip Rout

On Thu, 7 May 2020 at 12:46, Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:
Yes. If you need to retrieve data while the simulation is still running, you generally need to use traci. If you can wait until the simulation is finished you can retrieve the ticket information from the xml outputs as well.

Am Do., 7. Mai 2020 um 09:06 Uhr schrieb Tripplanner Mumbai <tripplanner.dr@xxxxxxxxx>:
Hello Jackob,
Thanks in advance.

On Thu, 7 May 2020 at 12:13, Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:
Hello,
during the simulation, you can use traci.person.getStage to access past, current and future stage information including the destination busStop of each stage (which is the origin stop for the subsequent stage).
regards,
Jakob

Am Do., 7. Mai 2020 um 08:36 Uhr schrieb Tripplanner Mumbai <tripplanner.dr@xxxxxxxxx>:
Hello,
I am trying to capture the origin and destination bus stops of each passenger (or on aggregate for a group) and issue tickets accordingly. I found that <stopinfo> has information about the line, number of passengers boarded and the source bus stop, as given below.

<stopinfo id="bus_14.3" type="bus" lane="109[1][0]+20003_1" pos="30.31" parking="0" started="983.00" ended="1080.00" delay="0.00" initialPersons="18" loadedPersons="3" unloadedPersons="12" initialContainers="0" loadedContainers="0" unloadedContainers="0" busStop="busStop#34"/>

Also, it can be noted that <person> has information about the destination stop while riding, as given below.

<person id="3" depart="1.20" color="red">

     <walk edges="82 53[0] 78[1][1] 189[0] 189[1][0]+20000" busStop="busStop#31"/>

     <ride busStop="busStop#33" lines="14"/>

</person>


Now, the question is how to capture both origin and destination information while the simulation is going on. Just like the stop information, is there any way to generate the ticket information.


regards,

Dillip Rout

_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
#!/usr/bin/env python

import os
import sys
import optparse
import numpy as np
#import StringIO

#global variables
personLogFile = ""
personIDLogFile = ""
MAX_STEPS = 3600
STAGE_CYCLES = 5 #assumes that a stage is at least 5 steps long, so, capture only after a stage cycle

# we need to import some python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)    
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")


from sumolib import checkBinary  # Checks for the binary in environ vars
import traci


def get_options():
    opt_parser = optparse.OptionParser()
    opt_parser.add_option("--nogui", action="store_true",
                         default=False, help="run the commandline version of sumo")
    options, args = opt_parser.parse_args()
    return options

def openLogFiles():
    global personLogFile, personIDLogFile
    personLogFile = open("person-logs.txt", "w")
    personIDLogFile = open("person-id-logs.txt", "w")
# contains TraCI control loop
def run():
    step = 0
    personFound = 0    
    global personLogFile, MAX_STEPS, STAGE_CYCLES, personIDLogFile
    
    while traci.simulation.getMinExpectedNumber() > 0: #simulate until all vehicles arrive
        traci.simulationStep() #capture the steps of simulation 
        #print(step)        
        step = step + 1
        if step % STAGE_CYCLES != 0:
            continue
        
        strLog = ""
               
        peopleIDs = traci.person.getIDList() #Returns a list of person IDs       
        
        for i in range(len(peopleIDs)):
                #print("PersonID:",peopleIDs[i],"stage:",traci.person.getStage(peopleIDs[i]))
            #if len(traci.person.getVehicle(peopleIDs[i])) != 0: # if not empty
            currStage = traci.person.getStage(peopleIDs[i])
            
            if currStage.type == 3: #record only if driving or riding 
                
                personIDLogFile.write("PersonID: "+str(peopleIDs[i])+" StageType: "+ str(currStage.type) +"\n")
                vehicleID = traci.person.getVehicle(peopleIDs[i])
                
                try:
                    prevStage = traci.person.getStage(peopleIDs[i],-1) 
#                except FatalTraCIError:
#                    print("Previous Stage Error for Person",peopleIDs[i])
#                    continue
                except:
                    print("Error in Previous Stage retrieval, so, skip this personID: ", peopleIDs[i])
                    continue                
                
                
                if prevStage == None or currStage == None or vehicleID == None or vehicleID == "":
                    continue #do not record it
                strLog = strLog + "PersonID: %s" % (peopleIDs[i])
                strLog = strLog + "\t SourceStop: %s" % (prevStage.destStop)
                strLog = strLog + "\t DestStop: %s" % (currStage.destStop)
                strLog = strLog + "\t LineNo: %s" % (currStage.line)
                strLog = strLog + "\t VehicleNo: %s" % (vehicleID) + "\n"
                              
#                strLog = strLog + "PersonID: %s, current stage: %s, vehicle: %s, previous stage: %s" % (peopleIDs[i],traci.person.getStage(peopleIDs[i]),traci.person.getVehicle(peopleIDs[i]),) + "\n"
                if i % 100 == 0: #flush the output if more people are there
                    personLogFile.write(strLog)
                    strLog = ""
                    
 
        if strLog != "":
            personLogFile.write(strLog)
        
        if step > MAX_STEPS:
            break
    
    # while loop has ended        
    print("total steps:",step)    
    traci.close()   #end simulation
    sys.stdout.flush()

def closeLogFiles():
    global personLogFile, personIDLogFile
    personLogFile.close()
    personIDLogFile.close()

# main entry point
if __name__ == "__main__":
    options = get_options()
    
    openLogFiles()
    
    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    traci.start([sumoBinary, "-c", "run.sumo.cfg"])
    run()
    
    closeLogFiles()

Back to the top