Views:

Question

How to create a flow bundle (PrT/PuT) and read out as a PuT path list by using COM?

Answer

1) Create a flow bundle:
Set aStopPoint = Visum.Net.StopPoints.ItemByKey(30)
Set aNetElms = Visum.CreateNetElements
aNetElms.Add aStopPoint
Set aFlowBundle = Visum.Net.FlowBundle
aFlowBundle.Clear
aFlowBundle.DemandSegments = "P"
aFlowBundle.Execute aNetElms

2) Create a PuT path list:
Set aPuTPathList = Visum.Lists.CreatePuTPathList
aPuTPathList.SetObjects 0, "P", routeFilter_filterFlowBundleRoutes
aPuTPathList.AddKeyColumns
aPuTPathList.AddColumn "JourneyTime"
aPuTPathList.AddColumn "Dep"
aPuTPathList.AddColumn "Arr"
aPuTPathList.Show

3) Read out the PuT path list:
aPuTPathListArray = aPuTPathList.SaveToArray
For aPath = 0 To UBound(aPuTPathListArray)
   aStr = ""
   For anAttr = 0 To aPuTPathList.NumColumns - 1
      aStr = aStr & aPuTPathListArray(aPath, anAttr) & " "
   Next anAttr
   Debug.Print Trim(aStr)
Next aPath

4) An example for Python on how to create a PrT flow bundle with restricted supply (only TSys "B") and traffic types/passenger types using an ActivityTypeSet, and use CreateCondition with Complement = True to code "And then not":

aFlowBundle = Visum.Net.FlowBundle
aFlowBundle.Clear()
aFlowBundle.DemandSegments = "P"
aZone = Visum.Net.Zones.ItemByKey(100)
aLink1 = Visum.Net.Links.ItemByKey(10, 11)
aLink2 = Visum.Net.Links.ItemByKey(20, 21)
anActivityTypeSet = aFlowBundle.CreateActivityTypeSet()
anActivityTypeSet.Add (1)
aNetElms = Visum.CreateNetElements()
aNetElms.Add(Visum.Net.TSystems.ItemByKey("B"))
aFlowBundle.CreateConditionWithRestrictedSupply(aZone, aNetElms, False, anActivityTypeSet)
aFlowBundle.CreateNewGroup()
aFlowBundle.CreateCondition(aLink1, anActivityTypeSet, False)
aFlowBundle.CreateCondition(aLink2, anActivityTypeSet, True)
aFlowBundle.ExecuteCurrentConditions()

An example on how to check this example code in the Visum Python console:

5) Another example for PrT:

Set aMainZone = Visum.Net.MainZones.ItemByKey(1)
Set aFlowBundle = Visum.Net.FlowBundle
aFlowBundle.Clear
aFlowBundle.DemandSegments = "C"

Set anActivityTypeSet = aFlowBundle.CreateActivityTypeSet
anActivityTypeSet.Add 2 ' 2 for destination activity trips

aFlowBundle.CreateCondition aMainZone, anActivityTypeSet
aFlowBundle.ExecuteCurrentConditions

6) An example for PuT using a "Line selection" and "Selection of traffic types" (Origin demand/Destination demand)?

Remarks:
- The line selection needs to be set using a filter, as this functionality of the dialog "Graphics tools (Flow bundle)" is not available in the COM interface.
- Once the line filter is active, the method
aFlowBundle.CreateConditionActiveLines
can catch an IRouteTrafficTypeSet object, coding the Traffic types.

Sub TestFlowBundleWithLineSelection()
Dim Visum As New VISUMLIB.Visum
Dim aNetElms As VISUMLIB.INetElements
Dim aFlowBundle As VISUMLIB.IFlowBundle
Dim anRouteTrafficTypeSet As VISUMLIB.IRouteTrafficTypeSet

Visum.IO.LoadVersion Application.ActiveWorkbook.Path & cMyVersionFileIn

Set aNetElms = Visum.CreateNetElements
aNetElms.Add Visum.Net.Lines.ItemByKey("004")

Set aFlowBundle = Visum.Net.FlowBundle
aFlowBundle.Clear

Set anRouteTrafficTypeSet = aFlowBundle.CreateRouteTrafficTypeSet
anRouteTrafficTypeSet.Add 2
anRouteTrafficTypeSet.Add 4

Visum.Filters.LineGroupFilter.Init
'Visum.Filters.LineGroupFilter.LineFilter.AddCondition "OP_NONE", False, "NAME", "EqualVal", "004" 'Alternative way.
Visum.Filters.LineGroupFilter.LineFilter.SetSelection aNetElms
Visum.Filters.LineGroupFilter.LineFilter.UseSelection = True

Visum.Filters.LineGroupFilter.LineFilter.UseFilter = True
Visum.Filters.LineGroupFilter.UseFilterForLines = True

aFlowBundle.DemandSegments = "PuT"
aFlowBundle.CreateConditionActiveLines anRouteTrafficTypeSet
aFlowBundle.ExecuteCurrentConditions

Set Visum = Nothing

End Sub

7) An example on two Stops and a Line:

Sub TestFlowBundleWithStopPointAndLineSelection()
Dim Visum As New VISUMLIB.Visum
Dim aNetElms As VISUMLIB.INetElements
Dim aFlowBundle As VISUMLIB.IFlowBundle
Dim anActivityTypeSet1 As VISUMLIB.IActivityTypeSet
Dim anActivityTypeSet2 As VISUMLIB.IActivityTypeSet
Dim aStopPoint1 As VISUMLIB.IStopPoint
Dim aStopPoint2 As VISUMLIB.IStopPoint

Visum.IO.LoadVersion Application.ActiveWorkbook.Path & cMyVersionFileIn

Set aFlowBundle = Visum.Net.FlowBundle
aFlowBundle.Clear
aFlowBundle.DemandSegments = "PuT"

Set aStopPoint1 = Visum.Net.StopPoints.ItemByKey("100030")
Set aStopPoint2 = Visum.Net.StopPoints.ItemByKey("100002")

Set anActivityTypeSet1 = aFlowBundle.CreateActivityTypeSet
anActivityTypeSet1.Add 1 ' Origin traffic
'anActivityTypeSet1.Add 2 ' Destination traffic
anActivityTypeSet1.Add 4 ' Boarding passengers
'anActivityTypeSet1.Add 8 ' Alighting passengers
anActivityTypeSet1.Add 16 ' Transfers
anActivityTypeSet1.Add 32 ' PassThroughStop
anActivityTypeSet1.Add 64 ' PassThroughNoStop

Debug.Print anActivityTypeSet1.GetActivityTypeSet

Set anActivityTypeSet2 = aFlowBundle.CreateActivityTypeSet
'anActivityTypeSet2.Add 1 ' Origin traffic
anActivityTypeSet2.Add 2 ' Destination traffic
'anActivityTypeSet2.Add 4 ' Boarding passengers
anActivityTypeSet2.Add 8 ' Alighting passengers
anActivityTypeSet2.Add 16 ' Transfers
anActivityTypeSet2.Add 32 ' PassThroughStop
anActivityTypeSet2.Add 64 ' PassThroughNoStop

Debug.Print anActivityTypeSet2.GetActivityTypeSet

Set aNetElms = Visum.CreateNetElements
aNetElms.Add Visum.Net.Lines.ItemByKey("004")
aFlowBundle.CreateConditionWithRestrictedSupply aStopPoint1, aNetElms, False, anActivityTypeSet1
aFlowBundle.CreateConditionWithRestrictedSupply aStopPoint2, aNetElms, False, anActivityTypeSet2
aFlowBundle.ExecuteCurrentConditions

Set Visum = Nothing

End Sub


An executable example in VBA is attached to this article, another one is available here:
c:\Users\Public\Documents\PTV Vision\PTV Visum 2024\COM\Examples_ComDocu\VBA\FlowBundleAnalysis.xls

In Python:
c:\Users\Public\Documents\PTV Vision\PTV Visum 2024\COM\Examples_ComDocu\Python\FlowbundleAnalysis.py