Pokazywanie postów oznaczonych etykietą COM. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą COM. Pokaż wszystkie posty

wtorek, 9 kwietnia 2013

Multiple Visum licences -> Multiple COM Objects

Problem:
Well, that's kind of a problem when you have many Visum licences and you want to use them variantly via COM.
By default latest installation is available under: ("Visum.Visum") key in registry and any new installation of Visum overwrites previous keys.
When you have may licences (Uni, Commercial, Teaching, etc.) it becomes confusing.
There's an option "Register as COM server" under "Options/Options" in Visum GUI - but it doesn't work for me.
So what's the solution?:
You simply run your Visum125.exe with '/regserver' flag from the command line - that's it. Below I created a small wrapper for my multiple licences:

import os   
def register_Visum(nazwa):
    def regVisum(path):
        command = "cd " + path + "& " + "Visum125.exe /regserver"       
        print command
        os.system(command)
       
    licencedict = {"edu_GN": "C:\Program Files (x86)\PTV_Vision\VISUM125_student_GN\Exe\ " ,
            "edu_45min": "C:\Program Files (x86)\PTV_Uni\VISUM125\Exe\ ",
            "PK": "C:\Program Files\PTV_Vision\VISUM125\Exe\ "}
   
    regVisum(licencedict[nazwa])
 
register_Visum("edu_GN")
register_Visum("edu_45min")
register_Visum("PK")


It will save a lot of my time and nerves now
PS. Another issue would be to register them under different names, ie. "Visum.Visum.Uni", "Visum.Visum.Commercial" - but I believe that's compiled within dll / exe and I won't have access to this, unless PTV exposes it.

środa, 20 marca 2013

why python for Visum scripting - short answer

that's why

task:
check if UDA exists

code:
def CheckAttr(obj,attr):
       return attr in [e.Code for e in o.Attributes.GetAll]


usage:

CheckAttr(Visum.Net.Links,"ToNodeNo")


with VB, or anything lower level it'd be at least 20 lines of code :P


Update - the same with VB:

Sub UpdateVisumUDAs(ByVal tableName As String _
   , ByVal keyFields As String() _
   , ByRef ds As DataSource _
   , Optional ByVal CreateUDA As Boolean = True _
   , Optional ByVal ValueType As Integer = 5)


Dim o As Object = ds.StringToVisumObject(tableName, ds)
Dim Attributes As Object()
Attributes = o.Attributes.GetAll
Dim AttrCodes As New List(Of String)
For Each Attribute As Object In Attributes
   AttrCodes.Add(Attribute.Code.ToString.ToUpper)
Next
For Each key As String In keyFields
   If CreateUDA AndAlso Not AttrCodes.Contains(key.ToString) Then
   o.AddUserDefinedAttribute(key.ToString, key.ToString, key.ToString, ValueType)
End If
Next


PS. Don't take me as an ignorant - I know more or less pros and cons for python vs. any 'proper' programming language, but I just love the way you can do things in python


czwartek, 24 stycznia 2013

Change Node/Link/Zone Numbers in Visum via COM + limit of Visum

I believe anyone who has created once Visum network out of big extrenal datasets (mainly GIS - .shp) came across problems with numbering duplicates. Here I will show you how to overcome those issues. There are two ways: one is scripting (snippet below), another is via Access database.

Case:
We have model of Kraków (city ca. 1mln inhabitants), we are creating regional model of Małopolska - Kraków is it's capital.
We have detailed GIS network from regional municipality, we have our own Kraków model with Visum network. We want to merge them together.
In most cases we will have problems with duplicate keys in database (i.e. "Node with ID 301 already defined in the network"). That's mainly due to very decent DB architecture behind visum data. Each network object belongs to specific table with well defined 'primary key' and 'foreign key' - which basically cannot have duplicates (http://en.wikipedia.org/wiki/Foreign_key).
It goes like this:
  • each node is identified by it's NO
  • each link is identified by its FromNodeNo and ToNodeNo (those are foreign keys, plus implicitly it has it's own primary key NO - I assume)
  • each turn has its FromNode, ViaNode and ToNode
If during import of any external objects those numbers will get confused we get rubbish results (either all network is mixed up, either it's not imported at all.

Toy-network example:

1. I created following network and exported it to .shp:


Network no 1


2. I created another network like this:
Network no 2
3. I tried to import network 1 into network 2:
a) result without setting "Offset parameter":
No network import at all.
b) when You set "Offset" to a number greater than max NodeNo, you will get something
first you get error for some links (which were already defined in network no 2)

and finally the resulting network will be as follows:
network 1 imported into network 2 (marked added links) all together network makes no sense
As we see there's a lot of confusion.

Solution:

there are two methods: one is scripting, another is via Access DB.


Scripting is easier and faster and can be automated, but it doesn't work for many objects (it works for nodes, doesn't work for links). See examples below(all scripts in python):

a) Bulk (didn't work with older versions of Visum) - much faster:

def get_Nodes(Attr):
       return Visum.Net.Nodes.GetMultiAttValues(Attr)


Nodes=get_Nodes("No")
Nodes=list(Nodes)
Nodes=[list(node) for node in Nodes]
for i,node in enumerate(Nodes):
       node[1]=i+100000000 #put max node no in your network here

# we need to do it twice: once we add big number to all elements and the we can give them ordered numbers starting from whatever
Visum.Net.Nodes.SetMultiAttValues("No",Nodes)

Nodes=get_Nodes("No")
Nodes=list(Nodes)
Nodes=[list(node) for node in Nodes]
for i,node in enumerate(Nodes):
         node[1]=i+1000000 #give your threshold here (nodes will start fron No=1000000

Visum.Net.Nodes.SetMultiAttValues("No",Nodes)


b) element by element - can be very slow:

Nodes=Visum.Net.Nodes.GetMultiAttValues("No")
Nodes=[node[1] for node in Nodes]
for node in Nodes:
       Visum.Net.Nodes.ItemByKey(node).SetAttValue("No",node+
100000000 )
       i+=1
for node in Nodes:
      Visum.Net.Nodes.ItemByKey(node+
100000000 ).SetAttValue("No",i)
      i+=1


2) Access DataBase:
I'm not ver familiar with Access so just a picture of what I do:
a) Export network into Access DB (can take a lot of time)
b) Open access file and edit tables
c) Change keys in tables (for links it's good to change name of "No" column into anything else and create additional column named No, then set this column as a key.
d) make the new column "Autoincrement" - so the number will be integers starting from 1
(for links it needs to be different, links have directed numbers so it shall be like this: 1 1 2 2 3 3 4 4 5 5 6 6 ... - I did it in excel and pasted.
e) you save the file and Import it into Visum

This way we merged four different shapefiles with overlapping numbers and two different Visum networks.
Everything is neatly numbered starting from one onwards.


PS. We came across another issue which seemed strange but we found very easy explanation. During import we got following message that node number exceeds: 2 147 483 648. Which happened to be max of LongInt datatype, so actually that's the limit of Visum :) You cannot go any further. Simply reduce umbers by means of the solutions above.

Hope it helps!




środa, 7 marca 2012

Optimal Count Locator (OCL) for Visum

i2 - Intelligent-infrastructure is proud to present its newest Visum add-on which tells you where to place counting locations in the transport model to get best results. Lets see how it works.

Idea
The quality of transport modeling depends, among others, on counting data. But who cares about quality of counting itself? We set up counting locations willing to catch as much flow as we can, yet how can we be sure that our location is best possible. Knowledge, and experience seems to be a good hint, but here we propose something more refined. Our tool employs acknowledged optimization technique to specify set of optimal counting locations catching as much flow and as many OD pairs as possible.

Study Case
We asked transport planning professionals to specify 10 best nodes to be counted in the city that they know very well (Kraków - PL). We compared their solutions to our algorithm results, and that’s what we got:


modeler 5yrs exp
modeler 10yrs exp
Optimal Count Locator by i2
Flow detected
45.7%
50.6%
56.3%
OD pairs detected
37.2%
45.1%
57.0%



We see that even experienced transport planners, who know the city didn’t manage to cover as much flow and OD pairs as OCL. They detected almost as many flows as OCL, but OD pairs coverage was much lower. This experiment can give you a hint about what are benefits from using OCL

Product
We introduce the optimization procedure wrapped in intuitive, user friendly interface(see fig below), which can quickly find optimal solution even for complex networks.
User can define his budget (number of points that can be placed) and detectors which are already installed. It’s also available to determine what kind of detectors we want to install: junction, link, directed link, (it soon will be extended to cover also turns).
Additional technical parameter is algorithm depth, being number of paths between origin and destination that are taken into calculation process. For assignment generating numerous routes per OD pair setting this parameter low can make procedure faster.
We propose various strategies of optimization. In our opinion, and due to our tests, the most useful is mixed maximization of both OD pairs coverage and flow coverage, however you can choose to maximize only flow, or only OD pairs.
fig. intuitive user interface
Running time
Calculation time depends on size of the network. On the average up-to-date PC it takes about 1 minute to download 300 000 of paths (model for Kraków, Poland  of ca. 350 zones), and then time of optimization itself depends on number of connectors and takes roughly 5s per detector.

Results
Results are saved in your Visum network as Boolean, User-Defined-Attribute “i2_OCL_Detectors”, which equals 1 if it’s an object that should be detected
To see results visually, you can import prepared .gpa file. Additionally you can use our flow bundle generator, where you can clearly see which flows are covered with your detection.
For detailed results and statistics you can see report including OD coverage, flow coverage, keys of detected elements, calculation time, etc.

fig. input data - Visum model
fig. Statistics for obtained results
fig. graphical presentation of results: violet - counting locations, yellow - counted flow, gray - uncounted flow.
Further developments
The engine we proposed is flexible and extendable, thus it can be suited for personal needs, or extended to new functionalities:

  • Transit - soon we will try to extend our functionality to cover also PuT, and define set of stop points, or lines to be surveyed.
  • Plate scanning – our partners ask us to provide tool to define optimal plate scanning locations. Actually that’s on our road map, however this task is much more complicated, and we will need to spend some hours thinking on how to solve it.
  • Vehicle floating data – the engine we proposed is capable to define optimal trajectory of VFD to get as much details as needed.
Sales
OCL (Optimal Count Location) is ready to buy Visum add-on, available straightaway at intelligent-infrastructure. We offer competitive price for a product that gives you significant savings in modeling. We also provide service, where you send us your visum file and we simply calculate the results that you want.

Rafał Kucharski

piątek, 13 sierpnia 2010

PTV Visum much more powerful - Matlab Connection

I've recently played with Visum Script writing from the console level. To do that  I've struggled to learn python -  as previously I programmed mostly in matlab. But I did it and I thought to myself that this opensource world is maybe even better than Mathworks professional computing IDE (Matlab).

In python You can have library for:
Excel Spreadsheet Writing
GUI interface with wx
Optimization
Matrix Calculation
Genetic Algs
Neuron Network
almost for everything....

but they just are.... say not fully professional.

In Matlab You may not have all this variety of modules, but You can calculate literally whatever You want, and it works, and You can be sure results is correct!

So I've just tried  today to link Visum with Matlab via COM interface:

 Visum=actxserver('Visum.Visum.110') 

that's all that You have to do in Matlab. And now You can easily access any Visum functionality and extend it using the power of Matlab.

So now I have perfect Transport Modeling Platform with acces to infinite professional math programing interface. 

No excuses from now: Yes You Can!