Skip to content

Commit

Permalink
fixed bug in MAG writer
Browse files Browse the repository at this point in the history
no VOT segmentation for MAG so VOT segment properties needed to be
ignored and code to segment removed.
  • Loading branch information
jim committed May 4, 2020
1 parent 9764e73 commit c9e6cde
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 137 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java'

jar {
baseName = 'carTracker'
version = '28Apr2020_v1.08'
version = '04May2020_v1.09'
}

repositories {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/algorithms/CarAllocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ private void setupObjectiveFunctionVariablesAndCoefficients( Household hh, MPSol
if(nextAo == 0)
parkCostGik = 0;

// set repositioning cost to very high value if non-AV hh and not starting in the same taz
// set repositioning cost to very high value if non-AV hh and not starting in the same taz and if the persons are not same for two trips
if(hh.getIfAvHousehold() == 0 ){
reposCostToNextTripOrigGik = NON_AV_REPO_COST;
reposCostToHome = NON_AV_REPO_COST;
if(!pairLi)
if(!pairLi || !samePerson)
reposCostToNextTripOrigSik = NON_AV_REPO_COST;
}
for ( int j=0; j < numAutos; j++ ) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appLayer/CarAllocatorMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static void main( String[] args ) {

CarAllocatorMain mainObj = new CarAllocatorMain();

System.out.println ( "CarTracker, 28Apr2020, v1.08, starting." );
System.out.println ( "CarTracker, 04May2020, v1.09, starting." );

ResourceBundle rb = null;
if ( args.length >=0 ) {
Expand Down
195 changes: 62 additions & 133 deletions src/main/java/appLayer/WriteCarAllocationOutputFilesMag.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public void writeCarAllocationOutputFile( Logger logger, HashMap<String, String>

tripTableFiles = new String[numberOfPeriods];

int numVotSegments = Integer.valueOf( propertyMap.get( "output.number.vot.segments" ) );
if ( numVotSegments > 1 ) {
votThresholds = new int[numVotSegments-1];
for(int i=0;i<numVotSegments-1;i++){
String tempKey = "output.trip.matrices.vot"+String.valueOf(i+1)+".threshold";
votThresholds[i]=Integer.valueOf( propertyMap.get(tempKey) );
}
numberOfVotCategories = numVotSegments;
}
// int numVotSegments = Integer.valueOf( propertyMap.get( "output.number.vot.segments" ) );
// if ( numVotSegments > 1 ) {
// votThresholds = new int[numVotSegments-1];
// for(int i=0;i<numVotSegments-1;i++){
// String tempKey = "output.trip.matrices.vot"+String.valueOf(i+1)+".threshold";
// votThresholds[i]=Integer.valueOf( propertyMap.get(tempKey) );
// }
// numberOfVotCategories = numVotSegments;
// }



Expand Down Expand Up @@ -135,7 +135,6 @@ public void writeCarAllocationOutputFile( Logger logger, HashMap<String, String>
periodIntervals[4][0] = Integer.valueOf( propertyMap.get( EV_PERIOD_START_KEY ) );
periodIntervals[4][1] = Integer.valueOf( propertyMap.get( EV_PERIOD_END_KEY ) );

logger.info( "writing trip matrix files." );

String formatString = propertyMap.get( OUTPUT_TRIP_TABLE_FORMAT_KEY );
MatrixType matrixType = MatrixType.lookUpMatrixType( formatString );
Expand Down Expand Up @@ -852,139 +851,69 @@ record = hh.getId()+","+
logger.info(String.format( "%-60s","Total Unused AV Cars = ") + String.format("%,15d",totalUsedAVCars));


logger.info( "writing trip matrix files." );

int offset = 0;
if ( separateCavFiles )
offset = numModeTables*numberOfVotCategories;
offset = numModeTables;

for ( int i=0; i < periodLabels.length; i++ ) {

Matrix[] matrices = new Matrix[numModeTables*numberOfVotCategories];
String[] tripTableNames = new String[numModeTables*numberOfVotCategories];
Matrix[] matrices = new Matrix[numModeTables];
String[] tripTableNames = new String[numModeTables];
if ( separateCavFiles ) {
matrices = new Matrix[numModeTables*numberOfVotCategories*2];
tripTableNames = new String[numModeTables*numberOfVotCategories*2];
matrices = new Matrix[numModeTables*2];
tripTableNames = new String[numModeTables*2];
}

if ( numberOfVotCategories > 1 ) {

// if separateCavFiles, write empty table after mode tables
if ( separateCavFiles ) {
for ( int j=0; j < numModeTables-1; j++ ) {
for (int v = 0; v<numberOfVotCategories; v++){
int matrixIndex = j*numberOfVotCategories + v;
String description = periodLabels[i] + " period C/AV " + autoTripTableNames[j] + " trips by vot segment " + String.valueOf(v) ;
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][(j)*numberOfVotCategories+v], tazValues );
tripTableNames[matrixIndex] = autoTripTableNames[j]+"_cav"+"_vot" + String.valueOf(v);
matrices[matrixIndex] = new Matrix( tripTableNames[matrixIndex], description, orderedTable );
matrices[matrixIndex].setExternalNumbers( extNumbers );
}
}
for (int v = 0; v<numberOfVotCategories; v++){
int matrixIndex = (numModeTables-1)*numberOfVotCategories + v;
String description = periodLabels[i] + " period C/AV empty trips by vot segment " + String.valueOf(v) ;
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][(numModeTables-1)*numberOfVotCategories+v], tazValues );
tripTableNames[matrixIndex] = "empty_cav_vot" + String.valueOf(v);
matrices[matrixIndex] = new Matrix( tripTableNames[matrixIndex], description, orderedTable );
matrices[matrixIndex].setExternalNumbers( extNumbers );
}
}
else {
for ( int j=0; j < numModeTables; j++ ) {
for (int v = 0; v<numberOfVotCategories; v++){
int matrixIndex = j*numberOfVotCategories + v;
String description = periodLabels[i] + " period C/AV " + autoTripTableNames[j] + " trips by vot segment " + String.valueOf(v) ;
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][(j)*numberOfVotCategories+v], tazValues );
tripTableNames[matrixIndex] = autoTripTableNames[j]+"_cav"+"_vot" + String.valueOf(v);
matrices[matrixIndex] = new Matrix( tripTableNames[matrixIndex], description, orderedTable );
matrices[matrixIndex].setExternalNumbers( extNumbers );
}
}
}



if ( separateCavFiles ) {
for ( int j=0; j < numModeTables-1; j++ ) {
for (int v = 0; v<numberOfVotCategories; v++){
int matrixIndex = j*numberOfVotCategories + v;
String description = periodLabels[i] + " period non-C/AV " + autoTripTableNames[j] + " trips by vot segment " + String.valueOf(v) ;
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][(j)*numberOfVotCategories+v], tazValues );
tripTableNames[matrixIndex] = autoTripTableNames[j]+"_vot" + String.valueOf(v);
matrices[matrixIndex] = new Matrix( tripTableNames[matrixIndex], description, orderedTable );
matrices[matrixIndex].setExternalNumbers( extNumbers );
}
}
for (int v = 0; v<numberOfVotCategories; v++){
int matrixIndex = (numModeTables-1)*numberOfVotCategories + v;
String description = periodLabels[i] + " period non-C/AV empty trips by vot segment " + String.valueOf(v) ;
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][(numModeTables-1)*numberOfVotCategories+v], tazValues );
tripTableNames[matrixIndex] = "empty_vot" + String.valueOf(v);
matrices[matrixIndex] = new Matrix( tripTableNames[matrixIndex], description, orderedTable );
matrices[matrixIndex].setExternalNumbers( extNumbers );
}
}
else {
for ( int j=0; j < numModeTables; j++ ) {
for (int v = 0; v<numberOfVotCategories; v++){
int matrixIndex = j*numberOfVotCategories + v;
String description = periodLabels[i] + " period " + autoTripTableNames[j] + " trips by vot segment " + String.valueOf(v) ;
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][(j)*numberOfVotCategories+v], tazValues );
tripTableNames[matrixIndex] = autoTripTableNames[j]+"_vot" + String.valueOf(v);
matrices[matrixIndex] = new Matrix( tripTableNames[matrixIndex], description, orderedTable );
matrices[matrixIndex].setExternalNumbers( extNumbers );
}
}
}

}
else {

if ( separateCavFiles ) {

for ( int j=0; j < numModeTables-1; j++ ) {
String description = periodLabels[i] + " period C/AV " + autoTripTableNames[j] + " trips";
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][j], tazValues );
tripTableNames[j] = autoTripTableNames[j]+"_cav";
matrices[j] = new Matrix( tripTableNames[j], description, orderedTable );
matrices[j].setExternalNumbers( extNumbers );
}

String description = periodLabels[i] + " period C/AV empty trips";
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][(numModeTables-1)], tazValues );
tripTableNames[(numModeTables-1)] = "empty_cav";
matrices[(numModeTables-1)] = new Matrix( tripTableNames[(numModeTables-1)], description, orderedTable );
matrices[(numModeTables-1)].setExternalNumbers( extNumbers );

for ( int j=0; j < numModeTables-1; j++ ) {
description = periodLabels[i] + " period non-C/AV " + autoTripTableNames[j] + " trips";
orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][j], tazValues );
tripTableNames[j+offset] = autoTripTableNames[j];
matrices[j+offset] = new Matrix( tripTableNames[j+offset], description, orderedTable );
matrices[j+offset].setExternalNumbers( extNumbers );
}

description = periodLabels[i] + " period non-C/AV empty trips";
orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][(numModeTables-1)], tazValues );
tripTableNames[(numModeTables-1)+offset] = "empty";
matrices[(numModeTables-1)+offset] = new Matrix( tripTableNames[(numModeTables-1)+offset], description, orderedTable );
matrices[(numModeTables-1)+offset].setExternalNumbers( extNumbers );

}
else {

for ( int j=0; j < numModeTables; j++ ) {
String description = periodLabels[i] + " period " + autoTripTableNames[j] + " trips";
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][j], tazValues );
tripTableNames[j] = autoTripTableNames[j];
matrices[j] = new Matrix( tripTableNames[j], description, orderedTable );
matrices[j].setExternalNumbers( extNumbers );
}

}
if ( separateCavFiles ) {

for ( int j=0; j < numModeTables-1; j++ ) {
String description = periodLabels[i] + " period C/AV " + autoTripTableNames[j] + " trips";
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][j], tazValues );
tripTableNames[j] = autoTripTableNames[j]+"_cav";
matrices[j] = new Matrix( tripTableNames[j], description, orderedTable );
matrices[j].setExternalNumbers( extNumbers );
}

String description = periodLabels[i] + " period C/AV empty trips";
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, cavTripTables[i][(numModeTables-1)], tazValues );
tripTableNames[(numModeTables-1)] = "empty_cav";
matrices[(numModeTables-1)] = new Matrix( tripTableNames[(numModeTables-1)], description, orderedTable );
matrices[(numModeTables-1)].setExternalNumbers( extNumbers );

for ( int j=0; j < numModeTables-1; j++ ) {
description = periodLabels[i] + " period non-C/AV " + autoTripTableNames[j] + " trips";
orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][j], tazValues );
tripTableNames[j+offset] = autoTripTableNames[j];
matrices[j+offset] = new Matrix( tripTableNames[j+offset], description, orderedTable );
matrices[j+offset].setExternalNumbers( extNumbers );
}

description = periodLabels[i] + " period non-C/AV empty trips";
orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][(numModeTables-1)], tazValues );
tripTableNames[(numModeTables-1)+offset] = "empty";
matrices[(numModeTables-1)+offset] = new Matrix( tripTableNames[(numModeTables-1)+offset], description, orderedTable );
matrices[(numModeTables-1)+offset].setExternalNumbers( extNumbers );

}
else {

for ( int j=0; j < numModeTables; j++ ) {
String description = periodLabels[i] + " period " + autoTripTableNames[j] + " trips";
float[][] orderedTable = getTripTableOrderedByExternalTazValues( tazValuesOrder, nonCavTripTables[i][j], tazValues );
tripTableNames[j] = autoTripTableNames[j];
matrices[j] = new Matrix( tripTableNames[j], description, orderedTable );
matrices[j].setExternalNumbers( extNumbers );
}

}

}


logger.info( "writing file: " + tripTableFiles[i] + ", matrixType: " + matrixType );
for ( String table : tripTableNames )
logger.info( " " + table );

matrixHandler.writeMatrixFile( tripTableFiles[i], matrices, tripTableNames, matrixType );

}
Expand Down

0 comments on commit c9e6cde

Please sign in to comment.