-
Notifications
You must be signed in to change notification settings - Fork 28
/
RuntimeConfiguration.py
791 lines (662 loc) · 45.7 KB
/
RuntimeConfiguration.py
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
USAGE = r"""
This script makes some runtime configuration changes in order to try to simplify
changes that need to be made at runtime.
If no iteration is specified, then these include:
* Project Directory
+ Assumed to be the current working directory
+ Propagated to CTRAMP\\runtime\\accessibilities.properties,
CTRAMP\\runtime\\mtcTourBased.properties
* Synthesized households and persons files
+ Assumed to be INPUT\\popsyn\\hhFile.* and INPUT\\popsyn\\personFile.*
+ Propagated to CTRAMP\\runtime\\mtcTourBased.properties
* Auto Operating Costs
+ Specify the values in INPUT\\params.properties
+ It will be propagated to CTRAMP\\scripts\\block\\hwyParam.block,
CTRAMP\\runtime\\accessibilities.properties (new!),
CTRAMP\\runtime\\mtcTourBased.properties (new!)
+ It will be propagated to CTRAMP\\model\\ModeChoice.xls, (for costPerMile)
CTRAMP\\model\\TripModeChoice.xls,
CTRAMP\\model\\accessibility_utility.xls
* Truck Operating Cost
+ Specify the value in INPUT\\params.properties
+ It will be propagated to CTRAMP\\scripts\\block\\hwyParam.block
* Truck Trip Distribution gravity LOS term part from tolled time
+ Specify the value in INPUT\\params.properties
+ It will be propagated to CTRAMP\\scripts\\block\\hwyParam.block
* Telecommute constant
+ It will be propagated to CTRAMP\\model\\CoordinatedDailyActivityPattern.xls
* Means Based Tolling (Q1 and Q2) factors
+ They will be propagated to CTRAMP\\scripts\\block\\hwyParam.block
CTRAMP\\runtime\\mtcTourBased.properties
* Means Based Fare (Q1 and Q2) factors
+ They will be propagated to CTRAMP\\scripts\\block\\trnParam.block
CTRAMP\\runtime\\mtcTourBased.properties
* HSR Interregional trips disable flag
+ It will be propagated to CTRAMP\\scripts\\block\\trnParam.block
* Host IP - where the household manager, matrix manager and JPPF Server run
+ Assumed to be the HOST_IP_ADDRESS in the environment
+ Assumed that this script is running on this host IP (this is verified)
+ It will be propagated to CTRAMP\\runtime\\JavaOnly_runMain.cmd
CTRAMP\\runtime\\JavaOnly_runNode[0-4].cmd
CTRAMP\\runtime\\config\\jppf-clientDistributed.properties
CTRAMP\\runtime\\config\\jppf-clientLocal.properties
CTRAMP\\runtime\\config\\jppf-driver.properties
CTRAMP\\runtime\\config\\jppf-node[0-4].properties
CTRAMP\\runtime\\mtcTourBased.properties
* Distribution
+ Based on hostname.
* 'MODEL2-A', 'MODEL2-C','MODEL2-D','PORMDLPPW01','PORMDLPPW02','Model3-a','Model3-b','Model3-c','Model3-d': single machine setup with
48 Cube Voyager processes available
48 threads for accessibilities
24 threads for core
* 'mainmodel': multiple machine setup
If an iteration is specified, then the following UsualWorkAndSchoolLocationChoice
lines are set in CTRAMP\\runtime\\mtcTourBased.properties:
Iteration 1:
# ShadowPrice.Input.File = (blank)
ShadowPricing.MaximumIterations = 4
Iteration 2:
ShadowPrice.Input.File = main/ShadowPricing_3.csv
ShadowPricing.MaximumIterations = 2
Iteration 3:
ShadowPrice.Input.File = main/ShadowPricing_5.csv
ShadowPricing.MaximumIterations = 2
Iteration n:
ShadowPrice.Input.File = main/ShadowPricing_2n-1.csv
ShadowPricing.MaximumIterations = 2
logsums: same as Iteration 3
"""
import argparse
import collections
import glob
import math
import os
import re
import shutil
import socket
import sys
import pandas
import xlrd
import xlwt
import xlutils.copy
def check_tazdata():
"""
Checks that INPUT\\landuse\\tazData.csv has new required columns, CORDON and CORDONCOST
"""
tazdata_file = os.path.join("INPUT", "landuse", "tazData.csv")
tazdata_df = pandas.read_csv(tazdata_file)
tazdata_cols = list(tazdata_df.columns)
# check if the CORDON and CORDONCOST columns are in tazdata
assert("CORDON" in tazdata_cols)
assert("CORDONCOST" in tazdata_cols)
print("Found columns CORDON and CORDONCOST in tazData.csv")
# check if the tollam_da in tolls.csv is consistent with the CORDONCOST in tazData
# read toll file
toll_file = os.path.join("INPUT", "hwy", "tolls.csv")
toll_df = pandas.read_csv(toll_file)
# the cordon toll class in tolls.csv
cordon_toll = list(set(toll_df.loc[(toll_df.tolltype == 'cordon')]['tollclass']))
if cordon_toll == []:
print("No cordons found in tollclasses")
return
for i in cordon_toll:
tollam_da = float(toll_df.loc[(toll_df.tollclass == i)]['tollam_da'])
try:
CORDONCOST = float(tazdata_df.loc[tazdata_df.CORDON == i].groupby('CORDON').agg({'CORDONCOST':'mean'})['CORDONCOST'])/100
except:
CORDONCOST = None # Handle errors occur when some tollclass from tolls.csv don't exist in tazData.csv
if tollam_da != CORDONCOST:
print("ERROR: tollclass "+ str(i)+" from toll.csv tollam_da DOESN'T match with tazData.csv CORDONCOST")
assert tollam_da == CORDONCOST, "ERROR: tollclass "+ str(i)+" from toll.csv tollam_da DOESN'T matches with tazData.csv CORDONCOST"
else:
print("tollclass "+ str(i)+" from toll.csv tollam_da matches with tazData.csv CORDONCOST")
def replace_in_file(filepath, regex_dict):
"""
Copies `filepath` to `filepath.original`
Opens `filepath.original` and reads it, writing a new version to `filepath`.
The new version is the same as the old, except that the regexes in the regex_dict keys
are replaced by the corresponding values.
"""
shutil.move(filepath, "%s.original" % filepath)
print("Updating {}".format(filepath))
# read the contents
myfile = open("%s.original" % filepath, 'r')
file_contents = myfile.read()
myfile.close()
# do the regex subs
for pattern,newstr in regex_dict.items():
(file_contents, numsubs) = re.subn(pattern,newstr,file_contents,flags=re.IGNORECASE)
print(" Made {} sub for {}".format(numsubs, newstr))
# Fail on failure
if numsubs < 1:
print(" SUBSITUTION NOT MADE -- Fatal error")
print(" pattern = [{}]".format(pattern))
sys.exit(2)
# write the result
myfile = open(filepath, 'w')
myfile.write(file_contents)
myfile.close()
def append_to_file(filepath, append_str):
"""
Copies `filepath` to `filepath.original`
Opens `filepath.original` and reads it, writing a new version to `filepath`.
The new version is the same as the old, with the lines in append_dict added
"""
shutil.move(filepath, "%s.original" % filepath)
print("Updating {}".format(filepath))
# read the contents
myfile = open("%s.original" % filepath, 'r')
file_contents = myfile.read()
myfile.close()
# write the result
myfile = open(filepath, 'w')
myfile.write(file_contents)
myfile.write(append_str)
myfile.close()
def config_project_dir(for_logsums, replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
project_dir = os.getcwd()
project_dir = project_dir.replace("\\","/") # we want backwards slashes
project_dir = project_dir + "/" # trailing backwards slash
filepath = os.path.join("CTRAMP","runtime","accessibilities.properties")
replacements[filepath] = collections.OrderedDict()
# Simple regex: . = any character not a newline
# \S = non-whitespace character
replacements[filepath]["(\nProject.Directory[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % project_dir
filepath = os.path.join("CTRAMP","runtime","mtcTourBased.properties")
if for_logsums:
filepath = os.path.join("CTRAMP","runtime","logsums.properties")
replacements[filepath]["(\nProject.Directory[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % project_dir
def config_popsyn_files(replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
hhfiles = glob.glob( os.path.join("INPUT", "popsyn", "hhFile.*") )
# there should be only one
assert(len(hhfiles) == 1)
hhfile = hhfiles[0]
hhfile = hhfile.replace("\\","/") # we want backwards slashes
hhfile = hhfile.replace("INPUT/","") # strip input
perfiles = glob.glob( os.path.join("INPUT", "popsyn", "personFile.*") )
assert(len(perfiles) == 1)
perfile = perfiles[0]
perfile = perfile.replace("\\","/") # we want backwards slashes
perfile = perfile.replace("INPUT/", "") # strip input
filepath = os.path.join("CTRAMP","runtime","mtcTourBased.properties")
replacements[filepath]["(\nPopulationSynthesizer.InputToCTRAMP.HouseholdFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % hhfile
replacements[filepath]["(\nPopulationSynthesizer.InputToCTRAMP.PersonFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % perfile
def config_mobility_params(params_filename, params_contents, for_logsums, replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
# get parameters - see examples in congig directory
modelYear = int(os.environ["MODEL_YEAR"])
BikeInfra_CIVT_Mult = float(get_property(params_filename, params_contents, "Bike_Infra_C_IVT_Multiplier"))
WorkTransitHesitance = float(get_property(params_filename, params_contents, "Work_Transit_Hesitance"))
NonWorkTransitHesitance = float(get_property(params_filename, params_contents, "NonWork_Transit_Hesitance"))
BARTTransitHesitance = float(get_property(params_filename, params_contents, "BART_Transit_Hesitance"))
MeansBasedTollsQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Tolling_Q1Factor"))
MeansBasedTollsQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Tolling_Q2Factor"))
MeansBasedFareQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Fare_Q1Factor"))
MeansBasedFareQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Fare_Q2Factor"))
# cordon
MeansBasedCordonTollsQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Tolling_Q1Factor"))
MeansBasedCordonTollsQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Tolling_Q2Factor"))
MeansBasedCordonFareQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Fare_Q1Factor"))
MeansBasedCordonFareQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Fare_Q2Factor"))
# WFH factors
WFHFullTimeWorkerFactor = float(get_property(params_filename, params_contents, "WFH_FullTimeWorker_Factor"))
WFHPartTimeWorkerFactor = float(get_property(params_filename, params_contents, "WFH_PartTimeWorker_Factor"))
Adjust_TNCsingle_TourMode = float(get_property(params_filename, params_contents, "Adjust_TNCsingle_TourMode"))
Adjust_TNCshared_TourMode = float(get_property(params_filename, params_contents, "Adjust_TNCshared_TourMode"))
Adjust_TNCsingle_TripMode = float(get_property(params_filename, params_contents, "Adjust_TNCsingle_TripMode"))
Adjust_TNCshared_TripMode = float(get_property(params_filename, params_contents, "Adjust_TNCshared_TripMode"))
avShare = float(get_property(params_filename, params_contents, "Mobility.AV.Share"))
pBoostAutosLTDrivers = float(get_property(params_filename, params_contents, "Mobility.AV.ProbabilityBoost.AutosLTDrivers"))
pBoostAutosGEDrivers = float(get_property(params_filename, params_contents, "Mobility.AV.ProbabilityBoost.AutosGEDrivers"))
avIVTFactor = float(get_property(params_filename, params_contents, "Mobility.AV.IVTFactor"))
avparkCostFactor = float(get_property(params_filename, params_contents, "Mobility.AV.ParkingCostFactor"))
avCPMFactor = float(get_property(params_filename, params_contents, "Mobility.AV.CostPerMileFactor"))
avTermTimeFactor = float(get_property(params_filename, params_contents, "Mobility.AV.TerminalTimeFactor"))
tncIVTFactor = float(get_property(params_filename, params_contents, "Mobility.TNC.shared.IVTFactor"))
taxiBaseFare = float(get_property(params_filename, params_contents, "taxi.baseFare"))
taxiCPMile = float(get_property(params_filename, params_contents, "taxi.costPerMile"))
taxiCPMin = float(get_property(params_filename, params_contents, "taxi.costPerMinute"))
tncSingleBaseFare = float(get_property(params_filename, params_contents, "TNC.single.baseFare"))
tncSingleCPMile = float(get_property(params_filename, params_contents, "TNC.single.costPerMile"))
tncSingleCPMin = float(get_property(params_filename, params_contents, "TNC.single.costPerMinute"))
tncSingleMinCost = float(get_property(params_filename, params_contents, "TNC.single.costMinimum"))
tncSharedBaseFare = float(get_property(params_filename, params_contents, "TNC.shared.baseFare"))
tncSharedCPMile = float(get_property(params_filename, params_contents, "TNC.shared.costPerMile"))
tncSharedCPMin = float(get_property(params_filename, params_contents, "TNC.shared.costPerMinute"))
tncSharedMinCost = float(get_property(params_filename, params_contents, "TNC.shared.costMinimum"))
tncSingleMeanWaitTime = get_property(params_filename, params_contents, "TNC.single.waitTime.mean")
tncSingleSDWaitTime = get_property(params_filename, params_contents, "TNC.single.waitTime.sd")
tncSharedMeanWaitTime = get_property(params_filename, params_contents, "TNC.shared.waitTime.mean")
tncSharedSDWaitTime = get_property(params_filename, params_contents, "TNC.shared.waitTime.sd")
taxiMeanWaitTime = get_property(params_filename, params_contents, "Taxi.waitTime.mean")
taxiSDWaitTime = get_property(params_filename, params_contents, "Taxi.waitTime.sd")
taxiDaShare = float(get_property(params_filename, params_contents, "Taxi.da.share"))
taxiS2Share = float(get_property(params_filename, params_contents, "Taxi.s2.share"))
taxiS3Share = float(get_property(params_filename, params_contents, "Taxi.s3.share"))
tncSingleDaShare = float(get_property(params_filename, params_contents, "TNC.single.da.share"))
tncSingleS2Share = float(get_property(params_filename, params_contents, "TNC.single.s2.share"))
tncSingleS3Share = float(get_property(params_filename, params_contents, "TNC.single.s3.share"))
tncSharedDaShare = float(get_property(params_filename, params_contents, "TNC.shared.da.share"))
tncSharedS2Share = float(get_property(params_filename, params_contents, "TNC.shared.s2.share"))
tncSharedS3Share = float(get_property(params_filename, params_contents, "TNC.shared.s3.share"))
# Pass the data to mtcTourBased.properties or logsums.properties
filepath = os.path.join("CTRAMP","runtime","mtcTourBased.properties")
if for_logsums:
filepath = os.path.join("CTRAMP","runtime","logsums.properties")
replacements[filepath]["(\nModel_Year[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%d" % modelYear
replacements[filepath]["(\nBike_Infra_C_IVT_Multiplier[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % BikeInfra_CIVT_Mult
replacements[filepath]["(\nWork_Transit_Hesitance[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % WorkTransitHesitance
replacements[filepath]["(\nNonWork_Transit_Hesitance[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % NonWorkTransitHesitance
replacements[filepath]["(\nBART_Transit_Hesitance[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % BARTTransitHesitance
replacements[filepath]["(\nMeans_Based_Tolling_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedTollsQ1Factor
replacements[filepath]["(\nMeans_Based_Tolling_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedTollsQ2Factor
replacements[filepath]["(\nMeans_Based_Fare_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedFareQ1Factor
replacements[filepath]["(\nMeans_Based_Fare_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedFareQ2Factor
replacements[filepath]["(\nMeans_Based_Cordon_Tolling_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonTollsQ1Factor
replacements[filepath]["(\nMeans_Based_Cordon_Tolling_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonTollsQ2Factor
replacements[filepath]["(\nMeans_Based_Cordon_Fare_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonFareQ1Factor
replacements[filepath]["(\nMeans_Based_Cordon_Fare_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonFareQ2Factor
# WFH factors
replacements[filepath]["(\nCDAP.WFH.FullTimeWorker.Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % WFHFullTimeWorkerFactor
replacements[filepath]["(\nCDAP.WFH.PartTimeworker.Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % WFHPartTimeWorkerFactor
replacements[filepath]["(\nAdjust_TNCsingle_TourMode[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % Adjust_TNCsingle_TourMode
replacements[filepath]["(\nAdjust_TNCshared_TourMode[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % Adjust_TNCshared_TourMode
replacements[filepath]["(\nAdjust_TNCsingle_TripMode[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % Adjust_TNCsingle_TripMode
replacements[filepath]["(\nAdjust_TNCshared_TripMode[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % Adjust_TNCshared_TripMode
replacements[filepath]["(\nMobility.AV.Share[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % avShare
replacements[filepath]["(\nMobility.AV.ProbabilityBoost.AutosLTDrivers[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % pBoostAutosLTDrivers
replacements[filepath]["(\nMobility.AV.ProbabilityBoost.AutosGEDrivers[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % pBoostAutosGEDrivers
replacements[filepath]["(\nMobility.AV.IVTFactor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % avIVTFactor
replacements[filepath]["(\nMobility.AV.ParkingCostFactor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % avparkCostFactor
replacements[filepath]["(\nMobility.AV.CostPerMileFactor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % avCPMFactor
replacements[filepath]["(\nMobility.AV.TerminalTimeFactor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % avTermTimeFactor
replacements[filepath]["(\nMobility.TNC.shared.IVTFactor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncIVTFactor
replacements[filepath]["(\ntaxi.baseFare[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % taxiBaseFare
replacements[filepath]["(\ntaxi.costPerMile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % taxiCPMile
replacements[filepath]["(\ntaxi.costPerMinute[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % taxiCPMin
replacements[filepath]["(\nTNC.single.baseFare[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSingleBaseFare
replacements[filepath]["(\nTNC.single.costPerMile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSingleCPMile
replacements[filepath]["(\nTNC.single.costPerMinute[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSingleCPMin
replacements[filepath]["(\nTNC.single.costMinimum[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSingleMinCost
replacements[filepath]["(\nTNC.shared.baseFare[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSharedBaseFare
replacements[filepath]["(\nTNC.shared.costPerMile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSharedCPMile
replacements[filepath]["(\nTNC.shared.costPerMinute[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSharedCPMin
replacements[filepath]["(\nTNC.shared.costMinimum[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % tncSharedMinCost
replacements[filepath]["(\nTNC.single.waitTime.mean[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % tncSingleMeanWaitTime
replacements[filepath]["(\nTNC.single.waitTime.sd[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % tncSingleSDWaitTime
replacements[filepath]["(\nTNC.shared.waitTime.mean[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % tncSharedMeanWaitTime
replacements[filepath]["(\nTNC.shared.waitTime.sd[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % tncSharedSDWaitTime
replacements[filepath]["(\nTaxi.waitTime.mean[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % taxiMeanWaitTime
replacements[filepath]["(\nTaxi.waitTime.sd[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % taxiSDWaitTime
occ_file = open("taxi_tnc_occ_factors.csv", "w")
occ_file.write('1,%5.2f,%5.2f,%5.2f\n' % (taxiDaShare,tncSingleDaShare,tncSharedDaShare))
occ_file.write('2,%5.2f,%5.2f,%5.2f\n' % (taxiS2Share,tncSingleS2Share,tncSharedS2Share))
occ_file.write('3,%5.2f,%5.2f,%5.2f\n' % (taxiS3Share,tncSingleS3Share,tncSharedS3Share))
occ_file.close()
def get_property(properties_file_name, properties_file_contents, propname):
"""
Return the string for this property.
Exit if not found.
"""
match = re.search("\n%s[ \t]*=[ \t]*(\S*)[ \t]*" % propname, properties_file_contents)
if match == None:
print("Couldn't find {} in {}".format(propname, properties_file_name))
sys.exit(2)
return match.group(1)
def config_auto_opcost(params_filename, params_contents, for_logsums, replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
# find the auto operating cost
auto_opc = float(get_property(params_filename, params_contents, "AutoOpCost"))
# put them into the CTRAMP\scripts\block\hwyParam.block
filepath = os.path.join("CTRAMP","scripts","block","hwyParam.block")
replacements[filepath]["(\nAUTOOPC[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % auto_opc
filepath = os.path.join("CTRAMP","runtime","accessibilities.properties")
replacements[filepath]["(\nAuto.Operating.Cost[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % auto_opc
filepath = os.path.join("CTRAMP","runtime","mtcTourBased.properties")
if for_logsums:
filepath = os.path.join("CTRAMP","runtime","logsums.properties")
replacements[filepath]["(\nAuto.Operating.Cost[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % auto_opc
# put it into the UECs
config_uec("%.2f" % auto_opc)
# small truck
filepath = os.path.join("CTRAMP","scripts","block","hwyParam.block")
smtr_opc = get_property(params_filename, params_contents, "SmTruckOpCost")
replacements[filepath]["(\nSMTROPC[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % smtr_opc
# large truck
lrtr_opc = get_property(params_filename, params_contents, "LrTruckOpCost")
replacements[filepath]["(\nLRTROPC[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % lrtr_opc
# bus
bus_opc = get_property(params_filename, params_contents, "BusOpCost")
replacements[filepath]["(\nBUSOPC[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % bus_opc
# TruckTripDistribution gravity LOS term - tolled time part
truck_distrib_LOS_toll_part = get_property(params_filename, params_contents, "TRUCK_DISTRIB_LOS_TOLL_PART")
replacements[filepath]["(\nTRUCK_DISTRIB_LOS_TOLL_PART[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % truck_distrib_LOS_toll_part
# AV impacts on road capacity - represented by adjusting passenger car equivalents (PCEs) by facility type
av_pcefac_ft01 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT01"))
av_pcefac_ft02 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT02"))
av_pcefac_ft03 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT03"))
av_pcefac_ft04 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT04"))
av_pcefac_ft05 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT05"))
av_pcefac_ft06 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT06"))
av_pcefac_ft07 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT07"))
av_pcefac_ft08 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT08"))
av_pcefac_ft09 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT09"))
av_pcefac_ft10 = float(get_property(params_filename, params_contents, "AV_PCE_FAC_FT10"))
OwnedAV_zpv = float(get_property(params_filename, params_contents, "OwnedAV_ZPV_fac"))
TNC_zpv = float(get_property(params_filename, params_contents, "TNC_ZPV_fac"))
MeansBasedTollsQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Tolling_Q1Factor"))
MeansBasedTollsQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Tolling_Q2Factor"))
MeansBasedCordonTollsQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Tolling_Q1Factor"))
MeansBasedCordonTollsQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Tolling_Q2Factor"))
MeansBasedFareQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Fare_Q1Factor"))
MeansBasedFareQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Fare_Q2Factor"))
MeansBasedCordonFareQ1Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Fare_Q1Factor"))
MeansBasedCordonFareQ2Factor = float(get_property(params_filename, params_contents, "Means_Based_Cordon_Fare_Q2Factor"))
HSRInterregionalDisable = int(get_property(params_filename, params_contents, "HSR_Interregional_Disable"))
# put the av pce factors into the CTRAMP\scripts\block\hwyParam.block
filepath = os.path.join("CTRAMP","scripts","block","hwyParam.block")
replacements[filepath]["(\nAV_PCE_FT01[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft01
replacements[filepath]["(\nAV_PCE_FT02[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft02
replacements[filepath]["(\nAV_PCE_FT03[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft03
replacements[filepath]["(\nAV_PCE_FT04[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft04
replacements[filepath]["(\nAV_PCE_FT05[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft05
replacements[filepath]["(\nAV_PCE_FT06[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft06
replacements[filepath]["(\nAV_PCE_FT07[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft07
replacements[filepath]["(\nAV_PCE_FT08[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft08
replacements[filepath]["(\nAV_PCE_FT09[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft09
replacements[filepath]["(\nAV_PCE_FT10[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % av_pcefac_ft10
replacements[filepath]["(\nOwnedAV_ZPV_factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % OwnedAV_zpv
replacements[filepath]["(\nTNC_ZPV_factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % TNC_zpv
replacements[filepath]["(\nMeans_Based_Tolling_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedTollsQ1Factor
replacements[filepath]["(\nMeans_Based_Tolling_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedTollsQ2Factor
replacements[filepath]["(\nMeans_Based_Cordon_Tolling_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonTollsQ1Factor
replacements[filepath]["(\nMeans_Based_Cordon_Tolling_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonTollsQ2Factor
# put the means based fare discount factors into CTRAMP\scripts\block\trnParam.block
filepath = os.path.join("CTRAMP","scripts","block","trnParam.block")
replacements[filepath]["(\nMeans_Based_Fare_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedFareQ1Factor
replacements[filepath]["(\nMeans_Based_Fare_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedFareQ2Factor
replacements[filepath]["(\nMeans_Based_Cordon_Fare_Q1Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonFareQ1Factor
replacements[filepath]["(\nMeans_Based_Cordon_Fare_Q2Factor[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%.2f" % MeansBasedCordonFareQ2Factor
replacements[filepath]["(\nHSR_Interregional_Disable[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%d" % HSRInterregionalDisable
def config_logsums(replacements, append):
filepath = os.path.join("CTRAMP","runtime","logsums.properties")
# households and persons
replacements[filepath]["(\nPopulationSynthesizer.InputToCTRAMP.HouseholdFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % "logsums/accessibilities_dummy_households.csv"
replacements[filepath]["(\nPopulationSynthesizer.InputToCTRAMP.PersonFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % "logsums/accessibilities_dummy_persons.csv"
# turn off some submodels
replacements[filepath]["(\nRunModel.AutoOwnership[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.FreeParking[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.CoordinatedDailyActivityPattern[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.IndividualMandatoryTourFrequency[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.MandatoryTourDepartureTimeAndDuration[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.MandatoryTourModeChoice[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.JointTourFrequency[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.JointTourLocationChoice[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.JointTourDepartureTimeAndDuration[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.JointTourModeChoice[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.IndividualNonMandatoryTourFrequency[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.IndividualNonMandatoryTourDepartureTimeAndDuration[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.IndividualNonMandatoryTourModeChoice[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.AtWorkSubTourFrequency[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.AtWorkSubTourDepartureTimeAndDuration[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.AtWorkSubTourModeChoice[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.StopFrequency[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
replacements[filepath]["(\nRunModel.StopLocation[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
# sample size
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.SampleOfAlternatives.SampleSize[ \t]*=[ \t]*)(\S*)"] = r"\g<1>4362"
replacements[filepath]["(\nJointTourLocationChoice.SampleOfAlternatives.SampleSize[ \t]*=[ \t]*)(\S*)"] = r"\g<1>30"
replacements[filepath]["(\nIndividualNonMandatoryTourLocationChoice.SampleOfAlternatives.SampleSize[ \t]*=[ \t]*)(\S*)"] = r"\g<1>4362"
replacements[filepath]["(\nAtWorkSubtourLocationChoice.SampleOfAlternatives.SampleSize[ \t]*=[ \t]*)(\S*)"] = r"\g<1>30"
# use logsums from base run
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.ShadowPrice.Input.File[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/ShadowPricing_7.csv"
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.ShadowPricing.MaximumIterations[ \t]*=[ \t]*)(\S*)"] = r"\g<1>1"
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.ShadowPricing.OutputFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/ShadowPricing.csv"
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.SizeTerms.OutputFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/DestinationChoiceSizeTerms.csv"
replacements[filepath]["(\nResults.HouseholdDataFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/householdData.csv"
replacements[filepath]["(\nResults.PersonDataFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/personData.csv"
replacements[filepath]["(\nResults.IndivTourDataFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/indivTourData.csv"
replacements[filepath]["(\nResults.JointTourDataFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/jointTourData.csv"
replacements[filepath]["(\nResults.IndivTripDataFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/indivTripData.csv"
replacements[filepath]["(\nResults.JointTripDataFile[ \t]*=[ \t]*)(\S*)"] = r"\g<1>logsums/jointTripData.csv"
replacements[filepath]["(\nResults.WriteDataToDatabase[ \t]*=[ \t]*)(\S*)"] = r"\g<1>false"
append[filepath] = "\n#-- Logsum input files for recreating skipped model choices\n" + \
"Accessibilities.HouseholdDataFile = logsums/accessibilities_dummy_model_households.csv\n" + \
"Accessibilities.PersonDataFile = logsums/accessibilities_dummy_model_persons.csv\n" + \
"Accessibilities.IndivTourDataFile = logsums/accessibilities_dummy_indivTours.csv\n"
def config_host_ip(for_logsums, replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
host_ip_address = os.environ['HOST_IP_ADDRESS']
# verify that the host IP address relevant to this machine
ips_here = socket.gethostbyname_ex(socket.gethostname())[-1]
if host_ip_address not in ips_here:
print("FATAL: HOST_IP_ADDRESS {} does not match the IP addresses for this machine {}".format(host_ip_address, str(ips_here)))
sys.exit(2)
# CTRAMP\runtime\JavaOnly_runMain.cmd and CTRAMP\runtime\JavaOnly_runNode*.cmd
filenames = ["JavaOnly_runMain.cmd"]
for nodenum in range(5): filenames.append("JavaOnly_runNode%d.cmd" % nodenum)
for filename in filenames:
filepath = os.path.join("CTRAMP","runtime",filename)
replacements[filepath]["(\nset HOST_IP=)(\S*)"] = r"\g<1>%s" % host_ip_address
# driver number
last_number = host_ip_address.split(".")[-1]
driver = 'driver%s' % last_number
for filename in ['jppf-clientDistributed.properties','jppf-clientLocal.properties']:
filepath = os.path.join("CTRAMP","runtime","config",filename)
replacements[filepath]["(\njppf.drivers[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % driver
replacements[filepath]["(\n)(driver[0-9]+\.)"] = r"\g<1>%s." % driver
# server host
filenames = ['jppf-clientDistributed.properties',
'jppf-clientLocal.properties',
'jppf-driver.properties']
for nodenum in range(5): filenames.append("jppf-node%d.properties" % nodenum)
for filename in filenames:
filepath = os.path.join("CTRAMP","runtime","config",filename)
replacements[filepath]["(jppf.server.host[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % host_ip_address
# management host
filepath = os.path.join("CTRAMP","runtime","config",'jppf-clientDistributed.properties')
replacements[filepath]["(jppf.management.host[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % host_ip_address
# put it into mtcTourBased.properties or logsums.properties
if for_logsums:
# do for logsums.properties
filepath = os.path.join("CTRAMP","runtime","logsums.properties")
replacements[filepath]["(\nRunModel.HouseholdServerAddress[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % host_ip_address
replacements[filepath]["(\nRunModel.MatrixServerAddress[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % host_ip_address
else:
filepath = os.path.join("CTRAMP","runtime","mtcTourBased.properties")
replacements[filepath]["(\nRunModel.HouseholdServerAddress[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % host_ip_address
replacements[filepath]["(\nRunModel.MatrixServerAddress[ \t]*=[ \t]*)(\S*)"] = r"\g<1>%s" % host_ip_address
def config_distribution(replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
hostname = socket.gethostname()
if hostname in ['mainmodel','satmodel2','lzorn-vm']:
# accessibilities
filepath = os.path.join("CTRAMP","runtime","accessibilities.properties")
replacements[filepath]["(\nnum.acc.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>14"
# CORE
filenames = []
for nodenum in range(5): filenames.append("jppf-node%d.properties" % nodenum)
for filename in filenames:
filepath = os.path.join("CTRAMP","runtime","config",filename)
replacements[filepath]["(\nprocessing.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>12"
# hwyassign
print("Copying HwyIntraStep_64.block to HwyIntraStep.block")
shutil.copy2(os.path.join("CTRAMP","scripts","block","HwyIntraStep_64.block"),
os.path.join("CTRAMP","scripts","block","HwyIntraStep.block"))
elif hostname in ['MODEL2-A','MODEL2-B','MODEL2-C','MODEL2-D','PORMDLPPW01','PORMDLPPW02','Model3-a','Model3-b','model3-c','model3-d'] or hostname.startswith("WIN-"):
# accessibilities: 48 logical processors
filepath = os.path.join("CTRAMP","runtime","accessibilities.properties")
replacements[filepath]["(\nnum.acc.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>48"
# CORE: use half for JPPF nodes - 48 didn't seem to take
filenames = []
for nodenum in range(5): filenames.append("jppf-node%d.properties" % nodenum)
for filename in filenames:
filepath = os.path.join("CTRAMP","runtime","config",filename)
replacements[filepath]["(\nprocessing.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>24"
# hwyassign
print("Copying HwyIntraStep_48.block to HwyIntraStep.block")
shutil.copy2(os.path.join("CTRAMP","scripts","block","HwyIntraStep_48.block"),
os.path.join("CTRAMP","scripts","block","HwyIntraStep.block"))
else:
raise Exception("RuntimeConfiguration.py does not recognize hostname [%s] for distribution configuration" % hostname)
# def config_distribution(replacements):
# """
# See USAGE for details.
# Replacements = { filepath -> regex_dict }
# """
# hostname = socket.gethostname()
# if hostname == 'mainmodel':
# # accessibilities
# filepath = os.path.join("CTRAMP","runtime","accessibilities.properties")
# replacements[filepath]["(\nnum.acc.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>14"
# # CORE
# filenames = []
# for nodenum in range(5): filenames.append("jppf-node%d.properties" % nodenum)
# for filename in filenames:
# filepath = os.path.join("CTRAMP","runtime","config",filename)
# replacements[filepath]["(\nprocessing.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>12"
# # hwyassign
# print("Copying HwyIntraStep_64.block to HwyIntraStep.block")
# shutil.copy2(os.path.join("CTRAMP","scripts","block","HwyIntraStep_64.block"),
# os.path.join("CTRAMP","scripts","block","HwyIntraStep.block"))
# elif hostname in ['MODEL2-A','MODEL2-B','MODEL2-C','MODEL2-D','PORMDLPPW01','PORMDLPPW02','Model3-a'] or hostname.startswith("WIN-"):
# # accessibilities: 48 logical processors
# filepath = os.path.join("CTRAMP","runtime","accessibilities.properties")
# replacements[filepath]["(\nnum.acc.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>48"
# # CORE: use half for JPPF nodes - 48 didn't seem to take
# filenames = []
# for nodenum in range(5): filenames.append("jppf-node%d.properties" % nodenum)
# for filename in filenames:
# filepath = os.path.join("CTRAMP","runtime","config",filename)
# replacements[filepath]["(\nprocessing.threads[ \t]*=[ \t]*)(\S*)"] = r"\g<1>24"
# # hwyassign
# print("Copying HwyIntraStep_48.block to HwyIntraStep.block")
# shutil.copy2(os.path.join("CTRAMP","scripts","block","HwyIntraStep_48.block"),
# os.path.join("CTRAMP","scripts","block","HwyIntraStep.block"))
# else:
raise Exception("RuntimeConfiguration.py does not recognize hostname [%s] for distribution configuration" % hostname)
def config_shadowprice(iter, replacements):
"""
See USAGE for details.
Replacements = { filepath -> regex_dict }
"""
filepath = os.path.join("CTRAMP","runtime","mtcTourBased.properties")
if iter==1:
# 4 iterations, no input file -- comment it out
replacements[filepath]["(\n)(#?)(UsualWorkAndSchoolLocationChoice.ShadowPrice.Input.File[ \t]*=[ \t]*)(\S*)"] = \
r"\g<1>#\g<3>\g<4>"
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.ShadowPricing.MaximumIterations[ \t]*=[ \t]*)(\S*)"] = \
r"\g<1>4"
elif iter==2:
# update to 2 iterations and add input file
replacements[filepath]["(\n)(#?)(UsualWorkAndSchoolLocationChoice.ShadowPrice.Input.File[ \t]*=[ \t]*)(\S*)"] = \
r"\g<1>\g<3>main/ShadowPricing_3.csv"
replacements[filepath]["(\nUsualWorkAndSchoolLocationChoice.ShadowPricing.MaximumIterations[ \t]*=[ \t]*)(\S*)"] = \
r"\g<1>2"
else:
# update input file
replacements[filepath]["(\n)(#?)(UsualWorkAndSchoolLocationChoice.ShadowPrice.Input.File[ \t]*=[ \t]*)(\S*)"] = \
r"\g<1>\g<3>main/ShadowPricing_%d.csv" % (2*iter-1)
def config_uec(auto_operating_cost):
auto_op_cost_float = float(auto_operating_cost)
for bookname in ["ModeChoice.xls","TripModeChoice.xls","accessibility_utility.xls"]:
filepath = os.path.join("CTRAMP","model",bookname)
shutil.move(filepath, "%s.original" % filepath)
print("Updating {}".format(filepath))
rb = xlrd.open_workbook("%s.original" % filepath, formatting_info=True, on_demand=True)
wb = xlutils.copy.copy(rb)
for sheet_num in range(rb.nsheets):
rs = rb.get_sheet(sheet_num)
for rownum in range(rs.nrows):
# print(rs.cell(rownum,1))
if rs.cell(rownum,1).value=='costPerMile':
print(" Sheet '{}': replacing costPerMile '{}' -> {:.2f}".format(
rs.name, rs.cell(rownum,4).value, auto_op_cost_float))
wb.get_sheet(sheet_num).write(rownum,4,auto_op_cost_float,
xlwt.easyxf("align: horiz left"))
# print(rs.cell(rownum,1))
wb.save(filepath)
def config_freeparking(params_filename, params_contents):
"""
Transfer Free_Parking_Eligibility_OnOff to FreeParkingEligibility UECs
"""
# read the telecommute constant from the properties file
Free_Parking_Eligibility_OnOff = float(get_property(params_filename, params_contents, "Free_Parking_Eligibility_OnOff"))
for bookname in ["FreeParkingEligibility.xls"]:
filepath = os.path.join("CTRAMP","model",bookname)
shutil.move(filepath, "%s.original" % filepath)
print("Updating {}".format(filepath))
rb = xlrd.open_workbook("%s.original" % filepath, formatting_info=True, on_demand=True)
wb = xlutils.copy.copy(rb)
for sheet_num in range(rb.nsheets):
rs = rb.get_sheet(sheet_num)
for rownum in range(rs.nrows):
# print(rs.cell(rownum,1))
if rs.cell(rownum,2).value=='Free parking eligibility OnOff dummy':
print(" Sheet '{}': replacing Free parking eligibility OnOff dummy '{}' -> {:.4f}".format(
rs.name, rs.cell(rownum,6).value, Free_Parking_Eligibility_OnOff))
wb.get_sheet(sheet_num).write(rownum,6, Free_Parking_Eligibility_OnOff, xlwt.easyxf("align: horiz right"))
wb.save(filepath)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = USAGE,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--iter",
help="Iteration for which to configure. If not specified, will configure for pre-run.",
type=int, choices=[1,2,3,4,5])
parser.add_argument("--logsums", help="Configure for logsums.", action='store_true')
my_args = parser.parse_args()
# read INPUT\params.properties
params_filename = os.path.join("INPUT", "params.properties")
myfile = open( params_filename, 'r' )
params_contents = myfile.read()
myfile.close()
print("Read {} lines from {}".format(len(params_contents), params_filename))
# Figure out the replacements we need to make
replacements = collections.defaultdict(collections.OrderedDict)
append = collections.defaultdict(collections.OrderedDict)
if my_args.logsums:
# reconfigure host ip places so logsums doesn't nec need to be run on same machine as model core
config_host_ip(True, replacements)
config_project_dir(True, replacements)
# copy properties file to logsums file
shutil.copyfile(os.path.join("CTRAMP","runtime","mtcTourBased.properties"),
os.path.join("CTRAMP","runtime","logsums.properties"))
config_logsums(replacements, append)
config_mobility_params(params_filename, params_contents, True, replacements)
config_auto_opcost(params_filename, params_contents, True, replacements)
elif my_args.iter == None:
check_tazdata()
config_project_dir(False, replacements)
config_popsyn_files(replacements)
config_mobility_params(params_filename, params_contents, False, replacements)
config_auto_opcost(params_filename, params_contents, False, replacements)
config_host_ip(False, replacements)
config_distribution(replacements)
config_freeparking(params_filename, params_contents)
else:
config_shadowprice(my_args.iter, replacements)
# Go ahead and make the replacements
for filepath,regex_dict in replacements.items():
replace_in_file(filepath, regex_dict)
# append
for filepath,append_str in append.items():
append_to_file(filepath, append_str)