-
Notifications
You must be signed in to change notification settings - Fork 0
/
DavTC8.rsc
4213 lines (3565 loc) · 177 KB
/
DavTC8.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
macro "Daviess Regional Model Version"
model_version = 20201103
// Developed by Ken Kaltenbach & Johnny Han, The Corradino Group
// 10/30/2020 MB Stantec - removed/cleaned up commented out/old code
// 10/30/2020 MB Stantec - removed Auto OUE Assignment Procedure and MSATime for TC7/8 update
// 08/08/2020 MB Stantec - minor edit at County School Balance (ln 682) trip gen stage to avoid cname County Name "Total" error
// 04/29/2015 Replace HourlyCap with AB_HourlyCap & BA_HourlyCap
// Replace DailyCap with AB_DailyCap & BA_DailyCap
// 03/17/2015 Make the Model Document callable from GUI (Initialization --> Input Files)
// 02/20/2015 Re-calibrate trip production rates
// 02/19/2015 Add congested travel time by day-part to line layer
// 02/18/2015 Change EMP_OTH to EMP_NRET (non-retail employment) in TAZ file
// Delete LAMPO references
// Make day-part count an input and delete %
// 02/17/2015 Create .BIN files for hard coded input parameters, which includ:
// - Day-part capacity conversion factors
// - Household model coefficients
// - External trip model parameters
// - Gamma & Exponential function parameters
// 02/10/2015 Re-calibrate household model constants
required_tc_build = 12420
required_tc_version = 7.0
return({model_version, required_tc_build, required_tc_version})
// create script from model table with 'RunMacro("TCP Create Model Script")'
endmacro
dbox "Daviess Regional Model"
right, center toolbox nokeyboard
title: "Daviess Regional Planning Model"
init do
shared project_dbox, ui_file, ScenArr, ScenSel
ui_file = GetInterface()
model_title = "Daviess Regional Model"
runmacro("load model")
project_dbox = 1
enditem
macro "load model" do
global cname,cnum
cname={"DAVIESS","HANCOCK","HENDERSON","MCLEAN","OHIO"}
cnum={30,46,51,75,92}
global model_table,ModelDir,sellink
{ModelInfo, StageInfo, MacroInfo,} = RunMacro("TCP Load Model", model_title)
if ModelInfo = null then return()
{model_table,,,model_version,} = ModelInfo
{StepMacro, StepTitle, StepFlag, StepAcce} = MacroInfo
StageName = StageInfo[1]
stages = StageName.length
pparts=SplitPath(model_table)
ModelDir=pparts[1]+pparts[2] //
single_stage = 0
sellink = 0
StepFlag = RunMacro("TCP Process Step Flags", StepFlag,, 0)
if !RunMacro("TCP Update Project Dbox", model_title, stages, &ScenNames) then
runmacro("closing")
enditem
update do
if project_dbox = -99 then
runmacro("closing")
else do
if !RunMacro("TCP Update Project Dbox", model_title, stages, &ScenNames) then
runmacro("closing")
end
enditem
close do runmacro("closing") enditem
button 0,0
icons: ModelDir+"GISDK\\BMP\\KYTC.bmp"
frame 0.5, 6, 39.0, 7.7 prompt: "Scenarios"
scroll list 1.5, 7.0, 37.0, 3.5 multiple list: ScenNames variable: ScenSel do
RunMacro("TCP Update Scenarios", model_title, stages, model_table)
enditem
checkbox 2, 10.8, 15 prompt: "Stop after stage" variable: single_stage
checkbox same, 12.2, 15 prompt: "Selected Lnk run" variable: sellink
button 20, 10.8, 18, 1.0 prompt: "Model Table" do
RunMacro("TCP Choose Model Table", model_title, model_table)
enditem
button same, 12.4, 18, 1.0 prompt: "Setup" do
RunDbox("TCP Scenario Manager", model_title, model_table)
enditem
button "Daviess_A1" 1, 14.5 icons: "bmp\\plannetwork.bmp" do cur_stage = 1 Runmacro("set steps") enditem
button "Daviess_B1" after, same, 19.0, 1.6 disabled prompt:StageName[1] do cur_stage = 1 Runmacro("run stages") enditem
button "Daviess_C1" after, same icons: "bmp\\ViewButton.bmp", "bmp\\ViewButton.bmp", "bmp\\ViewButton2.bmp" do RunMacro("TCP Model Show", ScenArr, 1) enditem
button "Daviess_A2" 1, 16.8 icons: "bmp\\plantripgen.bmp" do cur_stage = 2 Runmacro("set steps") enditem
button "Daviess_B2" after, same, 19.0, 1.6 disabled prompt:StageName[2] do cur_stage = 2 Runmacro("run stages") enditem
button "Daviess_C2" after, same icons: "bmp\\ViewButton.bmp", "bmp\\ViewButton.bmp", "bmp\\ViewButton2.bmp" do RunMacro("TCP Model Show", ScenArr, 2) enditem
button "Daviess_A3" 1, 19.1 icons: "bmp\\planassign.bmp" do cur_stage = 3 Runmacro("set steps") enditem
button "Daviess_B3" after, same, 19.0, 1.6 disabled prompt:StageName[3] do cur_stage = 3 Runmacro("run stages") enditem
button "Daviess_C3" after, same icons: "bmp\\ViewButton.bmp", "bmp\\ViewButton.bmp", "bmp\\ViewButton2.bmp" do RunMacro("TCP Model Show", ScenArr, 3) enditem
button "Daviess_A4" 1, 21.4 icons: "bmp\\planmatrix.bmp" do cur_stage = 4 Runmacro("set steps") enditem
button "Daviess_B4" after, same, 19.0, 1.6 disabled prompt:StageName[4] do cur_stage = 4 Runmacro("run stages") enditem
button "Daviess_C4" after, same icons: "bmp\\ViewButton.bmp", "bmp\\ViewButton.bmp", "bmp\\ViewButton2.bmp" do RunMacro("TCP Model Show", ScenArr, 4) enditem
button 1, 26.6, 33, 1.6 prompt: "Quit" do Runmacro("closing") enditem
text 25, after variable: "v " + i2s(model_version)
macro "set steps" do
global idir,odir
SetAlternateInterface()
RunDbox("TCP Set Step Flags", StepTitle[cur_stage], &StepFlag[cur_stage], StepAcce[cur_stage])
enditem
macro "run stages" do
global idir,odir
scen_data_dir = ScenArr[ScenSel[1]][3]
// - Create output and report folders if they do not exist already
on error do
goto lab1
end
CreateDirectory(scen_data_dir+"output")
lab1:
on error default
on error do
goto lab2
end
CreateDirectory(scen_data_dir+"Reports")
lab2:
on error default
//
repfile=scen_data_dir+"Reports\\DaviessModel.xml"
logfile=scen_data_dir+"Reports\\DaviessLog.xml"
idir=scen_data_dir+"input\\"
odir=scen_data_dir+"output\\"
oldrepfile=GetReportFileName()
oldlogfile=GetLogFileName()
SetReportFileName(repfile)
SetLogFileName(logfile)
shared d_LogInfo
d_LogInfo.[Report File] = repfile
d_LogInfo.[Log File] = logfile
if RunMacro("TCP Check Stage Files", cur_stage, single_stage, StepFlag, ScenArr, ScenSel) then
RunMacro("TCP Run Stages", cur_stage, single_stage, StepMacro, StepFlag, ScenArr, ScenSel,, {{"Title", StepTitle}})
//
if oldrepfile <> null then SetReportFileName(oldrepfile)
if oldlogfile <> null then SetLogFileName(oldlogfile)
shared d_LogInfo
d_LogInfo.[Report File] = oldrepfile
d_LogInfo.[Log File] = oldlogfile
vws = GetViewNames()
for i = 1 to vws.length do
CloseView(vws[i])
end
enditem
macro "closing" do
if RunMacro("TCP Close Model Dbox") = 1 then
return()
enditem
enddbox
// ------ BldNet -- Build Highway Network -------------------------
macro "BldNet" (Args) // Build Highway Network
//shared prj_dry_run if prj_dry_run then return(1)
global nfile
nfile = Args.[Highway Layer]
db_file = Args.[Highway Layer]
netfAM = Args.[NET AM]
netfMD = Args.[NET MD]
netfPM = Args.[NET PM]
netfNT = Args.[NET NT]
{node_lyr,link_lyr} = RunMacro("TCB Add DB Layers", db_file)
// +++++++ ADD REQUIRED OUTPUT FIELDS TO THE NETWORK DATABASE ++++++++++++++++++
flds={"AB_AM_CAP", "BA_AM_CAP",
"AB_MD_CAP", "BA_MD_CAP",
"AB_PM_CAP", "BA_PM_CAP",
"AB_NT_CAP", "BA_NT_CAP",
"BPRA" , "BPRB",
"AB_AM_LANES", "BA_AM_LANES",
"AB_MD_LANES", "BA_MD_LANES",
"AB_PM_LANES", "BA_PM_LANES",
"AB_NT_LANES", "BA_NT_LANES"
}
RunMacro("addfields",{flds,link_lyr})
// populate time-period-specific capacities, use reasonable values
vabhcap = GetDataVector(link_lyr+"|", "AB_HourlyCap", ) // Changes are made by Johnny Han, 4/29/2015
vbahcap = GetDataVector(link_lyr+"|", "BA_HourlyCap", ) // Changes are made by Johnny Han, 4/29/2015
vDL = GetDataVector(link_lyr+"|", "DIR_LANES", )
vDL = if(nz(vDL)=0) then 1 else vDL // for external station connectors
vAMAL = GetDataVector(link_lyr+"|", "AB_AM_LANES", )
vAMBL = GetDataVector(link_lyr+"|", "BA_AM_LANES", )
vMDAL = GetDataVector(link_lyr+"|", "AB_MD_LANES", )
vMDBL = GetDataVector(link_lyr+"|", "BA_MD_LANES", )
vPMAL = GetDataVector(link_lyr+"|", "AB_PM_LANES", )
vPMBL = GetDataVector(link_lyr+"|", "BA_PM_LANES", )
vNTAL = GetDataVector(link_lyr+"|", "AB_NT_LANES", )
vNTBL = GetDataVector(link_lyr+"|", "BA_NT_LANES", )
// check for period-specific lanes. If none, use DIR_LANES
vAMAL = if(nz(vAMAL)=0) then vDL else vAMAL
vAMBL = if(nz(vAMBL)=0) then vDL else vAMBL
vMDAL = if(nz(vMDAL)=0) then vDL else vMDAL
vMDBL = if(nz(vMDBL)=0) then vDL else vMDBL
vPMAL = if(nz(vPMAL)=0) then vDL else vPMAL
vPMBL = if(nz(vPMBL)=0) then vDL else vPMBL
vNTAL = if(nz(vNTAL)=0) then vDL else vNTAL
vNTBL = if(nz(vNTBL)=0) then vDL else vNTBL
// set directional capacities by direction and time period -- make these are in the assignment
// Day-part capacity factors <<--- These factors go to input\DayPart_Cap.bin as required by KYTC
// AM = 2.5
// MD = 5.0
// PM = 2.9
// NT = 4.3
// Get day-part capacity conversion factors
dpf = Args.DayPart_Cap
dpc_tab = OpenTable("DP_Cap", "FFB", {dpf,})
SetView(dpc_tab)
vr = nz(GetDataVector(dpc_tab+"|", "Factor", ))
dp = V2A(vr)
// 1 2 3 4
timep={"AM_Peak","Midday","PM_Peak","Night"}
dim dpc[4] // day-part capacity factors by period
for p = 1 to timep.length do // time period loop
dpc[p] = dp[p]
end
// Change vhcap to vabhcap or vbahcap, by Johnny Han, 4/29/2015
vamcapa = vAMAL*vabhcap*dpc[1]/vDL
vamcapb = vAMBL*vbahcap*dpc[1]/vDL
vmdcapa = vMDAL*vabhcap*dpc[2]/vDL
vmdcapb = vMDBL*vbahcap*dpc[2]/vDL
vpmcapa = vPMAL*vabhcap*dpc[3]/vDL
vpmcapb = vPMBL*vbahcap*dpc[3]/vDL
vntcapa = vNTAL*vabhcap*dpc[4]/vDL
vntcapb = vNTBL*vbahcap*dpc[4]/vDL
SetDataVector(link_lyr+"|", "AB_AM_CAP", vamcapa, )
SetDataVector(link_lyr+"|", "BA_AM_CAP", vamcapb, )
SetDataVector(link_lyr+"|", "AB_MD_CAP", vmdcapa, )
SetDataVector(link_lyr+"|", "BA_MD_CAP", vmdcapb, )
SetDataVector(link_lyr+"|", "AB_PM_CAP", vpmcapa, )
SetDataVector(link_lyr+"|", "BA_PM_CAP", vpmcapb, )
SetDataVector(link_lyr+"|", "AB_NT_CAP", vntcapa, )
SetDataVector(link_lyr+"|", "BA_NT_CAP", vntcapb, )
//////////////////////////////////////////////////////////////////
// Build Highway Network
//////////////////////////////////////////////////////////////////
SetStatus(2,"Building Highway Network",)
//////////////////////////////////////////////////////////////////
// Adding fields to the highway network
//////////////////////////////////////////////////////////////////
llyr="["+link_lyr+"]"
nlyr="["+node_lyr+"]"
tp=Args.Turnpens
// STEP 1: Build Highway Network
// In_Network codes: 0 or null=not used, 1=autos and trucks, 2=autos only, 3=trucks only
qryH = "Select * where In_Network=1 | In_Network=2"
Opts = null
Opts.Input.[Link Set] = {db_file+"|"+link_lyr, link_lyr,"hwy",qryH}
Opts.Global.[Network Options].[Node ID] = node_lyr+".ID"
Opts.Global.[Network Options].[Link ID] = llyr+".ID"
Opts.Global.[Network Options].[Turn Penalties] = "Yes"
Opts.Global.[Network Options].[Keep Duplicate Links] = "FALSE"
Opts.Global.[Network Options].[Ignore Link Direction] = "FALSE"
Opts.Global.[Link Options] = {{"Length", llyr+".Length", llyr+".Length"},
{"ID", llyr+".ID", llyr+".ID"},
{"Dir", llyr+".Dir", llyr+".Dir"},
{"[Facil Type]", llyr+".FClass", llyr+".FClass"},
{"[Area Type]", llyr+".AREATYPE", llyr+".AREATYPE"},
{"BPRA", llyr+".BPRA", llyr+".BPRA"},
{"BPRB", llyr+".BPRB", llyr+".BPRB"},
{"Time", llyr+".AutoTime", llyr+".AutoTime"},
{"DailyCapacity", llyr+".AB_DailyCap", llyr+".BA_DailyCap"}, // Changes are made by Johnny Han, 4/29/2015
{"HourlyCapacity", llyr+".AB_HourlyCap", llyr+".BA_HourlyCap"}, // Changes are made by Johnny Han, 4/29/2015
{"AMCapacity", llyr+".AB_AM_CAP", llyr+".BA_AM_CAP"},
{"MDCapacity", llyr+".AB_MD_CAP", llyr+".BA_MD_CAP"},
{"PMCapacity", llyr+".AB_PM_CAP", llyr+".BA_PM_CAP"},
{"NTCapacity", llyr+".AB_NT_CAP", llyr+".BA_NT_CAP"},
{"FF_AutoTime", llyr+".AutoTime", llyr+".AutoTime"},
{"FF_TruckTime", llyr+".TruckTime", llyr+".TruckTime"}}
Opts.Output.[Network File] = netfAM
ret_value = RunMacro("TCB Run Operation", 1, "Build Highway Network", Opts)
if !ret_value then do
ShowMessage("Build Highway Network failed")
goto quit
end
// STEP 1: Highway Network Setting
SetStatus(2,"Highway Network Settings",)
Opts = null
Opts.Input.Database = db_file
Opts.Input.Network = netfAM
Opts.Input.[Spc Turn Pen Table] = {tp}
Opts.Input.[Centroids Set] = {db_file+"|"+node_lyr, node_lyr, "Centroids", "Select * where IsCentroid<>null"}
Opts.Field.[Link type] = "[Facil Type]"
Opts.Global.[Global Turn Penalties] = {0, 0, 0, -1}
Opts.Flag.[Use Link Types] = "True"
ret_value = RunMacro("TCB Run Operation", 1, "Highway Network Setting", Opts)
if !ret_value then do
ShowMessage("Highway Network Setting failed")
goto quit
end
// create MD, PM and night night networks, which are the same as AM at this point
copyfile(netfAM,netfMD)
copyfile(netfAM,netfPM)
copyfile(netfAM,netfNT)
quit:
RunMacro("CloseAllViews")
return(ret_value)
endMacro
// --------- End BldNet ----------------------------------------------
//====== Trip Generation ======// (Perform Trip Generation)
macro "Household Model" (Args) // Trip Generation
// Household Model
SetStatus(2,"Household Model",)
//--------
tazpoly = Args.[TAZ Layer]
//////Open File TAZ file
{oboro_in} = RunMacro("TCB Add DB Layers", tazpoly)
taz_no = RunMacro("GetIZONES",tazpoly)
maxz = taz_no
// NEW HOUSEHOLD MODEL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// store disggregation fractions on the TAZ file - create fields
hstratf ={{"pph1","Real",9,7},{"pph2","Real",9,7},{"pph3","Real",9,7},{"pph4","Real",9,7},
{"wrk0","Real",9,7},{"wrk1","Real",9,7},{"wrk2","Real",9,7},{"wrk3","Real",9,7},
{"aut0","Real",9,7},{"aut1","Real",9,7},{"aut2","Real",9,7},{"aut3","Real",9,7},
{"mixempintden","Real",12,4}, // dchoice variable
{"inc_Q","Integer",6,0}} // income quartile
RunMacro("TCB Add View Fields",{oboro_in,hstratf})
/*
// Household size logit contants <<--- These constants go to input\HHModel_Constants.bin file as required by KYTC
// recalib for Daviess Henderson +
Chhsz = {-0.9082, 0.4153, 0.0949,
-0.0224, 0.3838,-1.6516,
0.7609, 0.7250,-5.1667,
1.3667, 0.3416,-5.6636}
// Household workers logit contants
// recalib for Daviess Henderson +
Chhwrk = { -5.1175, -46.2809, 0.0000,
-3.9589, -46.1147, -1.9149,
-2.8831, -46.4298, -2.2513,
-1.4746, -46.0720, -6.2661}
// Household autos logit contants
// recalib for Daviess Henderson +
Chhaut = {5.7025, 0.0021, 0.0000,
0.5451, 10.1230, 11.2221,
0.8858, 14.5587, 1.3816,
0.4898, 15.7542, 0.0000}
*/
// select internal TAZs, non-group quarters
SetLayer(oboro_in)
qry = "Select * where nz(ExSta)=0"
n = SelectByQuery("Internal", "Several", qry,)
// Establish income quartiles: 1 - 4, low - high
vQ = Vector(n, "Short", {{"Constant",1},{"Row Based","True"}})
vI = GetDataVector(oboro_in+"|Internal", "inc_Q",{{"Sort Order",{{"Income_Median","A"}}}})
recs=vI.length
q1=0
q2=recs/4
q3=recs/2
q4=q2+q3
for inc=1 to vI.length do
quart=1
if(inc>q2) then quart=2
if(inc>q3) then quart=3
if(inc>q4) then quart=4
vQ[inc]=quart
end
SetDataVector(oboro_in+"|Internal", "inc_Q", vQ, {{"Sort Order",{{"Income_Median","A"}}}} )
// get data vectors for HH, POP, AUTOS, Workers
global vhh
vhh = nz(GetDataVector(oboro_in+"|Internal", "House_Occ", ))
vpop = nz(GetDataVector(oboro_in+"|Internal", "Est_POP", ))
vaut = nz(GetDataVector(oboro_in+"|Internal", "Vehicles", ))
vwrk = nz(GetDataVector(oboro_in+"|Internal", "WORKERS", ))
vwph = if(vhh<>0) then vwrk/vhh else 0 // average workers per household
vpph = if(vhh<>0) then vpop/vhh else 0 // average persons per household
vauthh = if(vhh<>0) then vaut/vhh else 0 // average autos per household
// Trap bad data ------------------
vauthh = min(vauthh,6)
vpph = min(vpph,6)
vwrk = min(vwrk,6)
// --------------------------------
// HH Classification Vectors
global vHC,vAXP,vAXW
Dim vHC[3,4] // vHC[var,level]
Dim vAXP[4,4] // vAXP[autos,persons]
Dim vAXW[4,4] // vAXW[autos,workers]
// Get Household Model Constants
// 1_Var is coefficient for person/HH in household size & auto models, and coefficient for worker/HH in worker modele
// 2_Var is coefficient for auto/HH in all models
// 3_Var is the constant term in all models
term = {"1_Var","2_Var","3_Var"}
HHConst = Args.[HH Model Constants]
HHM_const = OpenTable("HH Model Const", "FFB", {HHConst,})
SetView(HHM_const)
Dim Coeff[3,4,3] // coefficients by models, classes, terms
for m = 1 to 3 do // household model loop
qry = "Select * where Model="+i2s(m)
sset="Model_"+i2s(m)
n = SelectByQuery(sset, "Several", qry,)
for t = 1 to 3 do // term loop
vr = nz(GetDataVector(HHM_const+"|"+sset, term[t], ))
ra = v2a(vr)
for class = 1 to 4 do // class loop
Coeff[m][class][t] = ra[class]
end
end
end
// Household size model
vU1 = exp(Coeff[1][1][1] * vpph + Coeff[1][1][2] * vauthh + Coeff[1][1][3] )
vU2 = exp(Coeff[1][2][1] * vpph + Coeff[1][2][2] * vauthh + Coeff[1][2][3] )
vU3 = exp(Coeff[1][3][1] * vpph + Coeff[1][3][2] * vauthh + Coeff[1][3][3] )
vU4 = exp(Coeff[1][4][1] * vpph + Coeff[1][4][2] * vauthh + Coeff[1][4][3] )
vDenom = vU1 + vU2 + vU3 + vU4
vHC[1][1] = vU1/vDenom
vHC[1][2] = vU2/vDenom
vHC[1][3] = vU3/vDenom
vHC[1][4] = vU4/vDenom
SetDataVector(oboro_in+"|Internal", "pph1", vHC[1][1], )
SetDataVector(oboro_in+"|Internal", "pph2", vHC[1][2], )
SetDataVector(oboro_in+"|Internal", "pph3", vHC[1][3], )
SetDataVector(oboro_in+"|Internal", "pph4", vHC[1][4], )
// Workers model
vU1 = exp(Coeff[2][1][1] * vwph + Coeff[2][1][2] * vauthh + Coeff[2][1][3] )
vU2 = exp(Coeff[2][2][1] * vwph + Coeff[2][2][2] * vauthh + Coeff[2][2][3] )
vU3 = exp(Coeff[2][3][1] * vwph + Coeff[2][3][2] * vauthh + Coeff[2][3][3] )
vU4 = exp(Coeff[2][4][1] * vwph + Coeff[2][4][2] * vauthh + Coeff[2][4][3] )
vDenom = vU1 + vU2 + vU3 + vU4
vHC[2][1] = vU1/vDenom
vHC[2][2] = vU2/vDenom
vHC[2][3] = vU3/vDenom
vHC[2][4] = vU4/vDenom
SetDataVector(oboro_in+"|Internal", "wrk0", vHC[2][1], )
SetDataVector(oboro_in+"|Internal", "wrk1", vHC[2][2], )
SetDataVector(oboro_in+"|Internal", "wrk2", vHC[2][3], )
SetDataVector(oboro_in+"|Internal", "wrk3", vHC[2][4], )
// Autos model
vU1 = exp(Coeff[3][1][1] * vpph + Coeff[3][1][2] * vauthh + Coeff[3][1][3] )
vU2 = exp(Coeff[3][2][1] * vpph + Coeff[3][2][2] * vauthh + Coeff[3][2][3] )
vU3 = exp(Coeff[3][3][1] * vpph + Coeff[3][3][2] * vauthh + Coeff[3][3][3] )
vU4 = exp(Coeff[3][4][1] * vpph + Coeff[3][4][2] * vauthh + Coeff[3][4][3] )
vDenom = vU1 + vU2 + vU3 + vU4
vHC[3][1] = vU1/vDenom
vHC[3][2] = vU2/vDenom
vHC[3][3] = vU3/vDenom
vHC[3][4] = vU4/vDenom
SetDataVector(oboro_in+"|Internal", "aut0", vHC[3][1], )
SetDataVector(oboro_in+"|Internal", "aut1", vHC[3][2], )
SetDataVector(oboro_in+"|Internal", "aut2", vHC[3][3], )
SetDataVector(oboro_in+"|Internal", "aut3", vHC[3][4], )
// Populate household classification vectors
for autos = 1 to 4 do
for persons = 1 to 4 do
vAXP[autos][persons] = vHC[3][autos] * vHC[1][persons]
end
for workers = 1 to 4 do
vAXW[autos][workers] = vHC[3][autos] * vHC[2][workers]
end
end
SetStatus(2, "@System1", )
quit:
RunMacro("CloseAllViews")
return(1)
endmacro
// ----------------------------------------------------------------------------------------------------------
// TRIP GENERATION MODEL
macro "Trip Generation" (Args)
// shared prj_dry_run if prj_dry_run then return(1)
SetStatus(2,"Trip Generation: Ps and As",)
triprate = Args.[Production Rates]
tazpoly = Args.[TAZ Layer]
{oboro_in} = RunMacro("TCB Add DB Layers", tazpoly)
// select internal TAZs, non-group quarters
SetLayer(oboro_in)
qry = "Select * where nz(ExSta)=0"
n = SelectByQuery("Internal", "Several", qry,)
// Make sure P & A fields are present
flist ={"HBW","HBW_bal","HBO","HBO_bal","NHB","NHB_bal","HBsc","HBsc_bal","HBU","HBU_bal","LIGHT","MED","HEAVY",
"ATTHBW","ATTHBW_bal","ATTHBO","ATTHBO_bal","ATTNHB","ATTNHB_bal","ATTHBsc","ATTHBsc_bal","ATTHBU","ATTHBU_bal","ATTLIGHT","ATTMED","ATTHEAVY"}
for k=1 to flist.length do
Field=Field+{ {flist[k], "Real",10,3} }
end
RunMacro("TCB Add View Fields",{oboro_in,Field})
// PFAC = {1.00, 1.00, 1.00, 1.00, 1.00} <<--- Trip production adjusting factors go to Daviess_mod.bin as required by KYTC
// Get trip production adjusting factors
Dim PFAC[5]
PFAC[1] = Args.[HBW P Factor]
PFAC[2] = Args.[HBO P Factor]
PFAC[3] = Args.[NHB P Factor]
PFAC[4] = Args.[HBSch P Factor]
PFAC[5] = Args.[HBU P Factor]
// Trip Productions
pern = {"1_Var","2_Var","3_Var","4_Var"} // var is workers for HBW and persons for all others
Rate_mat = OpenTable("Prates", "FFB", {triprate,})
SetView(Rate_mat)
// get production rates
Dim Prat[6,4,4] // production rates by Purpose, Autos, Persons
for pur = 1 to 5 do //trip purpose loop
qry = "Select * where Pur="+i2s(pur)
sset="Pur_"+i2s(pur)
n = SelectByQuery(sset, "Several", qry,)
for per = 1 to 4 do
vr = nz(GetDataVector(Rate_mat+"|"+sset, pern[per], ))
ra = V2A(vr)
for autos = 1 to 4 do
Prat[pur][autos][per] = ra[autos] * PFAC[pur]
end
end
end
// HBW Productions -- not using income quartile now
for autos = 1 to 4 do
for workers = 1 to 4 do
vProds = vhh * vAXW[autos][workers] * Prat[1][autos][workers]
vPT = if(autos=1 && workers=1) then vProds+0 else vPT + vProds // accumulate
end
end
SetDataVector(oboro_in+"|Internal", "HBW", vPT, )
// Remaining Productions
iname={"HBW","HBO","NHB","HBsc","HBU"}
// HBO & NHB
for pur = 2 to 3 do
for autos = 1 to 4 do
for persons = 1 to 4 do
vProds = vhh * vAXP[autos][persons] * Prat[pur][autos][persons]
vPT = if(autos=1 && persons=1) then vProds+0 else vPT + vProds // accumulate
end
end
if(pur=3) then vPNHB=vPT
SetDataVector(oboro_in+"|Internal", iname[pur], vPT, )
end
// School and college
SetLayer(oboro_in)
v_K12H = GetDataVector(oboro_in+"|Internal", "K12_Home", )
v_CollegeH = GetDataVector(oboro_in+"|Internal", "College_Home", )
pur=4 // school
vPT = v_K12H * Prat[pur][1][1]
SetDataVector(oboro_in+"|Internal", iname[pur], vPT, )
pur=5 // college
vPT = v_CollegeH * Prat[pur][1][1]
SetDataVector(oboro_in+"|Internal", iname[pur], vPT, )
// ----------------------------------------------------------------------------------------------------------
// for empty and group quarters TAZs
qry = "Select * where nz(ID)<>null & (Est_POP/(House_Occ+0.1)>=20 | nz(House_Occ)=0)" // "Select * where EXT=null" -- for now, all zones
n = SelectByQuery("EmptyGQ", "Several", qry,)
vGQ = Vector(n, "Float", {{"Constant",0.0},{"Row Based","True"}})
iname={"HBW","HBO","NHB","HBsc","HBU"}
for pur = 1 to 5 do
SetDataVector(oboro_in+"|EmptyGQ", iname[pur], vGQ, )
end
// ----------------------------------------------------------------------------------------------------------
// Establish income quartiles: 1 - 4, low - high
vQ = Vector(n, "Short", {{"Constant",1},{"Row Based","True"}})
ret_value = 1
/*
// count links at each node in the street layer (use later in Dest.Choice Model) <<--- This is in case we want to do a destination choice model later
SetStatus(2,"Mixed Use Indicator",)
nfile=Args.[Highway Layer]
RunMacro("countlinks",nfile)
RunMacro("mix",nfile,tazpoly)
*/
// ATTRACTION MODEL =============================================================================
// get attraction rates
SetStatus(2,"Trip Attractions",)
arates=Args.[Attraction Rates]
// 1 2 3 4 5 6 7
avars={"HH", "Basic", "Retail", "Service", "Total","k_uenroll","k_students"}
aRate_mat = OpenTable("Arates", "FFB", {arates,})
SetView(aRate_mat)
Dim AR[8,7] // attraction rates by Purpose(8), variable(7)
for avar = 1 to avars.length do //trip purpose loop
vr = nz(GetDataVector(aRate_mat+"|", avars[avar], ))
ra = V2A(vr)
for pur = 1 to 8 do
AR[pur][avar] = ra[pur]
end
end
v_RET = nz(GetDataVector(oboro_in+"|Internal", "EMP_RET", ))
v_SERV = nz(GetDataVector(oboro_in+"|Internal", "EMP_SERV", ))
v_TOTE = nz(GetDataVector(oboro_in+"|Internal", "EMP_TOT", ))
v_ColEnrol = nz(GetDataVector(oboro_in+"|Internal", "College_Enrollment", ))
v_K12Enrol = nz(GetDataVector(oboro_in+"|Internal", "K12_Enrollment", ))
v_NRET = v_TOTE-v_RET-v_SERV // no-retail
iname={"ATTHBW","ATTHBO","ATTNHB","ATTHBsc","ATTHBU","ATTLIGHT","ATTMED","ATTHEAVY"}
dim v_atract[iname.length]
for pur=1 to iname.length do
if pur=1 then v_atract[pur] = (AR[pur][1]*vhh + AR[pur][2]*v_NRET + AR[pur][3]*v_RET + AR[pur][4]*v_SERV + AR[pur][5]*v_TOTE + AR[pur][6]*v_ColEnrol + AR[pur][7]*v_K12Enrol)*1.65 // HBW A's adjusted
if pur=2 then v_atract[pur] = (AR[pur][1]*vhh + AR[pur][2]*v_NRET + AR[pur][3]*v_RET + AR[pur][4]*v_SERV + AR[pur][5]*v_TOTE + AR[pur][6]*v_ColEnrol + AR[pur][7]*v_K12Enrol)*1.34 // HBO A's adjusted
if pur=3 then v_atract[pur] = (AR[pur][1]*vhh + AR[pur][2]*v_NRET + AR[pur][3]*v_RET + AR[pur][4]*v_SERV + AR[pur][5]*v_TOTE + AR[pur][6]*v_ColEnrol + AR[pur][7]*v_K12Enrol)*1.52 // NHB A's adjusted
if (pur>3 and pur<7) then v_atract[pur] = AR[pur][1]*vhh + AR[pur][2]*v_NRET + AR[pur][3]*v_RET + AR[pur][4]*v_SERV + AR[pur][5]*v_TOTE + AR[pur][6]*v_ColEnrol + AR[pur][7]*v_K12Enrol
if pur=7 then v_atract[pur] = (AR[pur][1]*vhh + AR[pur][2]*v_NRET + AR[pur][3]*v_RET + AR[pur][4]*v_SERV + AR[pur][5]*v_TOTE + AR[pur][6]*v_ColEnrol + AR[pur][7]*v_K12Enrol)*1.70 // Medium truck's adjusted to meet ODME target
if pur=8 then v_atract[pur] = (AR[pur][1]*vhh + AR[pur][2]*v_NRET + AR[pur][3]*v_RET + AR[pur][4]*v_SERV + AR[pur][5]*v_TOTE + AR[pur][6]*v_ColEnrol + AR[pur][7]*v_K12Enrol)*2.27 // Heavy truck's adjusted to meet ODME target
SetDataVector(oboro_in+"|Internal", iname[pur], v_atract[pur], )
end
// ---- Balance school productions to school attractions, by county =============
coset=oboro_in+"|County"
setlayer(oboro_in)
// for c= 1 to cname.length do -MB edit due to "Total" added in line 1062 County Summaries"
for c= 1 to 5 do
qry = "Select * where County_Name='"+cname[c]+"'"
n = SelectByQuery("County", "Several", qry,)
v_scp =GetDataVector(coset, "HBSc", )
v_sca =GetDataVector(coset, "ATTHBSc", )
sump = VectorStatistic(v_scp, "Sum", )
suma = VectorStatistic(v_sca, "Sum", )
facsc = suma/sump
v_scp = v_scp*facsc
SetDataVector(coset, "HBSc", v_scp, )
end
// APPLY Special Generators----------------------------------------------
v_HBW = nz(GetDataVector(oboro_in+"|Internal", "ATTHBW", ))
v_HBO = nz(GetDataVector(oboro_in+"|Internal", "ATTHBO", ))
v_NHB = nz(GetDataVector(oboro_in+"|Internal", "ATTNHB", ))
v_sHBW = GetDataVector(oboro_in+"|Internal", "SG_HBW", )
v_sHBO = GetDataVector(oboro_in+"|Internal", "SG_HBO", )
v_sNHB = GetDataVector(oboro_in+"|Internal", "SG_NHB", )
v_HBW=if(v_sHBW<>null) then v_sHBW else v_HBW
v_HBO=if(v_sHBO<>null) then v_sHBO else v_HBO
v_NHB=if(v_sNHB<>null) then v_sNHB else v_NHB
SetDataVector(oboro_in+"|Internal", "ATTHBW", v_HBW,)
SetDataVector(oboro_in+"|Internal", "ATTHBO", v_HBO,)
SetDataVector(oboro_in+"|Internal", "ATTNHB", v_NHB,)
// ----------------------------------------------------------------------
// ---------------------------------------- EXTERNAL-INTERNAL MODEL ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
db_file = Args.[Highway Layer]
netf = Args.[NET AM]
tazpoly = Args.[TAZ Layer]
xfile = Args.[External Data]
//create fields in TAZ file for external trips
flist ={"EE_Auto_P","EE_SU_P","EE_Comb_P","EI_Auto_P","EI_SU_P","EI_Comb_P","EI_Auto_A1","EI_Auto_A2","EI_Auto_A3","EI_Auto_A4",
"EI_Auto_A","EI_SU_A1","EI_SU_A2","EI_SU_A3","EI_SU_A4","EI_SU_A","EI_Comb_A1","EI_Comb_A2","EI_Comb_A3","EI_Comb_A4",
"EI_Comb_A","EI_Auto_A_bal","EI_SU_A_bal","EI_Comb_A_bal","ST1Dist","ST2Dist","ST3Dist","ST4Dist","Tot Int Ps","Tot Int As"}
for k=1 to flist.length do
Field=Field+{ {flist[k], "Real",10,3} }
end
RunMacro("TCB Add View Fields",{oboro_in,Field})
xd = OpenTable("ExData", "FFB", {xfile,})
//SetLayer(oboro_in)
// qry = "Select * where ExSta>0"
//n = SelectByQuery("xstations", "Several", qry,)
vw2 = JoinViews("jv",oboro_in+".ID", xd+".ID",)
v_ADT = nz(GetDataVector(vw2+"|", "ADT", ))
v_EE = nz(GetDataVector(vw2+"|", "EE", ))
v_EI = 1-v_EE
v_EE_a = nz(GetDataVector(vw2+"|", "EE_Auto",))
v_EE_s = nz(GetDataVector(vw2+"|", "EE_SU", ))
v_EE_c = nz(GetDataVector(vw2+"|", "EE_COMB",))
v_EI_a = nz(GetDataVector(vw2+"|", "EI_Auto",))
v_EI_s = nz(GetDataVector(vw2+"|", "EI_SU", ))
v_EI_c = nz(GetDataVector(vw2+"|", "EI_COMB",))
v_EE_Auto_P = 0.5*v_ADT*v_EE*v_EE_a
v_EE_SU_P = 0.5*v_ADT*v_EE*v_EE_s
v_EE_Comb_P = 0.5*v_ADT*v_EE*v_EE_c
v_EI_Auto_P = v_ADT*v_EI*v_EI_a
v_EI_SU_P = v_ADT*v_EI*v_EI_s
v_EI_Comb_P = v_ADT*v_EI*v_EI_c
SetDataVector(vw2+"|", "EE_Auto_P", v_EE_Auto_P,)
SetDataVector(vw2+"|", "EE_SU_P", v_EE_SU_P,)
SetDataVector(vw2+"|", "EE_Comb_P", v_EE_Comb_P,)
SetDataVector(vw2+"|", "EI_Auto_P", v_EI_Auto_P,)
SetDataVector(vw2+"|", "EI_SU_P", v_EI_SU_P,)
SetDataVector(vw2+"|", "EI_Comb_P", v_EI_Comb_P,)
{node_lyr,link_lyr} = RunMacro("TCB Add DB Layers", db_file)
SetLayer(node_lyr)
qry = "Select * where nz(IsCentroid)>0" // centroids for AirSage Analysis
n = SelectByQuery("Centroids", "Several", qry,)
// Distance to External Station for use in EI % calculation
for k= 1 to 4 do
tf=GetTempFileName(".mtx")
fld="ST"+i2s(k)+"Dist"
qry = "Select * where nz(Sta_Type)="+i2s(k) // external nodes
/* NCHRP 716 Station Types
1 - Fwy/Exway
2 - Arterial Near Xway
3 - Arterial Not Near Xway
4 - Collector/Local
*/
n = SelectByQuery("Xnode", "Several", qry,)
if(n>0) then do // skip if there are no stations of this type
Opts = null
Opts.Input.Network = netf
Opts.Input.[Origin Set] = {db_file+"|"+node_lyr, node_lyr,"Centroids"}
Opts.Input.[Destination Set] = {db_file+"|"+node_lyr, node_lyr,"Xnode"}
Opts.Field.Minimize = "Length"
Opts.Field.Nodes = "Node.ID"
Opts.Output.[Output Matrix].Label = "Dist"
Opts.Output.[Output Matrix].[File Name] = tf
ret_value = RunMacro("TCB Run Procedure", "TCSPMAT", Opts, &Ret)
if !ret_value then goto quit
m = OpenMatrix(tf, "True")
mc = CreateMatrixCurrency(m, "Dist - Length", , , )
mvec = GetMatrixVector(mc, {{"Marginal", "Row Minimum"}})
SetDataVector(oboro_in+"|", fld, mvec, {{"Sort Order",{{"ID","A"}}}} )
end
m=null
mc=null
end
// EI model from NCHRP 716
//ak={ 0.071, 0.118, 0.435, 0.153} // original values
//bk={{ -0.599, -1.285, -1.517, -1.482}, { -0.599, -1.285, -1.517, -1.482}, { -0.599, -1.285, -1.517, -1.482}} // ORIGINAL
// exponents held constants, coefficients adjusted to hit targets by station type <<--- These constants go to input\EI_Coefficient.bin as required by KYTC
// ak={{ 0.2061, 0.5636, 1.5246, 0.3658}, { 0.1877, 0.5452, 1.5396, 0.3329}, { 1.4680, 1.7974, 1.7796, 0.4598}}
// bk={{ -1.000, -1.285, -1.517, -1.482}, { -1.000, -1.1565, -1.3653, -1.3338}, { -1.000, -1.0280, -1.2136, -1.1856}} // tweak to allow longer truck trips
// Get EI Model Coefficients
Stype = {"1_Var","2_Var","3_Var", "4_Var"} // var is external station type
EICoeff = Args.[EI Model Coefficients]
EI_Coeff = OpenTable("EI Model Coeff", "FFB", {EICoeff,})
SetView(EI_Coeff)
Dim ak[3,4] // coefficient A by purpose, station type
Dim bk[3,4] // coefficient B by purpose, station type
for c = 1 to 2 do // coefficient loop
qry = "Select * where Coeff="+i2s(c)
sset="Coeff_"+i2s(c)
n = SelectByQuery(sset, "Several", qry,)
if c = 1 then do // coefficient A
for k = 1 to 4 do // station type loop
vr = nz(GetDataVector(EI_Coeff+"|"+sset, Stype[k], ))
ra = v2a(vr)
for m = 1 to 3 do // purpose loop
ak[m][k] = ra[m]
end
end
end
if c = 2 then do // coefficient B
for k = 1 to 4 do // station type loop
vr = nz(GetDataVector(EI_Coeff+"|"+sset, Stype[k], ))
ra = v2a(vr)
for m = 1 to 3 do // purpose loop
bk[m][k] = ra[m]
end
end
end
end
// time permitting, revisit this to calibrate from the KYSTM extract ---
va_hbw =GetDataVector(oboro_in+"|", "ATTHBW", )
va_hbo =GetDataVector(oboro_in+"|", "ATTHBO", )
va_nhb =GetDataVector(oboro_in+"|", "ATTNHB", )
//va_hbsc=GetDataVector(oboro_in+"|", "ATTHBsc", ) // assume no EI/IE school trips
va_hbu =GetDataVector(oboro_in+"|", "ATTHBU", )
va_tot = va_hbw + va_hbo + va_nhb + va_hbu
va_su =GetDataVector(oboro_in+"|", "ATTMED", ) // map medium trucks to SU
va_com =GetDataVector(oboro_in+"|", "ATTHEAVY", ) // map heavy trucks to combinations
// ------ EI Autos, Single Unit trucks, Combination trucks ------------
typ={"EI_Auto_A","EI_SU_A","EI_Comb_A"}
atts={va_tot,va_su,va_com}
dim va_rat[3] // ratio of internal A's after trucks removed to original A's
// EI trips are in vehicles, but when trips are removed from Internal Attractions, they must be converted to persons
occ={1.72,1.00,1.00} // assumed EI persons per vehicle
for m=1 to 3 do
dim v_EIA[5]
for k= 1 to 4 do
df = "ST"+i2s(k)+"Dist"
eif = typ[m]+i2s(k)
v_d =GetDataVector(oboro_in+"|", df, )
v_EIA[k] = ak[m][k]*atts[m]* pow(v_d,bk[m][k])
SetDataVector(oboro_in+"|", eif, v_EIA[k], )
end
if m=1 then v_EIA[5] = min((v_EIA[1] + v_EIA[2] + v_EIA[3] + v_EIA[4])*0.90,atts[m]) // cap EI attractions a the total number of attractions, EI_Auto A's adjusted
if m=2 then v_EIA[5] = min((v_EIA[1] + v_EIA[2] + v_EIA[3] + v_EIA[4])*0.90,atts[m]) // cap EI attractions a the total number of attractions EI_SU A's adjusted
if m=3 then v_EIA[5] = min((v_EIA[1] + v_EIA[2] + v_EIA[3] + v_EIA[4])*1.10,atts[m]) // cap EI attractions a the total number of attractions, EI_Comb A's adjusted
SetDataVector(oboro_in+"|", typ[m], v_EIA[5], )
v_sub=v_EIA[5]*occ[m]
va_rat[m]=if atts[m]>v_sub then (atts[m]-v_EIA[5]*occ[m])/atts[m] else 1 // subtract EI's from I-I attractions
end
// remove EI attractions internal attractions -----------
va_hbw = va_hbw * va_rat[1]
va_hbo = va_hbo * va_rat[1]
va_nhb = va_nhb * va_rat[1]
va_hbu = va_hbu * va_rat[1]
va_su = va_su * va_rat[2]
va_com = va_com * va_rat[3]
SetDataVector(oboro_in+"|", "ATTHBW", va_hbw, )
SetDataVector(oboro_in+"|", "ATTHBO", va_hbo, )
SetDataVector(oboro_in+"|", "ATTNHB", va_nhb, )
SetDataVector(oboro_in+"|", "ATTHBU", va_hbu, )
SetDataVector(oboro_in+"|", "ATTMED", va_su, )
SetDataVector(oboro_in+"|", "ATTHEAVY", va_com, )
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
// set truck productions to truck attractions
SetDataVector(oboro_in+"|Internal", "LIGHT", v_atract[6], ) // at the external stations, these will be indistinguishable from autos
SetDataVector(oboro_in+"|", "MED", va_su, ) // at the external stations, these will be SU
SetDataVector(oboro_in+"|", "HEAVY", va_com, ) // at the external stations, these will be COMB
// BALANCE P's and A's -------------------------
eqry = "Select * where (nz(ExSta)>0) | (nz(SG_HBW)+nz(SG_HBO)+nz(SG_NHB)>0)"
zone_set = tazpoly+"|"+oboro_in
balf=Args.[Balanced ATTR Table]
Opts = null
Opts.Input.[Data View Set] = {tazpoly+"|"+oboro_in, oboro_in}
// even though we hold this, there are not EI attractions at external stations anyway.
Opts.Input.[V2 Holding Sets] = {,,,,,{zone_set, oboro_in, "External", eqry},{zone_set, oboro_in, "External", eqry},{zone_set, oboro_in, "External", eqry}}
Opts.Field.[Vector 1] = {"HBW", "HBO", "NHB", "HBsc", "HBU","EI_Auto_P","EI_SU_P","EI_Comb_P"}
Opts.Field.[Vector 2] = {"ATTHBW", "ATTHBO", "ATTNHB", "ATTHBsc", "ATTHBU","EI_Auto_A","EI_SU_A","EI_Comb_A"}
Opts.Global.[Holding Method] = {"Hold Vector 1", "Hold Vector 1", "Hold Vector 1", "Hold Vector 2", "Hold Vector 2", "Hold Vector 1", "Hold Vector 1", "Hold Vector 1"}
Opts.Global.[Percent Weight] = {, , , , , , ,}
Opts.Global.[Store Type] = "Real"
Opts.Output.[Output Table] = balf
ret_value = RunMacro("TCB Run Procedure", "Balance", Opts, &Ret)
if !ret_value then goto quit
// ---------------------------------------------
bal_tab = OpenTable("balance", "FFB", {balf,})
vw2 = JoinViews("jv",oboro_in+".ID", bal_tab+".ID1",)
vp_hbw =GetDataVector(vw2+"|", bal_tab+".HBW", )
vp_hbo =GetDataVector(vw2+"|", bal_tab+".HBO", )
vp_nhb =GetDataVector(vw2+"|", bal_tab+".NHB", )
vp_hbsc=GetDataVector(vw2+"|", bal_tab+".HBsc", )
vp_hbu =GetDataVector(vw2+"|", bal_tab+".HBU", )
va_hbw =GetDataVector(vw2+"|", bal_tab+".ATTHBW", )
va_hbo =GetDataVector(vw2+"|", bal_tab+".ATTHBO", )
va_nhb =GetDataVector(vw2+"|", bal_tab+".ATTNHB", )
va_hbsc=GetDataVector(vw2+"|", bal_tab+".ATTHBsc", )
va_hbu =GetDataVector(vw2+"|", bal_tab+".ATTHBU", )
// truck vectors for summary
va_light =GetDataVector(vw2+"|", oboro_in+".ATTLIGHT", )
va_medium =GetDataVector(vw2+"|", oboro_in+".ATTMED", )
va_heavy =GetDataVector(vw2+"|", oboro_in+".ATTHEAVY", )
vp_light =GetDataVector(vw2+"|", oboro_in+".LIGHT", )
vp_medium =GetDataVector(vw2+"|", oboro_in+".MED", )
vp_heavy =GetDataVector(vw2+"|", oboro_in+".HEAVY", )
va_EI_Auto =GetDataVector(vw2+"|", bal_tab+".EI_Auto_A", )
va_EI_SU =GetDataVector(vw2+"|", bal_tab+".EI_SU_A", )
va_EI_Comb =GetDataVector(vw2+"|", bal_tab+".EI_Comb_A", )
vp_EI_Auto =GetDataVector(vw2+"|", bal_tab+".EI_Auto_P", )
vp_EI_SU =GetDataVector(vw2+"|", bal_tab+".EI_SU_P", )
vp_EI_Comb =GetDataVector(vw2+"|", bal_tab+".EI_Comb_P", )
SetDataVector(vw2+"|", oboro_in+".HBW_bal", vp_hbw, )
SetDataVector(vw2+"|", oboro_in+".HBO_bal", vp_hbo, )
SetDataVector(vw2+"|", oboro_in+".NHB_bal", va_nhb, ) // note here that NHB P's are replaced by balanced NHB attractions
SetDataVector(vw2+"|", oboro_in+".HBsc_bal", vp_hbsc,)
SetDataVector(vw2+"|", oboro_in+".HBU_bal", nz(vp_hbu), )
SetDataVector(vw2+"|", oboro_in+".ATTHBW_bal", va_hbw, )
SetDataVector(vw2+"|", oboro_in+".ATTHBO_bal", va_hbo, )
SetDataVector(vw2+"|", oboro_in+".ATTNHB_bal", va_nhb, )
SetDataVector(vw2+"|", oboro_in+".ATTHBsc_bal", va_hbsc,)
SetDataVector(vw2+"|", oboro_in+".ATTHBU_bal", nz(va_hbu), )
SetDataVector(vw2+"|", oboro_in+".EI_Auto_A_bal", nz(va_EI_Auto),)
SetDataVector(vw2+"|", oboro_in+".EI_SU_A_bal", nz(va_EI_SU),)
SetDataVector(vw2+"|", oboro_in+".EI_Comb_A_bal", nz(va_EI_Comb),)
SetDataVector(vw2+"|", oboro_in+".EI_Auto_P", nz(vp_EI_Auto),)
SetDataVector(vw2+"|", oboro_in+".EI_SU_P", nz(vp_EI_SU),)
SetDataVector(vw2+"|", oboro_in+".EI_Comb_P", nz(vp_EI_Comb),)
// total internal p's and a's
vp_itot = nz(vp_hbw) +nz(vp_hbo) +nz(va_nhb) +nz(vp_hbsc) +nz(vp_hbu)+ nz(vp_light) +nz(vp_medium)+ nz(vp_heavy)
va_itot = nz(va_hbw) +nz(va_hbo) +nz(va_nhb) +nz(va_hbsc) +nz(va_hbu)+ nz(va_light) +nz(va_medium)+ nz(va_heavy)
SetDataVector(vw2+"|", oboro_in+".Tot Int Ps", nz(vp_itot),)
SetDataVector(vw2+"|", oboro_in+".Tot Int As", nz(va_itot),)
// summaries by County +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cc=cname.length+1
dim pop_c[cc],hh_c[cc],wk_c[cc],aut_c[cc],K12_c[cc],coll_c[cc],K12H_c[cc],CollegeH_c[cc],TEmp_c[cc]
dim hbwp_c[cc],hbwa_c[cc],hbop_c[cc],hboa_c[cc],nhbp_c[cc],nhba_c[cc],hbscp_c[cc],hbsca_c[cc],hbup_c[cc],hbua_c[cc]
SetLayer(oboro_in)
coset=oboro_in+"|County"
for c= 1 to cname.length do
qry = "Select * where County_Name='"+cname[c]+"'"
n = SelectByQuery("County", "Several", qry,)
v_pop =GetDataVector(coset, "Est_POP", )
v_hh =GetDataVector(coset, "House_Occ", )
v_wk =GetDataVector(coset, "Workers", )
v_aut =GetDataVector(coset, "Vehicles", )
v_K12 =GetDataVector(coset, "K12_Enrollment", )
v_coll =GetDataVector(coset, "College_Enrollment", )
v_K12H =GetDataVector(coset, "K12_Home", )
v_CollegeH=GetDataVector(coset, "College_Home", )
v_temp=GetDataVector(coset, "EMP_TOT", )
v_hbwp =GetDataVector(coset, "HBW", )
v_hbop =GetDataVector(coset, "HBO", )
v_nhbp =GetDataVector(coset, "NHB", )
v_hbscp=GetDataVector(coset, "HBsc", )
v_hbup =GetDataVector(coset, "HBU", )
v_hbwa =GetDataVector(coset, "ATTHBW", )
v_hboa =GetDataVector(coset, "ATTHBO", )
v_nhba =GetDataVector(coset, "ATTNHB", )
v_hbsca=GetDataVector(coset, "ATTHBsc", )
v_hbua =GetDataVector(coset, "ATTHBU", )
pop_c[c] = VectorStatistic(v_pop, "Sum", )
pop_c[cc] = nz(pop_c[cc])+pop_c[c]
hh_c[c] = VectorStatistic(v_hh, "Sum", )
hh_c[cc] = nz(hh_c[cc])+hh_c[c]
wk_c[c] = VectorStatistic(v_wk, "Sum", )
wk_c[cc] = nz(wk_c[cc])+wk_c[c]
aut_c[c] = VectorStatistic(v_aut, "Sum", )
aut_c[cc] = nz(aut_c[cc])+aut_c[c]
K12_c[c] = VectorStatistic(v_K12, "Sum", )
K12_c[cc] = nz(K12_c[cc])+K12_c[c]
coll_c[c] = VectorStatistic(v_coll, "Sum", )