-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add group name to WeightModifier. Add ability to use custom factor ag… #963
Add group name to WeightModifier. Add ability to use custom factor ag… #963
Conversation
…gregator function for weight modifiers groups
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.
Don't forget about CHANGELOG.md.
Reviewed 1 of 3 files at r1, all commit messages.
Reviewable status: 0 of 1 approvals obtained (waiting on @nadiia-volyk)
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 14 at r1 (raw file):
new Dictionary<string, WeightModifier>(); private Dictionary<string, Func<double, double, double>> _groupFactorAggregators =
I'm not sure if we need another dictionary. Maybe modifiers just can share a group object?
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 125 at r1 (raw file):
name, new Func<Vertex, Vertex, bool>((a, b) => {
This function is way to expensive for something that is called for every edge, not every line is dependent on input parameters a and b.
Try to move as much as possible outside of lambda and just pass precomputed data as capture list. As an alternative, new type can be inherited from WeightModifier
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 141 at r1 (raw file):
var hintLine = new RoutingHintLine(polyline, factor, influenceDistance, true, is2D); var isAffectedParallely = hintLine.Affects(a.Point, b.Point); var isIntersected = polyline.Intersects(line, out _, includeEnds: true);
Check if Line DistanceTo Line is more efficient in this case, as intersect won't work with influence distance.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 163 at r1 (raw file):
{ var modifiersGroups = _weightModifiers.Values.GroupBy(m => m.Group); var modifierFactors = new List<double>();
The function is called for every edge. There is no reason to do grouping every time. This can be function that operates on one group of modifiers instead.
Code quote:
ModifierFactor
/// <param name="groupName">Group name. Must be not null.</param> | ||
/// <returns>List of WeightModifier with the specified group name.</returns> | ||
/// <exception cref="ArgumentNullException">Throws if <paramref name="groupName"/> is null.</exception> | ||
public List<WeightModifier> GetGroupWeightModifiers(string groupName) |
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.
Rename to GetWeightModifiersGroup to be consistent with function above and return IEnumerable and ToList is not required.
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.
Reviewable status: 0 of 1 approvals obtained (waiting on @nadiia-volyk)
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 66 at r1 (raw file):
/// <param name="groupName">Group name.</param> /// <param name="groupFactorAggregator">Factor aggregator function.</param> public void SetWeightModifiersGroupFactorAggregator(string groupName, Func<double, double, double> groupFactorAggregator)
I think we can drop Factor from name to make it little bit shorter.
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.
Reviewable status: 0 of 1 approvals obtained (waiting on @DmytroMuravskyi)
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 66 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
I think we can drop Factor from name to make it little bit shorter.
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 77 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
Rename to GetWeightModifiersGroup to be consistent with function above and return IEnumerable and ToList is not required.
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 125 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
This function is way to expensive for something that is called for every edge, not every line is dependent on input parameters a and b.
Try to move as much as possible outside of lambda and just pass precomputed data as capture list. As an alternative, new type can be inherited from WeightModifier
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 141 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
Check if Line DistanceTo Line is more efficient in this case, as intersect won't work with influence distance.
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 163 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
The function is called for every edge. There is no reason to do grouping every time. This can be function that operates on one group of modifiers instead.
Done.
@@ -51,14 +55,43 @@ public void ClearWeightModifiers() | |||
_weightModifiers.Clear(); | |||
} | |||
|
|||
/// <summary> | |||
/// Set factor aggregator function for weight modifiers group. |
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.
let's describe a little bit more about what these do. "The aggregator function will be applied to any list of weight modifications that share a group name. This ensures that if a type of modifier is applied to a single edge more than once we have options for how to apply duplicate modifiers."
} | ||
catch | ||
{ | ||
hintLine = 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.
what can result in us not being able to make a hint line? should we notify the user somehow that this happened?
/// Group weight modifiers. | ||
/// </summary> | ||
/// <returns>Weight modifiers grouped by group name.</returns> | ||
private IEnumerable<IGrouping<string, WeightModifier>> GroupWeightModifiers() |
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.
rename to GroupedWeightModifiers
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.
Reviewed 3 of 4 files at r2, all commit messages.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nadiia-volyk)
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 125 at r1 (raw file):
Previously, nadiia-volyk wrote…
Done.
Few details:
- Do not null check we don't really expect that it's better to throw so the problem is visible. Also, just return null above if hint is null
- Run Affects first since it doesn't require any additional data.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 217 at r2 (raw file):
} if (!_groupFactorAggregators.TryGetValue(modifiersGroup.Key, out var aggregateFactorFunc))
Looks good, let's also make this function have two parameters instead of group: IEnumerable and AggregateFunction.
And retrieve AggregateFunction in CalculateEdgeInfos.
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.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nadiia-volyk)
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 125 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
Few details:
- Do not null check we don't really expect that it's better to throw so the problem is visible. Also, just return null above if hint is null
- Run Affects first since it doesn't require any additional data.
Also, consider grouping code into something like hintLine.Intersects(a ,b)
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.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @DmytroMuravskyi and @wynged)
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 125 at r1 (raw file):
Previously, DmytroMuravskyi wrote…
Also, consider grouping code into something like hintLine.Intersects(a ,b)
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 59 at r2 (raw file):
Previously, wynged (Eric Wassail) wrote…
let's describe a little bit more about what these do. "The aggregator function will be applied to any list of weight modifications that share a group name. This ensures that if a type of modifier is applied to a single edge more than once we have options for how to apply duplicate modifiers."
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 129 at r2 (raw file):
Previously, wynged (Eric Wassail) wrote…
what can result in us not being able to make a hint line? should we notify the user somehow that this happened?
if the polyline is vertical and needs to be used in 2D comparison, such hint line cannot be created.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 172 at r2 (raw file):
Previously, wynged (Eric Wassail) wrote…
rename to
GroupedWeightModifiers
Done.
Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRoutingWeightModifier.cs
line 217 at r2 (raw file):
Previously, DmytroMuravskyi wrote…
Looks good, let's also make this function have two parameters instead of group: IEnumerable and AggregateFunction.
And retrieve AggregateFunction in CalculateEdgeInfos.
Done.
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.
Reviewed 2 of 3 files at r3, all commit messages.
Reviewable status: complete! 1 of 1 approvals obtained (waiting on @DmytroMuravskyi and @nadiia-volyk)
…gregator function for weight modifiers groups
BACKGROUND:
DESCRIPTION:
SetWeightModifiersGroupFactorAggregator
method for setting factor aggregator functions for different groups.AggregateFactorMin
,AggregateFactorMax
,AggregateFactorMultiply
can be used.REQUIRED:
CHANGELOG.md
.This change is