-
Notifications
You must be signed in to change notification settings - Fork 2
/
5 - Benefits.rsc
1114 lines (938 loc) · 48.7 KB
/
5 - Benefits.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
// Project Benefit Calculation DBox
dBox "Benefits" center,center,170,35 toolbox NoKeyboard Title:"Benefit Calculation"
init do
shared Args
if Args.General.debug = 1 then do
ShowItem("Debug")
end
// Default the no-build dbd to the general dbd
if Args.Benefits.noBuildHwy = null then Args.Benefits.noBuildHwy = Args.General.hwyDBD
Args.Benefits.noBuildHwyArray = {"Choose Highway DBD",Args.Benefits.noBuildHwy}
Args.Benefits.PosVars.nbHwy = 2
Args.Benefits.allBuildHwyArray = {"Choose Highway DBD",Args.Benefits.allBuildHwy}
if Args.Benefits.allBuildHwy <> null then Args.Benefits.PosVars.abHwy = 2
// Update the Link Field List
{Args.Benefits.nlayer,Args.Benefits.llayer} = GetDBLayers(Args.Benefits.noBuildHwy)
a_info = GetDBInfo(Args.Benefits.noBuildHwy)
Args.Benefits.hwyScope = a_info[1]
tempLink = AddLayerToWorkspace(Args.Benefits.llayer,Args.Benefits.noBuildHwy,Args.Benefits.llayer,)
fieldList = GetFields(tempLink,"All")
Args.General.linkFieldList = fieldList[1] // updating the general list so that all dBoxs benefit
DropLayerFromWorkspace(tempLink)
// Initialize the delay units list
Args.Benefits.unitList = {"mins","hours"}
// Setup the array that will control which dbox items are updated
// when the dBox is opened or settings are loaded.
Args.GUI.Benefits.ItemList = {
{"popNBHwy",,Args.Benefits.noBuildHwy,Args.Benefits.noBuildHwyArray,"nbHwy"},
{"popABHwy",,Args.Benefits.allBuildHwy,Args.Benefits.allBuildHwyArray,"abHwy"},
{"popProjID",,Args.Benefits.projID,Args.General.linkFieldList,"projID"},
{"popFlow",,Args.Benefits.abFlow,Args.General.linkFieldList,"abFlow"},
{"popCap",,Args.Benefits.abCap,Args.General.linkFieldList,"abCap"},
{"popDelay",,Args.Benefits.abDelay,Args.General.linkFieldList,"abDelay"},
{"popDelayUnits",,Args.Benefits.abDelayUnits,Args.Benefits.unitList,"abDelayUnits"}
}
if Args.Benefits.length <> null then RunMacro("Set Benefits Dbox Items")
enditem
// No-Build Highway DBD drop down menu
Popdown Menu "popNBHwy" 12, 2, 100, 7 prompt: "No-Build Highway" list: Args.Benefits.noBuildHwyArray variable:Args.Benefits.PosVars.nbHwy do
on escape goto quit
if Args.Benefits.PosVars.nbHwy = 1 then do
Args.Benefits.noBuildHwy = ChooseFile({{"Geographic File (*.dbd)", "*.dbd"}}, "Choose Highway DBD",{{"Initial Directory",Args.General.initialDir}})
// path = SplitPath(Args.Benefits.noBuildHwy)
// Args.Benefits.noBuildHwyArray = {"Choose Highway DBD",path[3] + path[4]}
Args.Benefits.noBuildHwyArray = {"Choose Highway DBD",Args.Benefits.noBuildHwy}
Args.Benefits.PosVars.nbHwy = 2
{Args.Benefits.nlayer,Args.Benefits.llayer} = GetDBLayers(Args.Benefits.noBuildHwy)
a_info = GetDBInfo(Args.Benefits.noBuildHwy)
Args.Benefits.hwyScope = a_info[1]
tempLink = AddLayerToWorkspace(Args.Benefits.llayer,Args.Benefits.noBuildHwy,Args.Benefits.llayer,)
fieldList = GetFields(tempLink,"All")
Args.General.linkFieldList = fieldList[1]
DropLayerFromWorkspace(tempLink)
end
quit:
on escape default
enditem
// All-Build Highway DBD drop down menu
Popdown Menu "popABHwy" same, after, 100, 7 prompt: "All-Build Highway" list: Args.Benefits.allBuildHwyArray variable:Args.Benefits.PosVars.abHwy do
on escape goto quit
if Args.Benefits.PosVars.abHwy = 1 then do
Args.Benefits.allBuildHwy = ChooseFile({{"Geographic File (*.dbd)", "*.dbd"}}, "Choose Highway DBD",{{"Initial Directory",Args.General.initialDir}})
// path = SplitPath(Args.Benefits.allBuildHwy)
// Args.Benefits.allBuildHwyArray = {"Choose Highway DBD",path[3] + path[4]}
Args.Benefits.allBuildHwyArray = {"Choose Highway DBD",Args.Benefits.allBuildHwy}
Args.Benefits.PosVars.abHwy = 2
end
quit:
on escape default
enditem
// Choose the Project ID Field
Popdown Menu "popProjID" same, after, 20, 8 prompt: "ProjectID" list: Args.General.linkFieldList variable: Args.Benefits.PosVars.projID do
Args.Benefits.projID = Args.General.linkFieldList[Args.Benefits.PosVars.projID]
// In order to use the project ID to make selections later, determine if the field
// is made up of strings or numbers
temp = AddLayerToWorkspace(Args.Benefits.llayer,Args.Benefits.noBuildHwy,Args.Benefits.llayer)
Args.Benefits.projIDType = GetFieldTableType(Args.Benefits.llayer + "." + Args.Benefits.projID)
DropLayerFromWorkspace(temp)
enditem
// Choose AB Flow Field
Text same,after Variable:"(BA fields are found automatically)"
Popdown Menu "popFlow" same, after, 20, 8 prompt: "AB Daily Flow" list: Args.General.linkFieldList variable: Args.Benefits.PosVars.abFlow do
Args.Benefits.abFlow = Args.General.linkFieldList[Args.Benefits.PosVars.abFlow]
temp = RunMacro("getBAField",Args.Benefits.abFlow, Args.General.linkFieldList)
Args.Benefits.baFlow = temp[1]
enditem
// Choose AB Cap Field
Popdown Menu "popCap" same, after, 20, 8 prompt: "AB Daily Capacity" list: Args.General.linkFieldList variable: Args.Benefits.PosVars.abCap do
Args.Benefits.abCap = Args.General.linkFieldList[Args.Benefits.PosVars.abCap]
temp = RunMacro("getBAField",Args.Benefits.abCap, Args.General.linkFieldList)
Args.Benefits.baCap = temp[1]
enditem
// Choose FF Speed
Popdown Menu "popFFSpeed" same, after, 20, 8 prompt: "AB FF Speed" list: Args.General.linkFieldList variable: Args.Benefits.PosVars.abffSpeed do
Args.Benefits.abffSpeed = Args.General.linkFieldList[Args.Benefits.PosVars.abffSpeed]
temp = RunMacro("getBAField",Args.Benefits.abffSpeed, Args.General.linkFieldList)
Args.Benefits.baffSpeed = temp[1]
enditem
// Choose AB Delay Field
Popdown Menu "popDelay" same, after, 20, 8 prompt: "AB Daily Delay" list: Args.General.linkFieldList variable: Args.Benefits.PosVars.abDelay do
Args.Benefits.abDelay = Args.General.linkFieldList[Args.Benefits.PosVars.abDelay]
temp = RunMacro("getBAField",Args.Benefits.abDelay, Args.General.linkFieldList)
Args.Benefits.baDelay = temp[1]
enditem
// Delay units
Popdown Menu "popDelayUnits" after, same, 10, 8 list: Args.Benefits.unitList variable: Args.Benefits.PosVars.abDelayUnits do
Args.Benefits.abDelayUnits = Args.Benefits.unitList[Args.Benefits.PosVars.abDelayUnits]
enditem
// Buffer size
Edit Text "ben_buffer" 55, 5.75, 5,1 Prompt:"Buffer Radius (mi)" Variable: Args.Benefits.buffer
// Actual calculation
button 20, 16, 23 Prompt:"Calculate Project Benefits" do
CreateProgressBar("Calculating Benfeits", "True")
// Create the output directory
path = SplitPath(Args.Benefits.allBuildHwy)
Args.Benefits.outputDir = path[1] + path[2] + "\\BenefitCalculation\\"
on error goto skipfolder
CreateDirectory(Args.Benefits.outputDir)
skipfolder:
on error default
// Create a copy of the all-build dbd without centroid connectors
// (Exporting is much faster than copying and deleting links)
Args.Benefits.resultHwy = Args.Benefits.outputDir + "BenefitCalculation.dbd"
{nlayer, llayer} = GetDBLayers(Args.Benefits.allBuildHwy)
llayer = AddLayerToWorkspace(llayer, Args.Benefits.allBuildHwy, llayer)
SetLayer(llayer)
ccClass = if TypeOf(Args.General.ccClass) = "string"
then "'" + Args.General.ccClass + "'"
else String(Args.General.ccClass)
qry = "Select * where " + Args.General.fClass + " <> " + ccClass
n = SelectByQuery("non-CCs", "Several", qry)
opts = null
{, opts.[Field Spec]} = GetFields(llayer, "All")
ExportGeography(llayer + "|non-CCs", Args.Benefits.resultHwy, opts)
DropLayerFromWorkspace(llayer)
// Open the result highway layer
{nlayer, llayer} = GetDBLayers(Args.Benefits.resultHwy)
llayer = AddLayerToWorkspace(llayer, Args.Benefits.resultHwy, llayer)
// In this code "ab" and "nb" stand for "all build" and "no build"
// Directionality (AB/BA) will be capitalized to avoid confusion
// Join the nobuild layer to the result layer
a_noBuildLayers = GetDBLayers(Args.Benefits.noBuildHwy)
noBuildLayer = AddLayerToWorkspace(a_noBuildLayers[2],Args.Benefits.noBuildHwy,a_noBuildLayers[2])
dv_join = JoinViews("allbuild+nobuild",llayer+".ID",noBuildLayer+".ID",)
SetView(dv_join)
// Collect projID, vol, cap, and time measures
// (convert any nulls to zeros)
Opts = null
Opts.[Missing As Zero] = "True"
v_linkID = GetDataVector(dv_join + "|", llayer + ".ID", Opts)
v_length = GetDataVector(dv_join + "|", llayer + ".Length", Opts)
v_allprojid = GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.projID, Opts)
// all build values
v_abABffSpeed = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.abffSpeed, Opts))
v_abBAffSpeed = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.baffSpeed, Opts))
v_abABVol = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.abFlow, Opts))
v_abBAVol = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.baFlow, Opts))
v_abABCap = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.abCap, Opts))
v_abBACap = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.baCap, Opts))
v_abABDelay = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.abDelay, Opts))
v_abBADelay = nz(GetDataVector(dv_join + "|", llayer + "." + Args.Benefits.baDelay, Opts))
// no build values
v_nbABffSpeed = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.abffSpeed, Opts))
v_nbBAffSpeed = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.baffSpeed, Opts))
v_nbABVol = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.abFlow, Opts))
v_nbBAVol = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.baFlow, Opts))
v_nbABCap = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.abCap, Opts))
v_nbBACap = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.baCap, Opts))
v_nbABDelay = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.abDelay, Opts))
v_nbBADelay = nz(GetDataVector(dv_join + "|", noBuildLayer + "." + Args.Benefits.baDelay, Opts))
CloseView(dv_join)
DropLayerFromWorkspace(llayer)
DropLayerFromWorkspace(noBuildLayer)
// Calculate absolute and pct changes from no build to build
v_ABVolDiff = v_abABVol - v_nbABVol
v_BAVolDiff = v_abBAVol - v_nbBAVol
v_totVolDiff = v_ABVolDiff + v_BAVolDiff
// if the volume decreases to 0, it should be -100%
v_ABVolPctDiff = if ( v_nbABVol = 0 ) then 999 else (v_abABVol - v_nbABVol) / v_nbABVol * 100
v_BAVolPctDiff = if ( v_nbBAVol = 0 ) then 999 else (v_abBAVol - v_nbBAVol) / v_nbBAVol * 100
v_ABCapDiff = v_abABCap - v_nbABCap
v_BACapDiff = v_abBACap - v_nbBACap
v_totCapDiff = v_ABCapDiff + v_BACapDiff
// if the capacity decreases to 0, it should be -100%
v_ABCapPctDiff = if ( v_nbABCap = 0 ) then 999 else (v_abABCap - v_nbABCap) / v_nbABCap * 100
v_BACapPctDiff = if ( v_nbBACap = 0 ) then 999 else (v_abBACap - v_nbBACap) / v_nbBACap * 100
// If delay is in minutes, convert to hours
if Args.Benefits.abDelayUnits = "mins" then do
v_abABDelay = v_abABDelay / 60
v_abBADelay = v_abBADelay / 60
v_nbABDelay = v_nbABDelay / 60
v_nbBADelay = v_nbBADelay / 60
end
/*
Discount delay
This is an optional feature that is currently not used.
The idea is to dampen the effects of extreme deficiency while still
being sensitive to changes in V/C above 1. A discount value of .5,
for example, would reduce delay from congestion above V/C = 1
(i.e. below half the FFS) by 50%.
There is really no way to calibrate this number, and to date, using the
conical VDF and scanning the no-build network for extreme V/C and making
needed corrections has been adequate. Setting the discount = 1 effectively
turns off this feature.
*/
discount = 1
// calculate delay at V/C = 1
// [trav time at half speed] * flow
v_abABmaxDelay = if v_abABffSpeed = 0 then 0 else v_length / ( v_abABffSpeed / 2 ) * v_abABVol
v_abBAmaxDelay = if v_abBAffSpeed = 0 then 0 else v_length / ( v_abBAffSpeed / 2 ) * v_abBAVol
v_nbABmaxDelay = if v_nbABffSpeed = 0 then 0 else v_length / ( v_nbABffSpeed / 2 ) * v_nbABVol
v_nbBAmaxDelay = if v_nbBAffSpeed = 0 then 0 else v_length / ( v_nbBAffSpeed / 2 ) * v_nbBAVol
v_abABDelayDiscount = if v_abABDelay <= v_abABmaxDelay then v_abABDelay else v_abABmaxDelay + (v_abABDelay - v_abABmaxDelay) * discount
v_abBADelayDiscount = if v_abBADelay <= v_abBAmaxDelay then v_abBADelay else v_abBAmaxDelay + (v_abBADelay - v_abBAmaxDelay) * discount
v_nbABDelayDiscount = if v_nbABDelay <= v_nbABmaxDelay then v_nbABDelay else v_nbABmaxDelay + (v_nbABDelay - v_nbABmaxDelay) * discount
v_nbBADelayDiscount = if v_nbBADelay <= v_nbBAmaxDelay then v_nbBADelay else v_nbBAmaxDelay + (v_nbBADelay - v_nbBAmaxDelay) * discount
v_ABDelayDiff = v_abABDelayDiscount - v_nbABDelayDiscount
v_BADelayDiff = v_abBADelayDiscount - v_nbBADelayDiscount
v_totDelayDiff = v_ABDelayDiff + v_BADelayDiff
// Check calculation in debug mode
if Args.General.debug = 1 then do
csvFile = Args.Benefits.outputDir + "delay discount check.csv"
file = OpenFile(csvFile,"w")
WriteLine(file," ,,No Build, , , , , ,,All Build, , , , , ")
WriteLine(file,"ID,,AB Delay,BA Delay,AB Max Delay,BA Max Delay,AB Discounted Delay,BA Discounted Delay,,AB Delay,BA Delay,AB Max Delay,BA Max Delay,AB Discounted Delay,BA Discounted Delay")
for i = 1 to v_ABDelayDiff.length do
WriteLine(file,String(v_linkID[i]) + ",," + String(v_nbABDelay[i]) + "," + String(v_nbBADelay[i]) + "," + String(v_nbABmaxDelay[i]) + "," + String(v_nbBAmaxDelay[i]) + "," + String(v_nbABDelayDiscount[i]) + "," + String(v_nbBADelayDiscount[i]) + ",," + String(v_abABDelay[i]) + "," + String(v_abBADelay[i]) + "," + String(v_abABmaxDelay[i]) + "," + String(v_abBAmaxDelay[i]) + "," + String(v_abABDelayDiscount[i]) + "," + String(v_abBADelayDiscount[i]))
end
CloseFile(file)
end
// Determine the unique list of project IDs
Opts = null
Opts.Unique = "True"
Opts.Ascending = "False"
v_uniqueProjID = SortVector(v_allprojid,Opts)
// Determine which projects change capacity
// (includes road diets as well as widenings)
a_projID = null
for i = 1 to v_uniqueProjID.length do
curProjID = v_uniqueProjID[i]
// Get the capacity change for the current project
v_capCheck = if ( v_allprojid = curProjID ) then v_totCapDiff else 0
totCapDiff = VectorStatistic(v_capCheck,"sum",)
// If the project has changed capacity, add it to the list
// Also, if the proj ID is 0 or null, ignore it.
if totCapDiff <> 0 then do
zero = if TypeOf(curProjID) = "string" then "0" else 0
if curProjID = zero or curProjID = null then continue
a_projID = a_projID + {curProjID}
end
end
v_projID = A2V(a_projID)
/*
Parcel the benefits out into primary and secondary types
Primary: caused by improvement to the link
Secondary: caused by improvements to other, nearby links
For each link, the first step is to calculate the percentage of primary and secondary benefit
Start with rules:
New Links
| Decrease Delay |Increase Delay
Increase Capacity (New Road) | |
Increase Volume | n/a |Primary
Decrease Volume | n/a |n/a
| |
| |
Existing Links | |
| Decrease Delay |Increase Delay
Increase Capacity (Widening) | |
Increase Volume | Primary |Secondary
Decrease Volume | Both (D.D.) |n/a D.D. = decreased delay
Decrease Capacity (Road Diet) | |
Increase Volume | n/a |Both (I.D.) I.D. = increased delay
Decrease Volume | Secondary |Primary
For the cells above labelled "Both", a ratio of primary and secondary benefits
must be determined.
The change in capacity is used to approximate the proportion of primary benefit.
i.e. capacity increases are the result of the project
The change in volume is used to approximate the proportion of secondary benefit.
i.e. volume decreases are the result of improvement in other projects
Thus, the following ratio of ratios:
abs(%change in Cap) / ( abs(%change in Cap) + abs(%change in Vol) )
Absolute value is needed because, while capacity and volume are moving in opposite
direction, you want to know their relative magnitude.
This metric will determine how much of the change in delay on the project is
due to the project and how much is the secondary benefit from other projects.
Example 1: if a link's capacity increases by 20% and it's volume decreases by 10%:
2/3 of the delay reduction is due to the project. That is primary benefit.
1/3 is due to improvements from other projects drawing volume away. Secondary benefit.
Example 2: if a link's capacity decreases by 30% and it's volume increases by 10%:
3/4 of the delay increase is due to the project.
1/4 is due to changes in other links.
*/
// For this section of code, ab/ba once again refers to direction (ab is not "all build").
// Confusing. Clean up if given time.
// Determine which cell (from the commented table above) the links fall into.
v_linkCategory = Vector(v_allprojid.length,"String",)
v_linkCategory = if (v_totDelayDiff < 0) then // Decreased Delay
(if v_totCapDiff >= 0 then // Increased Capacity
(if v_totVolDiff >= 0 then "Primary" else "Both") // Increased/Decreased Volume
else(if v_totCapDiff < 0 then // Decreased Capacity
(if v_totVolDiff >= 0 then "n/a" else "Secondary") // Increased/Decreased Volume
)
)
else if (v_totDelayDiff >= 0) then // Increased Delay
(if v_totCapDiff >= 0 then // Increased Capacity
(if v_totVolDiff >= 0 then "Secondary" else "n/a") // Increased/Decreased Volume
else(if v_totCapDiff < 0 then // Decreased Capacity
(if v_totVolDiff >= 0 then "Both" else "Primary") // Increased/Decreased Volume
)
)
else null
// all delay changes on new facilities are primary
v_linkCategory = if (v_nbABCap + v_nbBACap = 0) then "Primary" else v_linkCategory
// if capacity doesn't change, all delay changes are secondary
v_linkCategory = if v_totCapDiff = 0 then "Secondary" else v_linkCategory
// Calculate the "both" ratios for all links (even though only used for some)
v_abCapRatio = abs(v_ABCapPctDiff) / ( abs(v_ABCapPctDiff) + abs(v_ABVolPctDiff ))
v_baCapRatio = abs(v_BACapPctDiff) / ( abs(v_BACapPctDiff) + abs(v_BAVolPctDiff ))
v_abVolRatio = abs(v_ABVolPctDiff) / ( abs(v_ABCapPctDiff) + abs(v_ABVolPctDiff ))
v_baVolRatio = abs(v_BAVolPctDiff) / ( abs(v_BACapPctDiff) + abs(v_BAVolPctDiff ))
// Calculate primary/secondary benefits based on this grouping
// Multiply the benefit vectors by -1 to change a decrease in delay
// into a positive benefit metric.
v_abPrimBen = if v_linkCategory = "Primary" then v_ABDelayDiff * -1 else 0
v_abPrimBen = if v_linkCategory = "Both" then
v_ABDelayDiff * -1 * v_abCapRatio else v_abPrimBen
v_baPrimBen = if v_linkCategory = "Primary" then v_BADelayDiff * -1 else 0
v_baPrimBen = if v_linkCategory = "Both" then
v_BADelayDiff * -1 * v_baCapRatio else v_baPrimBen
v_abSecBen = if v_linkCategory = "Secondary" then v_ABDelayDiff * -1 else 0
v_abSecBen = if v_linkCategory = "Both" then
v_ABDelayDiff * -1 * v_abVolRatio else v_abSecBen
v_baSecBen = if v_linkCategory = "Secondary" then v_BADelayDiff * -1 else 0
v_baSecBen = if v_linkCategory = "Both" then
v_BADelayDiff * -1 * v_baVolRatio else v_baSecBen
// Check calculation in debug mode
if Args.General.debug = 1 then do
path = SplitPath(Args.Benefits.allBuildHwy)
Args.Benefits.outputDir = path[1] + path[2] + "\\BenefitCalculation\\"
testCSV = Args.Benefits.outputDir + "TestLinkCategoryLogic.csv"
file = OpenFile(testCSV,"w")
WriteLine(file,"ProjID,nbCap,totDelayDiff,totCapDiff,totVolDiff,Type,abCapRatio,baCapRatio,abVolRatio,baVolRatio,abPrimBen,baPrimBen,abSecBen,baSecBen")
for i = 1 to v_linkCategory.length do
pID = v_allprojid[i]
pID = if TypeOf(pID) <> "string" then String(pID) else pID
WriteLine(file, pID + "," + String(v_nbABCap[i] + v_nbBACap[i]) + "," + String(v_totDelayDiff[i]) + "," + String(v_totCapDiff[i]) + "," + String(v_totVolDiff[i])
+ "," + v_linkCategory[i] + "," + String(v_abCapRatio[i]) + "," + String(v_baCapRatio[i]) + "," + String(v_abVolRatio[i]) + "," + String(v_baVolRatio[i]) + "," + String(v_abPrimBen[i]) + "," + String(v_baPrimBen[i])
+ "," + String(v_abSecBen[i]) + "," + String(v_baSecBen[i]))
end
CloseFile(file)
end
// For some reason, these equations can lead to "negative zero"
// results that sort as smaller than, for example, -80
// Doesn't make sense - Have to set them to 0
v_abPrimBen = if ( v_abPrimBen < .0001 and v_abPrimBen > -.0001 ) then 0
else v_abPrimBen
v_baPrimBen = if ( v_baPrimBen < .0001 and v_baPrimBen > -.0001 ) then 0
else v_baPrimBen
v_abSecBen = if ( v_abSecBen < .0001 and v_abSecBen > -.0001 ) then 0
else v_abSecBen
v_baSecBen = if ( v_baSecBen < .0001 and v_baSecBen > -.0001 ) then 0
else v_baSecBen
// Modify the structure of the result hwy file
// to add benefit-related fields
{nlayer, llayer} = GetDBLayers(Args.Benefits.resultHwy)
dv_temp = AddLayerToWorkspace(
llayer, Args.Benefits.resultHwy, llayer,
)
strct = GetTableStructure(dv_temp)
for i = 1 to strct.length do
strct[i] = strct[i] + {strct[i][1]}
end
strct = strct + {{"ABCapChange" , "Real", 12, 2, "False", , , "AB Pct Capacity Change on Link", , , , null}}
strct = strct + {{"BACapChange" , "Real", 12, 2, "False", , , "BA Pct Capacity Change on Link", , , , null}}
strct = strct + {{"ABPctCapChange" , "Real", 12, 2, "False", , , "AB Pct Capacity Change on Link", , , , null}}
strct = strct + {{"BAPctCapChange" , "Real", 12, 2, "False", , , "BA Pct Capacity Change on Link", , , , null}}
strct = strct + {{"ABVolChange" , "Real", 12, 2, "False", , , "AB Pct Volume Change on Link", , , , null}}
strct = strct + {{"BAVolChange" , "Real", 12, 2, "False", , , "BA Pct Volume Change on Link", , , , null}}
strct = strct + {{"ABPctVolChange" , "Real", 12, 2, "False", , , "AB Pct Volume Change on Link", , , , null}}
strct = strct + {{"BAPctVolChange" , "Real", 12, 2, "False", , , "BA Pct Volume Change on Link", , , , null}}
// If the delay is discounted for V/C > 1, state that in the description
if discount <> 1 then do
strct = strct + {{"ABDelayChange" , "Real", 12, 2, "False", , , "Discounted AB Delay Change on Link. Delay above V/C = 1 multiplied by " + String(discount), , , , null}}
strct = strct + {{"BADelayChange" , "Real", 12, 2, "False", , , "Discounted AB Delay Change on Link. Delay above V/C = 1 multiplied by " + String(discount), , , , null}}
end else do
strct = strct + {{"ABDelayChange" , "Real", 12, 2, "False", , , "Total AB Delay Change on Link", , , , null}}
strct = strct + {{"BADelayChange" , "Real", 12, 2, "False", , , "Total BA Delay Change on Link", , , , null}}
end
strct = strct + {{"LinkCategory" , "String", 12, 2, "False", , , "Whether the link benefits are Primary, Secondary, or Both", , , , null}}
strct = strct + {{"ABPrimBen" , "Real", 12, 4, "False", , , "Delay savings from improvements to this link", , , , null}}
strct = strct + {{"BAPrimBen" , "Real", 12, 4, "False", , , "Delay savings from improvements to this link", , , , null}}
strct = strct + {{"ABSecBen" , "Real", 12, 4, "False", , , "Delay savings from improvements to other links", , , , null}}
strct = strct + {{"BASecBen" , "Real", 12, 4, "False", , , "Delay savings from improvements to other links", , , , null}}
strct = strct + {{"ProjectLength" , "Real", 12, 2, "False", , , "The approximate length of the project", , , , null}}
strct = strct + {{"ProjBens" , "Real", 12, 4, "False", , , "Total benefits assigned to this project ID", , , , null}}
strct = strct + {{"Score" , "Real", 12, 4, "False", , , "Final score of this project ID|Manually filled in", , , , null}}
ModifyTable(dv_temp, strct)
// Set the values of the new fields
SetDataVector( dv_temp + "|", "ABCapChange", v_ABCapDiff ,)
SetDataVector( dv_temp + "|", "BACapChange", v_BACapDiff ,)
SetDataVector( dv_temp + "|", "ABPctCapChange", v_ABCapPctDiff ,)
SetDataVector( dv_temp + "|", "BAPctCapChange", v_BACapPctDiff ,)
SetDataVector( dv_temp + "|", "ABVolChange", v_ABVolDiff ,)
SetDataVector( dv_temp + "|", "BAVolChange", v_BAVolDiff ,)
SetDataVector( dv_temp + "|", "ABPctVolChange", v_ABVolPctDiff ,)
SetDataVector( dv_temp + "|", "BAPctVolChange", v_BAVolPctDiff ,)
SetDataVector( dv_temp + "|", "ABDelayChange", v_ABDelayDiff ,)
SetDataVector( dv_temp + "|", "BADelayChange", v_BADelayDiff ,)
SetDataVector( dv_temp + "|", "LinkCategory", v_linkCategory ,)
SetDataVector( dv_temp + "|", "ABPrimBen", v_abPrimBen ,)
SetDataVector( dv_temp + "|", "BAPrimBen", v_baPrimBen ,)
SetDataVector( dv_temp + "|", "ABSecBen", v_abSecBen ,)
SetDataVector( dv_temp + "|", "BASecBen", v_baSecBen ,)
/*
Secondary benefit allocation
*/
// Loop over each project ID and determine the length
SetLayer(dv_temp)
for p = 1 to v_projID.length do
projID = v_projID[p]
// Some models use strings for project IDs, others don't. Catch both.
if Args.Benefits.projIDType = "String" then
projQuery = "Select * where " + Args.Benefits.projID + " = '" +
projID + "'"
else projQuery = "Select * where " + Args.Benefits.projID + " = " +
String(projID)
n = SelectByQuery("tempproj","Several",projQuery)
// Get direction and length vectors
v_dir = GetDataVector(dv_temp + "|tempproj","Dir",)
v_lengthTemp = GetDataVector(dv_temp + "|tempproj","Length",)
// Divide length by 2 if direction <> 0 (to avoid double counting length)
v_lengthTemp = if v_dir <> 0 then v_lengthTemp / 2 else v_lengthTemp
// Determine the total project distance and set that value for every
// link with the same project ID in the network
projLength = VectorStatistic(v_lengthTemp,"Sum",)
opts = null
opts.Constant = projLength
v_projLength = Vector(v_lengthTemp.length,"Double",opts)
SetDataVector(dv_temp + "|tempproj","ProjectLength",v_projLength,)
end
DeleteSet("tempproj")
DropLayerFromWorkspace(dv_temp)
// Create a map of the resulting highway layer
{map,nlayer,llayer} = RunMacro("Create Highway Map", Args.Benefits.resultHwy)
SetLayer(llayer)
// Create a distance skim matrix from every node to every node
Opts = null
Opts.Input.[Link Set] = {Args.Benefits.resultHwy + "|" + llayer, llayer}
Opts.Global.[Network Label] = "network"
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.[Network Options].[Time Units] = "Minutes"
Opts.Global.[Link Options].Length = {llayer + ".Length", llayer + ".Length", , , "False"}
Opts.Global.[Length Units] = "Miles"
Opts.Global.[Time Units] = "Minutes"
net_file = Args.Benefits.outputDir + "/network.net"
Opts.Output.[Network File] = net_file
ret = RunMacro("TCB Run Operation", "Build Highway Network", Opts, &Ret)
Opts = null
Opts.Input.Network = net_file
Opts.Input.[Origin Set] = {Args.Benefits.resultHwy + "|" + nlayer, nlayer}
Opts.Input.[Destination Set] = {Args.Benefits.resultHwy + "|" + nlayer, nlayer}
Opts.Input.[Via Set] = {Args.Benefits.resultHwy + "|" + nlayer, nlayer}
Opts.Field.Minimize = "Length"
Opts.Field.Nodes = nlayer + ".ID"
Opts.Flag = {}
Opts.Output.[Output Matrix].Label = "Shortest Path"
Opts.Output.[Output Matrix].Compression = 1
mtx_file = Args.Benefits.outputDir + "distance.mtx"
Opts.Output.[Output Matrix].[File Name] = mtx_file
ret = RunMacro("TCB Run Procedure", "TCSPMAT", Opts, &Ret)
// Open the matrix, create a currency, and convert
// nulls (diagonal) to zeros.
mtx = OpenMatrix(mtx_file, )
{ri, ci} = GetMatrixIndex(mtx)
mtx_cores = GetMatrixCoreNames(mtx)
mtx_cur = CreateMatrixCurrency(mtx, mtx_cores[1], ri, ci, )
mtx_cur := nz(mtx_cur)
// Create two node fields on the line layer to display from/to node IDs
from_node = CreateNodeField(llayer, "from_node", nlayer + ".ID", "From", )
to_node = CreateNodeField(llayer, "to_node", nlayer + ".ID", "To", )
/*
Loop over each project.
Three sets will be used within the loop:
projectSet
Selection of links of the current project
linkSet
Selection of a single link of a project
(while looping over the proj links)
linkBufferSet
Selection of links within the buffer distance around the current proj link
In addition, the linkSet and linkBufferSet also have their nodes selected.
*/
projectSet = RunMacro("G30 create set","current project")
linkSet = RunMacro("G30 create set", "project's link")
linkSet_nodes = RunMacro("G30 create set", "project's link's nodes")
linkBufferSet = RunMacro("G30 create set", "project's link's buffer")
linkBufferSet_nodes = RunMacro(
"G30 create set", "project's link's buffer's nodes"
)
DATA = null
// Loop over each project
CreateProgressBar("Secondary Benefit Allocation", "True")
for p = 1 to v_projID.length do
projID = v_projID[p]
cancel = UpdateProgressBar(
"Processing project number " + String(p) +
" of " + String(v_projID.length),
R2I((p - 1) / v_projID.length * 100)
)
if cancel then do
DestroyProgressBar()
DestroyProgressBar()
Throw("User pressed 'Cancel'")
end
// Select the current project
SetLayer(llayer)
qry = "Select * where " + Args.Benefits.projID + " = " +
(if TypeOf(projID) = "string" then "'" + projID + "'"
else String(projID))
n = SelectByQuery(projectSet, "Several", qry)
if n = 0 then Throw("No project records found")
// Determine buffer distance
v_proj_length = GetDataVector(llayer + "|" + projectSet, "ProjectLength", )
proj_length = v_proj_length[1]
buffer = proj_length
buffer = min(buffer, 10)
// Loop over each link of the current project
v_projLinkID = GetDataVector(llayer + "|" + projectSet, "ID",)
CreateProgressBar("Individual Project Links", "True")
for i = 1 to v_projLinkID.length do
id = v_projLinkID[i]
cancel = UpdateProgressBar(
"Processing link number " + String(i) +
" of " + String(v_projLinkID.length),
R2I((i - 1) / v_projLinkID.length * 100)
)
if cancel then do
DestroyProgressBar()
DestroyProgressBar()
Throw("User pressed 'Cancel'")
end
// Determine the absolute VMT change on the project link
// Use absolute VMT change because changes in either direction
// can induce postive or negative changes on surrounding links.
// For example, a positive VMT change on a project can create
// more delay on surrounding links that are now used to feed
// the project link. A positive VMT change can also cause a
// reduction in delay on a parallel facility that now has less
// traffic.
rh = LocateRecord(llayer + "|", "ID", {id}, )
SetRecord(llayer, rh)
ab_vol_change = llayer.ABVolChange
ba_vol_change = llayer.BAVolChange
length = llayer.Length
vmt_change = abs(ab_vol_change + ba_vol_change) * length
// Select the current link and it's nodes
SetLayer(llayer)
qry = "Select * where ID = " + String(id)
SelectByQuery(linkSet, "Several", qry)
SetLayer(nlayer)
SelectByLinks(linkSet_nodes, "Several", linkSet, )
// Select all links within the buffer distance of the current project
// link and collect their link IDs. Don't include links from the
// current project in the set. Other projects' links can be included.
// They may have secondary benefits (mixed benefit type).
SetLayer(llayer)
opts = null
opts.Inclusion = "Intersecting"
opts.[Source Not] = projectSet
SelectByVicinity(
linkBufferSet, "Several", llayer + "|" + linkSet, buffer, opts
)
// Collect ID information on the buffer links and create a table.
v_bufferLinkIDs = GetDataVector(llayer + "|" + linkBufferSet, "ID", opts)
v_bufferLink_fnode = GetDataVector(
llayer + "|" + linkBufferSet, "from_node", opts
)
v_bufferLink_tnode = GetDataVector(
llayer + "|" + linkBufferSet, "to_node", opts
)
buffer_tbl = null
buffer_tbl.link_id = v_bufferLinkIDs
buffer_tbl.from_node = v_bufferLink_fnode
buffer_tbl.to_node = v_bufferLink_tnode
// Select the buffer link's nodes as well. Allow the current link's
// nodes to be selected, too. Distances used are link-to-link, and
// are calculated by averaging node distances.
SetLayer(nlayer)
SelectByLinks(linkBufferSet_nodes, "Several", linkBufferSet, )
// Create indices for proj link nodes and buffer nodes
// Delete any that already exist
a_ind_names = GetMatrixIndexNames(mtx)
a_ind_names = a_ind_names[1]
if ArrayPosition(a_ind_names, {"proj_link"}, ) <> 0 then
DeleteMatrixIndex(mtx, "proj_link")
link_index = CreateMatrixIndex(
"proj_link", mtx, "Both", nlayer + "|" + linkSet_nodes,
"ID", "ID"
)
if ArrayPosition(a_ind_names, {"buffer_link"}, ) <> 0 then
DeleteMatrixIndex(mtx, "buffer_link")
buffer_index = CreateMatrixIndex(
"buffer_link", mtx, "Both", nlayer + "|" + linkBufferSet_nodes,
"ID", "ID"
)
// Create currencies for each direction of travel (from project link
// and to project link).
from_link_cur = CreateMatrixCurrency(
mtx, mtx_cores[1], link_index, buffer_index,
)
to_link_cur = CreateMatrixCurrency(
mtx, mtx_cores[1], buffer_index, link_index,
)
// Get distance vectors from skim matrix. Collect for both proj nodes
// and in both directions (4 vectors)
SetLayer(llayer)
a_nodes = GetEndpoints(id)
DIST = null
opts = null
opts.Index = "Row"
DIST.buffer_node = GetMatrixVector(to_link_cur, opts)
DIST.buffer_node.rowbased ="True"
for n = 1 to a_nodes.length do
node = a_nodes[n]
opts = null
opts.Row = node
DIST.("from_" + String(node)) = GetMatrixVector(from_link_cur, opts)
DIST.("from_" + String(node)).rowbased = "True"
opts = null
opts.Column = node
DIST.("to_" + String(node)) = GetMatrixVector(to_link_cur, opts)
DIST.("to_" + String(node)).rowbased = "True"
end
DIST.min_to = min(DIST.("to_" + String(a_nodes[1])), DIST.("to_" + String(a_nodes[2])))
DIST.min_from = min(DIST.("from_" + String(a_nodes[1])), DIST.("from_" + String(a_nodes[2])))
DIST.direction = if DIST.min_to < DIST.min_from then "to" else "from"
DIST.min_dist = min(DIST.min_to, DIST.min_from)
DIST.max_dist = if DIST.direction = "to"
then max(DIST.("to_" + String(a_nodes[1])), DIST.("to_" + String(a_nodes[2])))
else max(DIST.("from_" + String(a_nodes[1])), DIST.("from_" + String(a_nodes[2])))
// To check/debug the distance table calculations
if p = 1 and i = 1
then RunMacro(
"Write Table", DIST, Args.Benefits.outputDir +
"/check distance calc - proj 1 link 1.csv"
)
// Join the DIST table to the buffer table twice - once for each node
// on the buffer link
// The average distance is calculated from both buffer link nodes to
// the nearest project node. This removes bias against long project
// links.
DIST = RunMacro("Select", DIST, {"buffer_node", "min_dist"})
buffer_tbl = RunMacro("Join Tables", buffer_tbl, "from_node", DIST, "buffer_node")
buffer_tbl = RunMacro("Rename Field", buffer_tbl, "min_dist", "min_dist1")
buffer_tbl = RunMacro("Join Tables", buffer_tbl, "to_node", DIST, "buffer_node")
buffer_tbl = RunMacro("Rename Field", buffer_tbl, "min_dist", "min_dist2")
buffer_tbl.avg_dist = (buffer_tbl.min_dist1 + buffer_tbl.min_dist2) / 2
// Create a table with the buffer link ids
// and their distances to the project link.
DATA = null
DATA.BufferLinkID = buffer_tbl.link_id
// Collect secondary info and add to table
ABSecBen = GetDataVector(llayer + "|" + linkBufferSet, "ABSecBen", )
BASecBen = GetDataVector(llayer + "|" + linkBufferSet, "BASecBen", )
SecBen = ABSecBen + BASecBen
DATA.SecondaryBenefit = SecBen
// Add other pertinent data
// Add vmt change
opts = null
opts.Constant = projID
type = if TypeOf(projID) = "string" then "string" else "Long"
v_temp = Vector(v_bufferLinkIDs.length, type, opts)
DATA.projID = v_temp
opts.Constant = id
v_temp = Vector(v_bufferLinkIDs.length, "Long", opts)
DATA.projLinkID = v_temp
opts.Constant = vmt_change
v_temp = Vector(v_bufferLinkIDs.length, "Double", opts)
DATA.vmt_change = v_temp
opts.Constant = buffer
v_temp = Vector(v_bufferLinkIDs.length, "Double", opts)
DATA.buffer = v_temp
// Add distance and distance decay info
DATA.dist2link = buffer_tbl.avg_dist
// Set distance floor to .5 miles.
DATA.dist2link = max(DATA.dist2link, .5)
// Use (1/dist)^.5
/*DATA.DistWeight = Pow(1 / max(.5, v_dist), .5)*/
// Use (1 - dist / buffer) ^ 4
DATA.DistWeight = Pow(1 - DATA.dist2link / DATA.buffer, 4)
/* The average distance could be longer than the buffer for two reasons
1. The "touching" inclusion setting in SelectByVicinity
2. The difference between network skim distance and straightline buffer
If the average distance is larger than the buffer, the DistWeight
function starts going positive again. Set it to zero if that happens.
This prevents that link from contributing any secondary benefits at all.
In effect, this trims the buffer links down to only those that can
reach the project link, along the network, within the buffer distance.*/
DATA.DistWeight = if DATA.dist2link > buffer then 0 else DATA.DistWeight
// Build the FINAL table by binding DATA to it
// after each loop
if p = 1 and i = 1 then do
FINAL = DATA
end else do
FINAL = RunMacro("Bind Rows", FINAL, DATA)
end
end
DestroyProgressBar()
end
DestroyProgressBar()
// Use the tables library to vectorize and write out DATA
/*DATA = RunMacro("Vectorize Table", DATA)
RunMacro("Write Table", DATA, Args.Benefits.outputDir + "test.csv")*/
// Use the tables library to apportion benefits
agg = null
agg.vmt_change = {"sum"}
agg.DistWeight = {"sum"}
summary = RunMacro("Summarize", FINAL, {"BufferLinkID"}, agg)
/*summary = RunMacro(
"Select", {"BufferLinkID", "sum_vmt_change", "sum_DistWeight"}
)*/
FINAL = RunMacro("Join Tables", FINAL, "BufferLinkID", summary, "BufferLinkID")
FINAL.pct_vmt = FINAL.vmt_change / FINAL.sum_vmt_change
FINAL.pct_distweight = FINAL.DistWeight / FINAL.sum_DistWeight
FINAL.combined = FINAL.pct_vmt * FINAL.pct_distweight
agg = null
agg.combined = {"sum"}
summary2 = RunMacro("Summarize", FINAL, {"BufferLinkID"}, agg)
/*summary2 = RunMacro("Select", {"BufferLinkID", "sum_combined"})*/
FINAL = RunMacro("Join Tables", FINAL, "BufferLinkID", summary2, "BufferLinkID")
FINAL.pct = FINAL.combined / FINAL.sum_combined
FINAL.final = FINAL.pct * FINAL.SecondaryBenefit
// Write out intermediate table for checking
RunMacro(
"Write Table", FINAL,
Args.Benefits.outputDir + "check secondary benefit assignment.csv"
)
agg = null
agg.final = {"sum"}
secondary_tbl = RunMacro("Summarize", FINAL, {"projID"}, agg)
secondary_tbl = RunMacro(
"Rename Field", secondary_tbl, "sum_final", "secondary_benefits"
)
secondary_tbl.Count = null
/*
--------------------------------------------------------------
Step 3:
Calculate project-level metrics like VMT change and CMA change
--------------------------------------------------------------
*/
// VMT - Vehicle Miles Traveled
// CMA - Capacity Miles Available (metric made up for this application)
// Currently used to calculate utilization
// Util - "Utilization" or how much of the project is being used
// Prime - Primary benefits on the project links
// Change means the difference between build and no-build
v_projVMTDiff = Vector(v_projID.length,"Float",{{"Constant",0}})
v_projCMADiff = Vector(v_projID.length,"Float",{{"Constant",0}})
v_projPrimeBen = Vector(v_projID.length,"Float",{{"Constant",0}})
for i = 1 to v_projID.length do
projID = v_projID[i]
// VMT Change
v_tempVMT = if ( v_allprojid = projID ) then v_length * (v_ABVolDiff + v_BAVolDiff) else 0
vmt = VectorStatistic(v_tempVMT,"Sum",)
// CMA Change
v_tempCMA = if ( v_allprojid = projID ) then v_length * (v_ABCapDiff + v_BACapDiff) else 0
cma = VectorStatistic(v_tempCMA,"Sum",)
v_projVMTDiff[i] = vmt
v_projCMADiff[i] = cma
// Primary Benefits
v_tempBen = if ( v_allprojid = projID ) then (v_abPrimBen + v_baPrimBen) else 0
primeBen = VectorStatistic(v_tempBen,"Sum",)
v_projPrimeBen[i] = primeBen
end
// Utilization
v_projUtil = v_projVMTDiff / v_projCMADiff
// Create a final table object
a_colNames = {"proj_id", "vmt_diff", "cap_diff",
"utilization", "primary_benefits"}
a_data = {v_projID, v_projVMTDiff, v_projCMADiff,
v_projUtil, v_projPrimeBen}
RESULT = RunMacro("Create Table", a_colNames, a_data)
// Join the secondary benefit information to that table
// and calculate total benefits
RESULT = RunMacro("Join Tables", RESULT, "proj_id", secondary_tbl, "projID")
RESULT.total_benefits = RESULT.primary_benefits + RESULT.secondary_benefits
RunMacro(
"Write Table", RESULT,
Args.Benefits.outputDir + "final results.csv"
)
// Show warning if the delay increased from no-build to build
v_totalDelayDiff = v_ABDelayDiff + v_BADelayDiff
if VectorStatistic(v_totalDelayDiff,"sum",) > 0 then do
warningString = "Warning: Total delay increased from no-build " +
"to build scenarios."
ShowMessage(warningString)
end
DestroyProgressBar()
ShowMessage("Done calculating benefits")
quit:
enditem
// Debug Button
button "Debug" 5, 16, 12 Hidden do
ShowMessage(1)
enditem
// Save Settings Button
button "Save Settings" same, after, 12 do
RunMacro("Save Settings")
enditem
// Load Settings Button
button "Load Settings" same, after, 12 do
RunMacro("Load Settings")
RunMacro("Set Benefits Dbox Items")
enditem
// Quit Button
button "Quit" 55, 16, 12 do
Return(0)
enditem
EndDbox
/*
This macro takes an open highway layer (in a map) and a project id.
Exports the project links to a project layer.
Returns a vector describing the distance of every link in the highway layer
from the project layer. Also appends the information to the highway layer
in field "dist_2_proj".
map
String
name of open map
llyr
String
Name of highway link layer
set
String (Optional)
Name of selection of highway links to calc distance to the project
p_id_field
String
Name of the field holding project IDs
proj_id
String or Integer
Project ID to calc distance to
*/
Macro "Distance to Project" (map, llyr, set, p_id_field, proj_id)
SetLayer(llyr)
qry = "Select * where " + p_id_field + " = " +
(if TypeOf(proj_id) = "string" then "'" + proj_id + "'"
else String(proj_id))
n = SelectByQuery("proj", "Several", qry)