-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: ride hail transit re-enable #3790
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
802a738
the fix
nikolayilyin c38f713
some GH automatic changes
nikolayilyin 395926b
test to check all modes are working
nikolayilyin 56e3588
removing unnecessary files
nikolayilyin 24c4813
graphhopper folder will be created each time anyway
nikolayilyin f6e9a0a
fmt
nikolayilyin 0f6994b
an attempt to fix flaky test
nikolayilyin 2b5543d
an attempt to fix flaky test II
nikolayilyin b6c7d9d
fmt
nikolayilyin bff64e0
debugging flaky test
nikolayilyin edd9d5d
logging in case there are no excluded modes
nikolayilyin dce97ef
this folder will be re-created automatically
nikolayilyin f70d667
debugging flaky test
nikolayilyin f3db80a
debugging
nikolayilyin daccaa8
an attempt to fix failing test
nikolayilyin c2a2955
fmt
nikolayilyin 5ee0ebc
fix
nikolayilyin ee3ca00
rework of the test to fix parallel execution issues
nikolayilyin 1a90713
required for rework of the test to work
nikolayilyin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,204 @@ | ||
package beam.integration | ||
|
||
import beam.sim.BeamHelper | ||
import beam.utils.TestConfigUtils.testConfig | ||
import com.typesafe.config.{Config, ConfigValueFactory} | ||
import org.scalatest.AppendedClues | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
|
||
/** | ||
* Created by fdariasm on 29/08/2017 | ||
*/ | ||
class ModeChoiceSpec extends AnyWordSpecLike with Matchers with BeamHelper with IntegrationSpecCommon { | ||
|
||
// "Running beam with modeChoiceClass ModeChoiceDriveIfAvailable" must { | ||
// "prefer mode choice car type than other modes" in { | ||
// val theRun = new StartWithCustomConfig( | ||
// baseConfig.withValue(TestConstants.KEY_AGENT_MODAL_BEHAVIORS_MODE_CHOICE_CLASS, ConfigValueFactory.fromAnyRef | ||
// ("ModeChoiceDriveIfAvailable")) | ||
// ) | ||
// val testModeCount = theRun.groupedCount.getOrElse("car", 0) | ||
// val otherModesCount = theRun.groupedCount.getOrElse("ride_hail", 0) + | ||
// theRun.groupedCount.getOrElse("walk_transit", 0) + theRun.groupedCount.getOrElse("drive_transit", 0) + | ||
// theRun.groupedCount.getOrElse("bike", 0) | ||
// testModeCount should be >= otherModesCount | ||
// } | ||
// } | ||
class ModeChoiceSpec | ||
extends AnyWordSpecLike | ||
with Matchers | ||
with BeamHelper | ||
with IntegrationSpecCommon | ||
with AppendedClues { | ||
|
||
def getModesOtherThan(excludedMode: String, simulationModes: Map[String, Int]): Int = { | ||
simulationModes.foldLeft(0) { | ||
case (countOfModes, (mode, _)) if mode == excludedMode => countOfModes | ||
case (countOfModes, (_, count)) => countOfModes + count | ||
} | ||
} | ||
|
||
def getClueText(simulationModes: Map[String, Int]): String = { | ||
val allModesString = simulationModes.map { case (mode, count) => s"$mode:$count" }.mkString(", ") | ||
s", all modes are: $allModesString" | ||
} | ||
|
||
def baseBeamvilleUrbansimConfig: Config = testConfig("test/input/beamville/beam-urbansimv2-modechoicespec.conf") | ||
// .withValue("beam.agentsim.lastIteration", ConfigValueFactory.fromAnyRef("0")) | ||
// .withValue("beam.urbansim.fractionOfModesToClear.allModes", ConfigValueFactory.fromAnyRef("1.0")) | ||
// .withValue("beam.outputs.events.fileOutputFormats", ConfigValueFactory.fromAnyRef("xml")) | ||
// .withValue("beam.agentsim.agents.vehicles.fractionOfInitialVehicleFleet", ConfigValueFactory.fromAnyRef("10.0")) | ||
// .withValue("beam.agentsim.agents.vehicles.fractionOfPeopleWithBicycle", ConfigValueFactory.fromAnyRef("10.0")) | ||
|
||
// these should be as low as possible | ||
val test_mode_multiplier = 2 | ||
val test_mode_transit_multiplier = 20 | ||
|
||
def resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor( | ||
selectedMode: String, | ||
router: String, | ||
highIntercept: Int = 999999 | ||
): Config = { | ||
baseBeamvilleUrbansimConfig | ||
.withValue( | ||
s"beam.agentsim.agents.modalBehaviors.multinomialLogit.params.$selectedMode", | ||
ConfigValueFactory.fromAnyRef(highIntercept) | ||
) | ||
.withValue( | ||
s"beam.routing.carRouter", | ||
ConfigValueFactory.fromAnyRef(router) | ||
) | ||
.resolve() | ||
} | ||
|
||
"Running beam with high intercepts for drive transit" must { | ||
"use drive transit with R5 router" ignore { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("drive_transit_intercept", "R5") | ||
) | ||
|
||
val driveTransitModeCount = theRun.groupedCount.getOrElse("drive_transit", 0) | ||
val theRestModes = getModesOtherThan("drive_transit", theRun.groupedCount) | ||
driveTransitModeCount * test_mode_transit_multiplier should be >= theRestModes withClue getClueText( | ||
theRun.groupedCount | ||
) | ||
} | ||
|
||
"use drive transit with GH router" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("drive_transit_intercept", "staticGH") | ||
) | ||
|
||
val driveTransitModeCount = theRun.groupedCount.getOrElse("drive_transit", 0) | ||
val theRestModes = getModesOtherThan("drive_transit", theRun.groupedCount) | ||
driveTransitModeCount * test_mode_transit_multiplier should be >= theRestModes withClue getClueText( | ||
theRun.groupedCount | ||
) | ||
} | ||
} | ||
|
||
"Running beam with high intercepts for RH transit" must { | ||
"use RH transit with R5 router" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("ride_hail_transit_intercept", "R5") | ||
) | ||
|
||
val RHTransitCount = theRun.groupedCount.getOrElse("ride_hail_transit", 0) | ||
val theRestModes = getModesOtherThan("ride_hail_transit", theRun.groupedCount) | ||
RHTransitCount * test_mode_transit_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
} | ||
|
||
"Running beam with high intercepts for CAV" must { | ||
"use cav with R5 router" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("cav_intercept", "R5") | ||
) | ||
|
||
val cavModeCount = theRun.groupedCount.getOrElse("cav", 0) | ||
val theRestModes = getModesOtherThan("cav", theRun.groupedCount) | ||
cavModeCount * test_mode_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
} | ||
|
||
"Running beam with high intercepts for bike transit" must { | ||
"use bike transit with R5 router" ignore { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("bike_transit_intercept", "R5") | ||
) | ||
|
||
val bikeTransitModeCount = theRun.groupedCount.getOrElse("bike_transit", 0) | ||
val theRestModes = getModesOtherThan("bike_transit", theRun.groupedCount) | ||
bikeTransitModeCount * test_mode_transit_multiplier should be >= theRestModes withClue getClueText( | ||
theRun.groupedCount | ||
) | ||
} | ||
} | ||
|
||
"Running beam with high intercepts for CAR" must { | ||
"prefer mode choice car more than other modes (with ModeChoiceDriveIfAvailable)" in { | ||
val theRun = new StartWithCustomConfig( | ||
baseBeamvilleUrbansimConfig | ||
.withValue( | ||
TestConstants.KEY_AGENT_MODAL_BEHAVIORS_MODE_CHOICE_CLASS, | ||
ConfigValueFactory.fromAnyRef("ModeChoiceDriveIfAvailable") | ||
) | ||
.resolve() | ||
) | ||
|
||
val carModeCount = theRun.groupedCount.getOrElse("car", 0) | ||
val theRestModes = getModesOtherThan("car", theRun.groupedCount) | ||
carModeCount * test_mode_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
|
||
"use car with R5 router" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("car_intercept", "R5") | ||
) | ||
|
||
val carModeCount = theRun.groupedCount.getOrElse("car", 0) | ||
val theRestModes = getModesOtherThan("car", theRun.groupedCount) | ||
carModeCount * test_mode_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
} | ||
|
||
"Running beam with specified intercept" must { | ||
"prefer mode choice bike more than other modes" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("bike_intercept", "R5") | ||
) | ||
|
||
val bikeModeCount = theRun.groupedCount.getOrElse("bike", 0) | ||
val theRestModes = getModesOtherThan("bike", theRun.groupedCount) | ||
bikeModeCount * test_mode_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
|
||
"prefer mode choice walk more than other modes" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("walk_intercept", "R5") | ||
) | ||
|
||
val walkModeCount = theRun.groupedCount.getOrElse("walk", 0) | ||
val theRestModes = getModesOtherThan("walk", theRun.groupedCount) | ||
walkModeCount * test_mode_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
|
||
"prefer mode choice RH more than other modes" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("ride_hail_intercept", "R5") | ||
) | ||
|
||
val RHModeCount = theRun.groupedCount.getOrElse("ride_hail", 0) | ||
val theRestModes = getModesOtherThan("ride_hail", theRun.groupedCount) | ||
RHModeCount * test_mode_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
|
||
"prefer mode choice walk transit more than other modes" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("walk_transit_intercept", "R5") | ||
) | ||
|
||
val walkTransitModeCount = theRun.groupedCount.getOrElse("walk_transit", 0) | ||
val theRestModes = getModesOtherThan("walk_transit", theRun.groupedCount) | ||
walkTransitModeCount * test_mode_transit_multiplier should be >= theRestModes withClue getClueText( | ||
theRun.groupedCount | ||
) | ||
} | ||
|
||
"prefer mode choice RH pooled more than other modes" in { | ||
val theRun: StartWithCustomConfig = new StartWithCustomConfig( | ||
resolvedBaseBeamvilleUrbansimConfigWithHighInterceptFor("ride_hail_pooled_intercept", "R5") | ||
) | ||
|
||
val RHPooledCount = theRun.groupedCount.getOrElse("ride_hail_pooled", 0) | ||
val theRestModes = getModesOtherThan("ride_hail_pooled", theRun.groupedCount) | ||
RHPooledCount * test_mode_transit_multiplier should be >= theRestModes withClue getClueText(theRun.groupedCount) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we can use it. Though it looks a little strange. What we can do is to create a custom Logback appender (https://www.baeldung.com/custom-logback-appender) and in logback-test.xml add it to the PopulationAdjustment only. Then we can get the appender programmatically and cleanup/check it before/after running a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously it did not work with custom appender and logger in the test (the approach was different though), and it looks like suggested change is too much work just to get one test working