-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fixes #2331 hiearchy of parmaeter value does not work with distribute… #2332
Fixes #2331 hiearchy of parmaeter value does not work with distribute… #2332
Conversation
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.
This should solve the issue
@@ -13,7 +13,8 @@ public DiscreteDistributionFormula() : base(DistributionType.Discrete) | |||
protected override double CalculateFor(IReadOnlyList<IObjectReference> usedObjects, IUsingFormula dependentObject) | |||
{ | |||
var distributedParameter = dependentObject.ConvertedTo<IDistributedParameter>(); | |||
return CalculateValueFromPercentile(distributedParameter.Percentile, distributedParameter); | |||
//percentile not used in this formula | |||
return CalculateValueFromPercentile(Constants.DEFAULT_PERCENTILE, distributedParameter); |
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.
the parameter is not used. might was well not retrieve it (not related to this error)
@@ -111,24 +111,44 @@ private IParameter getOrAddModelParameter(ValueUpdaterParams valueUpdater, Param | |||
parameter = _parameterValueToParameterMapper.MapFrom(parameterValue); | |||
|
|||
simulationBuilder.AddBuilderReference(parameter, parameterValue); | |||
|
|||
//now we remove the parameter by name from the parent container just in case it already exists but with a different type (distributed vs not distributed) | |||
var potentialParameter = parentContainer.Parameter(parameterValue.Name); |
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.
before we were only landing in this code if a parameter did not exist. Now we also land there if it exists but with a different type
public void should_overwrite_the_parameter_value_with_the_value_of_the_parameter() | ||
{ | ||
var parameter = _model.Root.EntityAt<IParameter>("Liver", "Param"); | ||
parameter.Value.ShouldBeEqualTo(24.28, 1e-2); |
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.
value of the distribution using the percentile of 0.8 (assuming this is right, I did not verify...)
//now we remove the parameter by name from the parent container just in case it already exists but with a different type (distributed vs not distributed) | ||
var potentialParameter = parentContainer.Parameter(parameterValue.Name); | ||
parentContainer.RemoveChild(potentialParameter); | ||
|
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.
RemoveChild will not crash if potentialParameter is null?
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 certainly hope not but this is something I just assumed lol
…d parameters
Fixes #2331
Description
Well this was a tricky one! As I expected, the issue is because we are updating a NON_DISTRIBUTED Parameter by a DISTRIBUTED_PARAMETER. it works if the parameter does not exist because it's created. But in the case outlined by @PavelBal , the parameter was created by the other Module and therefore the update routine did not work. This PR removes the existing parameters if they don't have the same structure and add them again
Spent most of the time trying to reproduce the bug.. as always :)
Type of change
Please mark relevant options with an
x
in the brackets.How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Reviewer checklist
Mark everything that needs to be checked before merging the PR.
This change requires a documentation update
above is selectedScreenshots (if appropriate):
Questions (if appropriate):