Skip to content

Commit

Permalink
Merge pull request #59 from BayAreaMetro/transit-ccr
Browse files Browse the repository at this point in the history
Incorporate latest updates from transit-car into transit-ccr-single-python-env
  • Loading branch information
lmz authored Jul 14, 2022
2 parents 690cf19 + 518e726 commit c3a97ff
Show file tree
Hide file tree
Showing 45 changed files with 5,239 additions and 2,895 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Push Workflow

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Document branch
run: echo ${{ github.ref_name }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Configure Git user
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Build docs
run: |
mike deploy --push --rebase ${{ github.ref_name }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ core/release/
*.exe
model-files/runtime/config/pskill.exe
utilities/vta_expresslane_feed_saver/vta_expresslanes_2018*
site/
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,10 @@ public void setDestTaxiWaitTime(float destTaxiWaitTime) {
}

public float getFareSubsidy() {
return (tour.getTourPrimaryPurposeIndex() == ModelStructure.WORK_PRIMARY_PURPOSE_INDEX) ? person.getTransitSubsidyPercent() : 0f;
return ((tour.getTourPrimaryPurposeIndex() == ModelStructure.WORK_PRIMARY_PURPOSE_INDEX)||
(tour.getTourPrimaryPurposeIndex() == ModelStructure.SCHOOL_PRIMARY_PURPOSE_INDEX)||
(tour.getTourPrimaryPurposeIndex() == ModelStructure.UNIVERSITY_PRIMARY_PURPOSE_INDEX))
? person.getTransitSubsidyPercent() : 0f;
}

public int getIndexValue(String variableName)
Expand Down
7 changes: 5 additions & 2 deletions core/src/java/com/pb/mtctm2/abm/ctramp/TripModeChoiceDMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,11 @@ public void setWaitTimeTaxi(float waitTimeTaxi) {
}

public float getFareSubsidy() {
return person.getTransitSubsidyPercent();
}
return ((tour.getTourPrimaryPurposeIndex() == ModelStructure.WORK_PRIMARY_PURPOSE_INDEX)||
(tour.getTourPrimaryPurposeIndex() == ModelStructure.SCHOOL_PRIMARY_PURPOSE_INDEX)||
(tour.getTourPrimaryPurposeIndex() == ModelStructure.UNIVERSITY_PRIMARY_PURPOSE_INDEX))
? person.getTransitSubsidyPercent() : 0f;
}

public int outboundPNRTripOnTour() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,29 @@ public class ParkingCapacityRestraintModel {
private ArrayList<Household> householdsToResimulate;
private float sampleRate;
private int seed;
private static float UNSPECIFIED_SPACES = 20;
private static int MINUTES_PER_SIMULATION_PERIOD = 15;
private static int MAX_ITERATIONS = 10;
private float unspecified_spaces = 20;
private int minutes_per_simulation_period = 15;
private int max_iterations = 10;
private float lumpiness_factor=2f;
private float parkAndHideFactor=1.15f;
private float occupancyFactor = 1.05f;


private static final String PROPERTIES_SPACES_FOR_MISSING_TAPS = "ParkingCapacityRestraint.spacesForMissingLots";
private static final String PROPERTIES_MINUTES_PER_SIMULATION_PERIOD = "ParkingCapacityRestraint.minutesPerSimulationPeriod";
private static final String PROPERTIES_MAX_ITERATIONS = "ParkingCapacityRestraint.maxIterations";
private static final String PROPERTIES_LUMPINESS_FACTOR = "ParkingCapacityRestraint.lumpinessFactor";
private static final String PROPERTIES_PARK_AND_HIDE_FACTOR = "ParkingCapacityRestraint.parkAndHideFactor";
private static final String PROPERTIES_MAX_OCCUPANCY_FACTOR = "ParkingCapacityRestraint.occupancyFactor";





//this is the factor on 1/sample rate that is the maximum tolerance for convergence. For example, if the sample rate is 0.2
//then lumpiness (minimum number of vehicles) is 1/0.2 = 5. If the max tolerance is 2, the model would iterate until either
//max iterations is reached or when all lots have demand < (lot capacity + 5 * 2). Note this may need to be scaled as sample rate increases.

private static int LUMPINESS_FACTOR=2;

private static int PACKET_SIZE = 0;

Expand Down Expand Up @@ -128,6 +142,12 @@ public ParkingCapacityRestraintModel(ResourceBundle rb, HashMap<String, String>
*/
public void initialize() {

unspecified_spaces = Float.parseFloat(propertyMap.get(PROPERTIES_SPACES_FOR_MISSING_TAPS));
minutes_per_simulation_period = Integer.parseInt(propertyMap.get(PROPERTIES_MINUTES_PER_SIMULATION_PERIOD));
max_iterations = Integer.parseInt(propertyMap.get(PROPERTIES_MAX_ITERATIONS));
lumpiness_factor = Float.parseFloat(propertyMap.get( PROPERTIES_LUMPINESS_FACTOR));
parkAndHideFactor = Float.parseFloat(propertyMap.get(PROPERTIES_PARK_AND_HIDE_FACTOR));
occupancyFactor = Float.parseFloat(propertyMap.get(PROPERTIES_MAX_OCCUPANCY_FACTOR));

//initialize the end time in minutes (stored in double so no overlap between periods)
endTimeMinutes = new double[40+1];
Expand Down Expand Up @@ -157,8 +177,8 @@ public void initialize() {
tazManager = TazDataManager.getInstance(propertyMap);

//set the length of a simulation period
numberOfTimeBins = ((24*60)/MINUTES_PER_SIMULATION_PERIOD);
logger.info("Running "+numberOfTimeBins+" simulation periods using a period length of "+MINUTES_PER_SIMULATION_PERIOD+" minutes");
numberOfTimeBins = ((24*60)/minutes_per_simulation_period);
logger.info("Running "+numberOfTimeBins+" simulation periods using a period length of "+minutes_per_simulation_period+" minutes");


}
Expand Down Expand Up @@ -206,13 +226,13 @@ public void runModel(HashMap<String, String> propertyMap) {

converged = checkForConvergence(constraintIteration);

if(converged)
break;
if(converged) {
filename = propertyMap.get(PROPERTIES_PROJECT_DIRECTORY)
+ formFileName(propertyMap.get(PROPERTIES_CONSTRAINED_PNR_DEMAND_FILE), iteration*10+constraintIteration);

filename = propertyMap.get(PROPERTIES_PROJECT_DIRECTORY)
+ formFileName(propertyMap.get(PROPERTIES_CONSTRAINED_PNR_DEMAND_FILE), iteration*10+constraintIteration);

writeDemandToFile(filename,constrainedArrivalsToTAP,constrainedPNRLotMap);
writeDemandToFile(filename,constrainedArrivalsToTAP,constrainedPNRLotMap);
break;
}


}while(true);
Expand All @@ -232,22 +252,31 @@ public void runModel(HashMap<String, String> propertyMap) {
*/
public boolean checkForConvergence(int constraintIteration) {

if(constraintIteration == (MAX_ITERATIONS-1))
logger.info("Checking for convergence");

if(constraintIteration == (max_iterations-1)) {
logger.info("Max iterations reached");
return true;
}

//minimum tolerance is a function of sample rate
float lumpiness = 1.0f/sampleRate;
float buffer = 1.0f/sampleRate * lumpiness_factor;

logger.info("Buffer for over-capacity calculation: "+buffer);


logger.info("LOT CAPACITY CAP+BUFFER ARRIVALS OVER?");
//iterate through lots
Set<Integer> taps = constrainedPNRLotMap.keySet();
for(int tap : taps) {

float totalArrivals = constrainedArrivalsToTAP[tap];

float capacity = tapManager.getTotalSpaces(tap);
float capacity = tapManager.getTotalSpaces(tap) * parkAndHideFactor * occupancyFactor;

logger.info(tap+" "+capacity+" "+(capacity+buffer)+" "+totalArrivals+" "+(totalArrivals > (capacity + buffer)? "TRUE": "FALSE"));

if(totalArrivals > (capacity + lumpiness * LUMPINESS_FACTOR))
if(totalArrivals > (capacity + buffer))
return false;

}
Expand Down Expand Up @@ -463,7 +492,7 @@ public void codePNRTour(Tour thisTour) {
*/
public void calculateUnconstrainedArrivalsByPeriod() {

logger.info("Calculated "+numberOfTimeBins+" simulation periods using a period length of "+MINUTES_PER_SIMULATION_PERIOD+" minutes");
logger.info("Calculated "+numberOfTimeBins+" simulation periods using a period length of "+minutes_per_simulation_period+" minutes");

unconstrainedPNRArrivalsByPeriod=new float[numberOfTimeBins];

Expand All @@ -482,16 +511,17 @@ public void calculateUnconstrainedArrivalsByPeriod() {
for(Stop thisStop : unconstrainedPNRTrips) {

float departTime = thisStop.getMinute();
int bin = (int) Math.floor(departTime/((float) MINUTES_PER_SIMULATION_PERIOD));
int bin = (int) Math.floor(departTime/((float) minutes_per_simulation_period));

int tap = thisStop.getBoardTap();

//assume some small number of spaces if lot is not in station attribute file?
float totalSpaces = tapManager.getTotalSpaces(tap);
if(totalSpaces==0) {
totalSpaces=UNSPECIFIED_SPACES;
totalSpaces=unspecified_spaces;
tapManager.setTotalSpaces(tap, totalSpaces);
}
totalSpaces = totalSpaces * parkAndHideFactor * occupancyFactor;

unconstrainedPNRArrivalsByPeriod[bin] += (1.0/sampleRate);

Expand Down Expand Up @@ -732,7 +762,7 @@ private void calculateConstrainedArrivals(Tour thisTour) {
totalPNRArrivals += (1.0/sampleRate);

float departTime = thisStop.getMinute();
int bin = (int) Math.floor(departTime/((float) MINUTES_PER_SIMULATION_PERIOD));
int bin = (int) Math.floor(departTime/((float) minutes_per_simulation_period));

int tap = thisStop.getBoardTap();

Expand Down Expand Up @@ -774,15 +804,16 @@ private void writeDemandToFile(String filename, float[] arrivalsToTAP, HashMap<I

String header = "TAP,CAPACITY,TOT_ARRIVALS";
for(int i=0; i<numberOfTimeBins;++i) {
String timeString = getTimeString(MINUTES_PER_SIMULATION_PERIOD+(i*MINUTES_PER_SIMULATION_PERIOD));
String timeString = getTimeString(minutes_per_simulation_period+(i*minutes_per_simulation_period));
header += ","+timeString;
}
pnrWriter.println(header);
pnrWriter.flush();

Set<Integer> tapSet = PNRLotMap.keySet();
for(Integer tap:tapSet) {
float totalSpaces = tapManager.getTotalSpaces(tap);
float totalSpaces = tapManager.getTotalSpaces(tap) * parkAndHideFactor * occupancyFactor;

float[] arrivals = PNRLotMap.get(tap);
String printString = tap + "," + totalSpaces +","+arrivalsToTAP[tap];
for(int i=0;i<arrivals.length;++i) {
Expand Down
5 changes: 5 additions & 0 deletions docs/geographies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Geographies

Travel Model Two [MAZs and TAZs are posted on ArcGIS Online](https://mtc.maps.arcgis.com/home/item.html?id=757176c6fd2e44e092225d3ac75841b0).

<style>.embed-container {position: relative; padding-bottom: 90%; height: 0; max-width: 100%;} .embed-container iframe, .embed-container object, .embed-container iframe{position: absolute; top: 0; left: 0; width: 100%; height: 100%;} small{position: absolute; z-index: 40; bottom: 0; margin-bottom: -15px;}</style><div class="embed-container"><iframe width="1000" height="900" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" title="Travel_Model_Two_MAZ_TAZ_v2_2" src="//mtc.maps.arcgis.com/apps/Embed/index.html?webmap=757176c6fd2e44e092225d3ac75841b0&extent=-122.5554,37.7044,-122.3336,37.8139&zoom=true&previewImage=false&scale=true&disable_scroll=true&theme=light"></iframe></div>
Loading

0 comments on commit c3a97ff

Please sign in to comment.