Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sumo-user] traci and libsumo

Hello Jakob, community,

I have another problem..
traci.simulation.Stage is a collection.namedtuple so I can manipulate it using stage._replace(travelTime=1.0),
but if I do the same thing with libsumo.libsumo.TraCIStage I get
"AttributeError: 'TraCIStage' object has no attribute '_replace'"
and if I try to directly assign something with stage.travelTime = 1.0 I get 
"TypeError: 'tuple' object does not support item assignment"

I don't understand how to manipulate it. How it's intended to be used?

Regards,
Lara

On Tue, 23 Apr 2019 14:27:53 +0200
Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:

> constants is an attribute of libsumo rather than a module so you have to
> write something like
> 
> import libsumo as traci
> tc = traci.constants
> 
> Am Di., 23. Apr. 2019 um 14:14 Uhr schrieb Lara CODECA <
> lara.codeca@xxxxxxxxxx>:  
> 
> > Thank you, Jakob.
> >
> > I tried "import libsumo.constants as tc"
> > and I get a "ModuleNotFoundError: No module named 'libsumo.constants'"
> > that is why I asked. I suppose the shortcut is not working anymore.
> >
> > I'll remove the stepListener and I'll try again.
> >
> > Cheers,
> > Lara
> >
> > On Tue, 23 Apr 2019 12:26:13 +0200
> > Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:
> >  
> > > - libsumo.constants is the same as traci.constants
> > > - traci.addStepListener is a pure python client feature. It's missing  
> > from  
> > > libsumo and all other traci clients (hence the error in  
> > simple.example.py)  
> > > - the 'stageType' error was due to
> > > https://github.com/eclipse/sumo/issues/5502. Please update sumo and use  
> > the  
> > > member 'type' instead.
> > >
> > > regards,
> > > Jakob
> > >
> > >
> > > Am Di., 23. Apr. 2019 um 10:09 Uhr schrieb Lara CODECA <  
> > > lara.codeca@xxxxxxxxxx>:  
> > >  
> > > > Hello Michael,
> > > >
> > > > I'm using python 3, so that is fine.
> > > > libsumo has not constant and no StepListener, so I still need to import
> > > > traci, right?
> > > >
> > > > Using
> > > > https://github.com/lcodeca/SUMOActivityGen/blob/master/activitygen.py  
> > and  
> > > > fixing lines 34 and 35 to use libsumo you have the following error:
> > > >
> > > > Traceback (most recent call last):
> > > >   File "./activitygen.py", line 1342, in <module>
> > > >     _main()
> > > >   File "./activitygen.py", line 1327, in _main
> > > >     mobility.mobility_generation()
> > > >   File "./activitygen.py", line 223, in mobility_generation
> > > >     self._compute_trips_per_slice()
> > > >   File "./activitygen.py", line 365, in _compute_trips_per_slice
> > > >     _chain, _modes)
> > > >   File "./activitygen.py", line 521, in _generate_trip_traci
> > > >     route[-1].stageType == tc.STAGE_DRIVING):
> > > >   File
> > > > "/home/drone/Applications/SUMO/sumo-git/sumo/tools/libsumo/libsumo.py",
> > > > line 996, in <lambda>
> > > >     __getattr__ = lambda self, name: _swig_getattr(self, TraCIStage,  
> > name)  
> > > >   File
> > > > "/home/drone/Applications/SUMO/sumo-git/sumo/tools/libsumo/libsumo.py",
> > > > line 80, in _swig_getattr
> > > >     raise AttributeError("'%s' object has no attribute '%s'" %
> > > > (class_type.__name__, name))
> > > > AttributeError: 'TraCIStage' object has no attribute 'stageType'
> > > >
> > > > The problem is not in the call:
> > > > route = traci.simulation.findIntermodalRoute(stage.fromEdge, p_edge,
> > > > depart=_new_start_time, walkFactor=.9, modes=_mode, pType=_ptype,
> > > > vType=_vtype)
> > > > but in the returned value. That is why I was looking for the
> > > > documentation..
> > > >
> > > > In  
> > https://github.com/lcodeca/PyPML/blob/master/examples/simple.example.py  
> > > > if you change traci with libsumo,
> > > > the error is the following:
> > > > Traceback (most recent call last):
> > > >   File "./simple.example.py", line 125, in <module>
> > > >     _main()
> > > >   File "./simple.example.py", line 60, in _main
> > > >     monitor = ParkingMonitor(traci, parking_monitor_options)
> > > >   File "/home/drone/EURECOM/Projects/GITHUB/PyPML/pypml/pypml.py", line
> > > > 245, in __init__
> > > >     tc.VAR_PARKING_ENDING_VEHICLES_IDS))
> > > > TypeError: simulation_subscribe() takes no keyword arguments
> > > >
> > > > More precisely, here the question is in how to handle
> > > >  
> > self._traci_handler.simulation.subscribe(varIDs=(tc.VAR_PARKING_STARTING_VEHICLES_IDS,  
> > > > tc.VAR_PARKING_ENDING_VEHICLES_IDS))
> > > > where self._traci_handler is the return value of traci.start()
> > > >
> > > > All the code works fine with SUMO 1.2.0 and Python TraCI APIs.
> > > >
> > > > Thanks for your time!
> > > > Lara
> > > >
> > > > On Fri, 19 Apr 2019 20:49:51 +0200
> > > > Michael Behrisch <oss@xxxxxxxxxxx> wrote:
> > > >  
> > > > > Hi Lara,
> > > > > if libsumo is compiled correctly and is in your python path (together
> > > > > with the dll / so file), it should really be just a matter of "import
> > > > > libsumo as traci". It works only with Python3 however. Please tell us
> > > > > what ypu tried and which errors occured.
> > > > >
> > > > > Best regards,
> > > > > Michael
> > > > >
> > > > > Am 18.04.19 um 10:35 schrieb Lara CODECA:  
> > > > > > Hello community,
> > > > > >
> > > > > > I wrote a python library that uses traci to implement a parking  
> > > > monitoring system (https://github.com/lcodeca/PyPML).  
> > > > > > I'm trying to find a way to use libsumo (or even better both,  
> > leaving  
> > > > the choice to the user) in order to improve the performances.  
> > > > > >
> > > > > > Unfortunately, although is written in  
> > https://sumo.dlr.de/wiki/Libsumo  
> > > > that "Existing traci scripts can mostly be reused by calling import  
> > libsumo  
> > > > as traci", it's not true for me.  
> > > > > >
> > > > > > I always used http://sumo.sourceforge.net/pydoc/traci.html to  
> > use  
> > > > traci, but this is not true for libsumo.  
> > > > > > I'm trying to use  
> > > > https://sumo.dlr.de/daily/doxygen/d8/d1c/class_tra_c_i_a_p_i.html  
> > because  
> > > > it's written "C++ interface based on static functions and a few simple
> > > > wrapper classes", but I don't understand how to apply this  
> > documentation to  
> > > > a python3 style use of traci.  
> > > > > >
> > > > > > I cannot find any explicit example in the wiki that gives me the  
> > hint  
> > > > on how to do this.  
> > > > > >
> > > > > > I would love if someone could point me in the right direction..
> > > > > >
> > > > > > All the Best!
> > > > > > Lara
> > > > > >  
> > > > >
> > > > >  
> > > >
> > > >
> > > >
> > > > --
> > > > Lara CODECA
> > > > Postdoc
> > > > Tel : 04.93.00.81.51
> > > >
> > > > EURECOM
> > > > Campus SophiaTech
> > > > http://www.eurecom.fr/
> > > > _______________________________________________
> > > > sumo-user mailing list
> > > > sumo-user@xxxxxxxxxxx
> > > > To change your delivery options, retrieve your password, or unsubscribe
> > > > from this list, visit
> > > > https://www.eclipse.org/mailman/listinfo/sumo-user
> > > >  
> >
> >
> >
> > --
> > Lara CODECA
> > Postdoc
> > Tel : 04.93.00.81.51
> >
> > EURECOM
> > Campus SophiaTech
> > http://www.eurecom.fr/
> >  



-- 
Lara CODECA
Postdoc
Tel : 04.93.00.81.51

EURECOM
Campus SophiaTech
http://www.eurecom.fr/


Back to the top