-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat(mapping): configure type distributions for ScenarioVehicle #333
Conversation
allows defining multiple application types for equal vehicle type names in large sumo scenario Signed-off-by: Karl Schrab <[email protected]>
Signed-off-by: Karl Schrab <[email protected]>
Signed-off-by: Karl Schrab <[email protected]>
Signed-off-by: Karl Schrab <[email protected]>
Signed-off-by: Karl Schrab <[email protected]>
I think we will need to adjust some further parts of the documentation: |
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.
Some minor remarks but overall looks fine
return; | ||
final List<CPrototype> typeDistribution = framework.getTypeDistributionByName(scenarioVehicle.getVehicleType().getName()); | ||
if (!typeDistribution.isEmpty()) { | ||
final CPrototype selected = new StochasticSelector<>(typeDistribution, randomNumberGenerator).nextItem(); |
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.
Wouldn't it be better to somehow re-use the StochasticSelector
for each separate type distribution?
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.
I could do this somehow I guess, but I'm afraid that it would blow up the code here and would decrease readability. I'm not sure if this would even improve anything.
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.
In the BeST-scenario this would cause ~3 million unnecessary initializations of a StochasticSelector
, wouldn't it? Also I don't know how the randomness is affected if we draw a type distribution from the same selector or newly initialized ones, although I would assume this doesn't matter.
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.
I implemented this "cache".
Previous:
final CPrototype selected = new StochasticSelector<>(typeDistribution, randomNumberGenerator).nextItem();
Now:
StochasticSelector<CPrototype> selector = typeDistributionSelectors.get(scenarioVehicle.getVehicleType().getName());
if (selector == null) {
selector = new StochasticSelector<>(typeDistribution, randomNumberGenerator);
typeDistributionSelectors.put(scenarioVehicle.getVehicleType().getName(), selector);
}
final CPrototype selected = selector.nextItem();
Alternative approach, but I'm not 100% sure if other objects (e.g. the object for the lambda) are created instead, that's why I ditched this for now:
final CPrototype selected = typeDistributionSelectors.computeIfAbsent(
scenarioVehicle.getVehicleType().getName(), (v) -> new StochasticSelector<>(typeDistribution, randomNumberGenerator)
).nextItem();
...osaic-mapping/src/main/java/org/eclipse/mosaic/fed/mapping/ambassador/MappingAmbassador.java
Show resolved
Hide resolved
Yes, thanks for pointing out the parts for the adjustments. |
Signed-off-by: Karl Schrab <[email protected]>
… Sievekingplatz Signed-off-by: Karl Schrab <[email protected]>
Signed-off-by: Karl Schrab <[email protected]>
@schwepmo please review again, I used the typeDistribution field in the Sievekingplatz scenario and added an intergration test for it |
Description
When using predefined SUMO scenarios with, the mapping of applications could be configured using the
prototype
section by defining a prototype with a name matching the vType identifier of the vehicles, with theweight
attribute to control the equipment rate of applications.However, this allowed only to configure if a vehicle type could be configured with applications or not. No distinction between multiple application deployments could be done. This is now possible with this PR.
In the
mapping_config,json
, we now allow thetypeDistribution
section to define a whole distribution of application mappings for one vType identifier from the given SUMO scenario. Let's suppose we only have one vehicle type defined in the SUMO scenario, called "DefaultVehicle", then we can configure a complex application mapping as the following:Issue(s) related to this PR
Affected parts of the online documentation
Changes in the documentation required?
Yes, LuST tutorial should be adjusted to use
typeDistributions
instead.Definition of Done
Prerequisites
Required
type(scope): description
(in the style of Conventional Commits)enhancement
, orbugfix
)origin/main
has been merged into your Fork.Requested (can be enforced by maintainers)
Special notes to reviewer