Traffic micro-simulation calibration and validation : Différence entre versions
(→How to use VISSIM via a python script) |
(→How to use VISSIM via a python script) |
||
Ligne 1 : | Ligne 1 : | ||
− | ==How to use | + | ==How to use Vissim via a python script== |
− | As found in the | + | As found in the Vissim manual, an external program can communicate with Vissim via the COM interface, which is basically a Window's built-in interface designed to have programs interacting with each other by sharing their binary components. Via COM, it is possible to access the data and the functions of Vissim. The actual interaction between python and Vissim is taken care by each program's COM interface, and we thus only need to know the names of the objects that we want to access inside Vissim. So far as using COM with python, one will need to run the win32com package, which is part of the PyWin32 Extension. The package to import is ''win32com.client''. |
'''import''' win32com.client | '''import''' win32com.client | ||
+ | Additonnaly, it is important to note that in order to use Vissim through the COM interface, one needs to have a complete Vissim version installed. As such, any version prior to Vissim 4.0 will not work, and the student and demo versions are striped of their COM interface. | ||
+ | |||
For more information about what is a COM interface: http://msdn.microsoft.com/en-us/library/windows/desktop/ff485850(v=vs.85).aspx. <br> | For more information about what is a COM interface: http://msdn.microsoft.com/en-us/library/windows/desktop/ff485850(v=vs.85).aspx. <br> | ||
Getting PyWin32: http://starship.python.net/~skippy/win32/Downloads.html. | Getting PyWin32: http://starship.python.net/~skippy/win32/Downloads.html. | ||
===Starting Vissim=== | ===Starting Vissim=== | ||
− | Two commands can be used to start Vissim: ''Dispatch'' and ''dynamic.Dispatch''. The former will prompt a new Vissim instance to open and assign it to the variable you specified. If a Vissim instance is already open, it will ignore it. This can be problematic if you count on using more than one instance in parallel, since a single Vissim license can only handle 4 instances at a time. To avoid such a problem, you can use the ''dynamic.Dispatch'' | + | Two commands can be used to start Vissim: ''Dispatch()'' and ''dynamic.Dispatch()'' methods. The former will prompt a new Vissim instance to open and assign it to the variable you specified. If a Vissim instance is already open, it will ignore it. This can be problematic if you count on using more than one instance in parallel, since a single Vissim license can only handle 4 instances at a time. To avoid such a problem, you can use the ''dynamic.Dispatch()'' method, which will first assign already opened Vissim instances before opening new ones. |
Regardless of which of the two options is picked, the call needs to specify the version of Vissim to start. The version number is obtained by multiplying the real Vissim version by 100. Following this rule, version 5.4 becomes 540 and 6.0 becomes 600. The Following script exemple starts (or assigns an already opened) instance of Vissim 6.0: | Regardless of which of the two options is picked, the call needs to specify the version of Vissim to start. The version number is obtained by multiplying the real Vissim version by 100. Following this rule, version 5.4 becomes 540 and 6.0 becomes 600. The Following script exemple starts (or assigns an already opened) instance of Vissim 6.0: | ||
Ligne 18 : | Ligne 20 : | ||
'''return''' 'StartError' | '''return''' 'StartError' | ||
− | ===Loading a | + | ===Loading a save file=== |
− | + | All the information needed for the actual simulation (links, vehicule behaviors, etc.) is contained in the network file (''.inpx'' for Vissim 6.0 and newer versions, or ''.inp'' for older ones) Loading such a file is fairly easy, provided one knows the path to that file, and the variable into which Vissim was saved. You then invoke the ''LoadNet()'' method. | |
+ | |||
'''def''' loadNetwork(Vissim, Inpx_path): | '''def''' loadNetwork(Vissim, Inpx_path): | ||
'''try:''' | '''try:''' | ||
− | '''return''' | + | Vissim.LoadNet (Inpx_path) |
+ | '''return''' True | ||
+ | '''except:''' | ||
+ | '''return''' 'LoadNetError' | ||
+ | |||
+ | Similarly, one can load the environnement that comes around the network, such as the size of the screen window, the zommed position of the view and various display options. This is achieved with the '''LoadLayout()''' method. This information is found in the ''.layx'' file. | ||
+ | |||
+ | '''def''' loadLayout(Vissim, Layx_path): | ||
+ | '''try:''' | ||
+ | Vissim.LoadLayout (Layx_path) | ||
+ | '''return''' True | ||
'''except:''' | '''except:''' | ||
− | '''return''' ' | + | '''return''' 'LoadNetError' |
===The ''Evaluation'', ''Simulation'' and ''Graphic'' classes=== | ===The ''Evaluation'', ''Simulation'' and ''Graphic'' classes=== | ||
− | === | + | ===The ''Net'' class, and modifying parameters value=== |
===Starting the simulation=== | ===Starting the simulation=== |
Version du 18 novembre 2014 à 17:53
Sommaire
How to use Vissim via a python script
As found in the Vissim manual, an external program can communicate with Vissim via the COM interface, which is basically a Window's built-in interface designed to have programs interacting with each other by sharing their binary components. Via COM, it is possible to access the data and the functions of Vissim. The actual interaction between python and Vissim is taken care by each program's COM interface, and we thus only need to know the names of the objects that we want to access inside Vissim. So far as using COM with python, one will need to run the win32com package, which is part of the PyWin32 Extension. The package to import is win32com.client.
import win32com.client
Additonnaly, it is important to note that in order to use Vissim through the COM interface, one needs to have a complete Vissim version installed. As such, any version prior to Vissim 4.0 will not work, and the student and demo versions are striped of their COM interface.
For more information about what is a COM interface: http://msdn.microsoft.com/en-us/library/windows/desktop/ff485850(v=vs.85).aspx.
Getting PyWin32: http://starship.python.net/~skippy/win32/Downloads.html.
Starting Vissim
Two commands can be used to start Vissim: Dispatch() and dynamic.Dispatch() methods. The former will prompt a new Vissim instance to open and assign it to the variable you specified. If a Vissim instance is already open, it will ignore it. This can be problematic if you count on using more than one instance in parallel, since a single Vissim license can only handle 4 instances at a time. To avoid such a problem, you can use the dynamic.Dispatch() method, which will first assign already opened Vissim instances before opening new ones.
Regardless of which of the two options is picked, the call needs to specify the version of Vissim to start. The version number is obtained by multiplying the real Vissim version by 100. Following this rule, version 5.4 becomes 540 and 6.0 becomes 600. The Following script exemple starts (or assigns an already opened) instance of Vissim 6.0:
def startVissim(): try: return win32com.client.dynamic.Dispatch('Vissim.Vissim.600') except: return 'StartError'
Loading a save file
All the information needed for the actual simulation (links, vehicule behaviors, etc.) is contained in the network file (.inpx for Vissim 6.0 and newer versions, or .inp for older ones) Loading such a file is fairly easy, provided one knows the path to that file, and the variable into which Vissim was saved. You then invoke the LoadNet() method.
def loadNetwork(Vissim, Inpx_path): try: Vissim.LoadNet (Inpx_path) return True except: return 'LoadNetError'
Similarly, one can load the environnement that comes around the network, such as the size of the screen window, the zommed position of the view and various display options. This is achieved with the LoadLayout() method. This information is found in the .layx file.
def loadLayout(Vissim, Layx_path): try: Vissim.LoadLayout (Layx_path) return True except: return 'LoadNetError'
The Evaluation, Simulation and Graphic classes
The Net class, and modifying parameters value
Starting the simulation
Closing Vissim
Resources
- Microscopic Simulation Model Calibration and Validation http://cts.virginia.edu/SimCalVal.htm
- European project Methods and tools for supporting the Use caLibration and validaTIon of Traffic simUlation moDEls http://www.multitude-project.eu/, in particular all the guidelines on the topic http://dl.dropbox.com/u/21489630/Guidelines/Guidelines.rar
- Section 3.3 in Mohamed El Esawey's PhD thesis Travel time estimation in urban areas using neighbour links data