Traffic micro-simulation calibration and validation

De Transport
(Redirigé depuis SimulationCalibration)

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 Net object, and modifying parameters value

The Net object contains the core information usefull to the simulation. It is divided into multiple subobjects:

  • Links
  • Driving Behaviors
  • Detectors
  • Vehicule Inputs
  • etc.

All objects also have Attributes and Properties

For exemple, trying the set a value of 1.0 to the Weidemann 99 cc0 parameter would require to call the net object, the driving behavior object, and to set the cc0 attribute via the SetAttValue property. This reads:

   Vissim.Net.DrivingBehaviors[i].SetAttValue('W99cc0',1.0)

Similarly, you can get the actual value of this parameter with the AttValue property:

   Vissim.Net.DrivingBehaviors[i].AttValue('W99cc0')

Now, unless you build up your own driving behavior model, the actual value of i is irrelevant for most of the parameters, but not all. This is because they exists whether they are activated or not. And with some exceptions, they do not overlap between the Wiedemann 74 and Weidemann 99 models, even if the manual says they are conceptually the same, as is the case with W99ccO and the W74ax parameter. This means that changing the value of W99ccO will have no effect on the simulation unless the model really is set to Wiedemann 99. Let's say it matters, you could get the correct i value by first testing for the name with:

   Vissim.Net.DrivingBehaviors[i].AttValue('CarFollowModType')

which would return u'WIEDEMANN74' or u'WIEDEMANN99' , and could be changed to the correct one, activating the relevant parameters in the process. To continue this example, let's assume that Wiedemann 99 is assigned to the 1rst DrivingBehavior object, so i = 1.

Now, to apply the correct model to a Link, the Links object is used. In a network of 4 links and 3 connectors, the Links object would be of lenght 7, and would read, if it was a python list, as [1,2,3,10001,10002,10003]. Sure enought, len(vissim.Net.Links) will return 7, but don't expect to be able to use dir(vissim.Net.Links) to get a quick view of the available attributes. The only way to get all of this information is to read the Online Help in Vissim (which, really, is only a file named Vissim 6 - COM.chm and found in .\Program Files\PTV Vision\PTV Vissim 6\Exe)

A good way to be sure to be applying the to change to the good link, say the connector 10001, is to iterate over the Links object and get it's number attribute or name attribute if the links were named inside the network file. Then, you can change the associated driving behavior.

   For k in xrange(len(vissim.Net.Links)):
       if vissim.Net.Links[k].AttValue('No') == 10001:
           vissim.Net.Links[k].SetAttValue('LinkBehavType',1)

The Evaluation, Simulation and Graphic objects

Starting the simulation

Closing Vissim

Resources