24.08.2013 Views

VISSIM 5.30-05 User Manual

VISSIM 5.30-05 User Manual

VISSIM 5.30-05 User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The COM Interface (Optional Module)<br />

# Python Script sample for <strong>VISSIM</strong><br />

# Copyright (C) PTV AG. All rights reserved.<br />

# SB, VR 2006-07-25<br />

#<br />

# This code demonstrates the use of the following interfaces for the simulation of a<br />

# car park with access control and available free places information:<br />

# - ISignalControllers and ISignalGroups<br />

# - IDetectors: Use of the attributes PRESENCE and IMPULSE<br />

# - IStaticObjects: Use of the attribute STATE to change 3D state during simulation time<br />

#=======================================================<br />

import win32com.client<br />

#constants<br />

#=======================================================<br />

NAREAS = [0, 1, 2]<br />

GREEN = 2 #signal group type #permanent green#<br />

RED = 3 #signal group type #permanent red#<br />

OPENEDTIME = 5 #opened barrier time<br />

NPLACES = 11 #number of places<br />

#=======================================================<br />

#initialize global variables<br />

#=======================================================<br />

Sim = <strong>VISSIM</strong>.Simulation<br />

SgCtrls = <strong>VISSIM</strong>.Net.SignalControllers<br />

SgGrps = [SgCtrls.GetSignalControllerByNumber(i+1).SignalGroups.GetSignalGroupByNumber(1)<br />

for i in NAREAS]<br />

[SgGrps[i].SetAttValue("TYPE", RED) for i in NAREAS]<br />

StObjs = <strong>VISSIM</strong>.Net.StaticObjects<br />

Barriers = [StObjs.GetStaticObjectByName('Barrier0' + str(i+1) + '.v3d') for i in NAREAS]<br />

[Barriers[i].SetAttValue("STATE", 0) for i in NAREAS]<br />

BarrierOpening = [False for i in NAREAS]<br />

BarrierClosing = [False for i in NAREAS]<br />

Dets = [SgCtrls.GetSignalControllerByNumber(i+1).Detectors for i in NAREAS]<br />

DetsIn = [Dets[i].GetDetectorByNumber(11) for i in NAREAS]<br />

DetsPass = [Dets[i].GetDetectorByNumber(12) for i in NAREAS]<br />

DetsOut = [Dets[i].GetDetectorByNumber(91) for i in NAREAS]<br />

VehEntering = [False for i in NAREAS]<br />

VehParked = [0 for i in NAREAS]<br />

CtrName = [['Counter_P0' + str(i+1) + j + '.v3d' for i in NAREAS] for j in ['a', 'b']]<br />

#=======================================================<br />

#control detector for the entrance, pass and exit<br />

#=======================================================<br />

def ControlEntrances() :<br />

#Through all entrances for i in NAREAS :<br />

#if vehicle is on the entrance and no entrance is being processed<br />

#then start enter process<br />

if DetsIn[i].AttValue("PRESENCE") and not VehEntering[i] :<br />

VehEntering[i] = True #start entrance process<br />

BarrierOpening[i] = True #start open barrier process<br />

#did the entering vehicle enter?<br />

if VehEntering[i] and DetsPass[i].AttValue("PRESENCE") :<br />

SgGrps[i].SetAttValue("TYPE", RED) #don't allow to enter<br />

BarrierClosing[i] = True #start closing barrier<br />

#=======================================================<br />

#open and close barriers appropriately<br />

#=======================================================<br />

<strong>User</strong> <strong>Manual</strong> © PTV AG 2011 59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!