emme/2 macro programming with release 9: non trivial solutions to trivial problems vladimir livshits...

16
EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Upload: kyle-larson

Post on 26-Mar-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

EMME/2 Macro Programming With Release 9:

Non Trivial Solutions to Trivial Problems

Vladimir Livshits

University of Toronto

Page 2: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Some Major Problems Inherent to the Macro Language As a Keystroke Record:Exchange of information

between modules, banks, and scenarios

Handling complex data structures

User interface

Page 3: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

More than a Keystroke Record

File processing Loops and text registers in compound lines Convolutions of complex data structures in text

strings Handling of complex repetitive expressions

See paper for: Graphical user interface in macro routines Useful macro utilities Interactions with operating system in macro routines

Page 4: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Some Painful Stuff (1) Information exchange between: Modules - often the most difficult:

2.14 2.11, 2.41 2.11, 2.14 2.41, 2.24 2.41, 5.34 2.41, etc.

Banks - a lot easier with 1.31 (can be done naturally via keystroke record!), But might involve complicated logic in macros (checking what exists, ensuring data compatibility, etc.)

Scenarios - depends on a task at hand - can be straight forward, can be difficult

Page 5: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

File Processing: Example 1

t nodes

a* … centroids data …

a … regular nodes data ...

t links

a … links data …

file for links input in 2.11:

t links

d … links data ...

file for nodes input in 2.11:

d* … centroids data …

d … regular nodes data ...

MACRO

Page 6: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

~<<214.Out

~# One compound row below till the '~$' sign

~+;~t1=~@;~?t1=t links;~$>links;

~t2=%%%t1.1%%%;~>>211n.in;~?t2=a;~"d%%%t1.-1%%%;

~?t2=d;~"a%%%t1.-1%%%;~?t2=t;~"%%%t1%%%;~>>;~$

~# End of compound line

~:links

~+;~>>211l.in;~"%%%t1%%%;~>>

~# One compound row below till the '~$' sign

~+;~t1=~@;~?e;~$>exit;~t2=%%%t1.1%%%;~>>211l.in;~?t2=a;~"d%%%t1.-1%%%;~?t2=d;~"a

%%%t1.-1%%%;~?t2=t;~"%%%t1%%%;~>>;~$

~# End of compound line

~:exit

~+;~<<

~+;~>>211l.in;~" ;~>>;~>>211n.in;~" ;~>>

Page 7: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

File Processing: Example 2~/Select: 1. Delete all old station centroids

~/ 2. Add new station centroids

~/ 3. Remove all subway station centroids

~/ without parking lots and insert parking

~/ data in the retained centroids attributes

~/ 4. Connect station centroids to the road

~/ network

~/ 5. Check if station centroids have been

~/ inserted

~/ 6. Speed run - run options 1,2,3,4 using

~/ defaults

~/ 7. Change macro parameters

~/ 8. Display copyright notice

Page 8: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Example Schema for Automated Road Network Modifications

Mark up network elements

Produce input files for file processing

Reformat files in a macro

Read files in a bank

2.142.41

2.41 2.14 2.122.43

MACRO

2.41 2.11

2.12

Page 9: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Main Principles of File Processing in Emme/2 Macro Language Release 9

Utilisation of text registers to exchange information between different files

Utilisation of sub-strings (text substitutions) to reformat text lines

Careful closing of files opened for writing In a compound line in order to avoid undesirable writing to the files

Utilisation of compound lines For efficient handling of file processing procedures

Utilisation of the t0 text register and positional parameters %1% … %32%

For reformatting and for exchanging text strings between files

Page 10: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Some Painful Stuff (2)

Processing complex data structures: No ‘modular programming’ or ‘object-

oriented programming’ elements in the macro language

Many modeling procedures are based on data structure rather then operations (hierarchical logit models estimations, counts stations and screen lines)

Page 11: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Expressions in Compound Lines and Convolution of Complex Data

Structures in Text Strings

D A TA 1 .1 .1sc reen lin e 1d irec tion 0 1s ta tion 0 0 1

D A TA 1 .1 .2sc reen lin e 1d irec tion 0 1s ta tion 0 0 2

D A TA 1 .1sc reen lin e 1d irec tion 0 1

D A TA 1 .2sc reen lin e 1d irec tion 0 2

D A TA 1sc reen lin e 1

Page 12: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Output file

inode jnode result

60233 60239 285

60239 60233 229

Complex Data Structures: Example 1

Input file:

inode jnode result

60233 60239 0101002

60239 60233 0101001

station code

~<macro_name 0102 001002

volume

Page 13: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

~+;~t1=%%%1%%%;~t2=%%%2%%%

~# String of screen lines: %t1%

~# String of stations: %t2%

batchout=output

m=2.41

~# Change module parameters

~+;5;n;y;y;n;n;n

~# Input stations codes in tmpl1

~+;3;tmpl1;*;;~* input file name;n;y

~+;1;n

~# One compound row below till ‘0’:

~+;~?t2=;~$>l;volau*(tmpl1==%%%t1.2%%%01%%%t2.3%%%)+;

~t2=%%%t2.-3%%%;~?!t2=;~$;0

~+;;!ul1=0;;3

~:l

q

batchout=^

Page 14: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Main Principles of Convoluting Complex Data Structures for

Macro Processing Utilisation of text strings — offers great flexibility for

reflection of different data structures (hierarchical data, lists, etc.) and different data types (characters as well as numeric data) in emme/2 macros.

Utilisation of text substitutions — handling of the different data structures with text strings can be efficiently done with text substitutions, especially with text substitutions in text registers.

Flow control based on the encoded in a text string data structure — text registers with text substitutions can be used as loop counters and / or criteria.

Page 15: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Conclusions Complex emme/2 based models can be

efficiently encoded entirely in emme/2 software File processing in emme/2 macro language

offers additional possibilities to automate complex network or matrix manipulations outside of matrix or network editors

Processing of complex data structures (e.g. hierarchical matrix organisations in nested logit models) can be efficiently done by convoluting information about the data structures in text strings and including expressions in compound line loops

Page 16: EMME/2 Macro Programming With Release 9: Non Trivial Solutions to Trivial Problems Vladimir Livshits University of Toronto

Acknowledgements

Data Management GroupINRO Consultants Inc.University of Toronto