Skip to content

CustomWeighting: ensure Map is ordered - #2162

Merged
karussell merged 4 commits into
masterfrom
custom_weighting_bug
Oct 25, 2020
Merged

karussell merged 4 commits into
masterfrom
custom_weighting_bug

Conversation

@karussell

Copy link
Copy Markdown
Member

There is a bug which could occur for Java or the API when using multiple encoded values and/or multiple cases for one encoded value. The next goal should be to make CustomModel.getPriority/getSpeedFactor/getMaxSpeed type safe which we might reach when we limit the language to only "clause" as key and number as value (which is a next but much bigger step).

@karussell karussell added the bug label Oct 24, 2020
@karussell karussell added this to the 3.0 milestone Oct 24, 2020

@easbar easbar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea to use linked hash map 👍

@karussell
karussell merged commit dd9dbd5 into master Oct 25, 2020
@karussell
karussell deleted the custom_weighting_bug branch October 25, 2020 22:33
karussell added a commit that referenced this pull request Oct 27, 2020
* CustomWeighting: ensure Map is ordered

* minor

* cleaner junit5 assertThrows

* one more assertThrow
karussell added a commit that referenced this pull request Jan 19, 2021
* basic test with janino passing

* move janino scripting to safe whitelisted approach

* create a class to add encoded values on the fly but limit user input to expression

* compilation unit via overwriting getValue method safely

* minor fix regarding ClassName

* ensure it is not called twice

* separate parsing of condition and number

* CustomWeighting: ensure Map is ordered (#2162)

* CustomWeighting: ensure Map is ordered

* minor

* cleaner junit5 assertThrows

* one more assertThrow

* change expression from factor multiplication to if-then-elseif-else and make speed factor working too

* replace catch all with true and make max_speed working

* no need to parse value which is always a number

* use global max speed

* minor cleanup and fix regarding sharedEV

* found a way to avoid Unparser.unparse

* use scripting in CustomWeighting. This revealed: we need if and if-else-if clauses and maybe a different variable initialization

* reduce max speed and fix priority bug

* cosmetics

* minor truck.yml tweaks

* adapt benchmarks

* a bit more details in exception

* see perf with ugly caching hack

* revert and see bench

* workaround bug with import conflict (two imports for enum 'NO')

* inject class for constants, avoid static imports that can easily collide

* special case of RouteNetwork for bike

* introduce thread-safe caching; minor restructuring

* reduce code duplication in ScriptHelper

* move code out of ScriptHelper and rename it to ExpressionBuilder

* less recursion for more clear protection

* further cleanup and improved naming

* adapt CustomModel.merge to scripting and throw exception if query-CustomModel contains factors >1

* improved docs about custom model

* adapted docs to new format

* removed CustomWeightingOld and all related classes

* minor fixes

* make debugging possible; every dynamic class has a different name now; fix two issues in source code creation (RoadClass->EncodedValue and import JsonFeature)

* improve caching: remove oldest accessed entry, instead oldest inserted

* introduce cache to keep certain classes in cache forever

* try perf with disabled cache to see CH numbers again

* Revert "try perf with disabled cache to see CH numbers again"

This reverts commit 85c9743.

* make it possible to disable dyn cache; clarify about the static cache which is populated via checkProfilesConsistency

* allow multiple first_match and make names of encoded values even stricter

* non-shared EncodedValue is too complex due to '.' we should use '$' or '__'

* use non-shared encoded values

* test again without cache

* call in-area method only when necessary, improves speed where pre-conditional checks are done like road_class!=PRIMARY && in_area_custom1

* make area names stricter

* already consider parts of the pull request reviews

* Custom weighting helper cleanup (#2211)

* Chain CustomWeighting constructors, use static creator method

* CustomWeighting no longer depends on CustomWeightingHelper

* Extract parameter object for CustomWeighting

* Use SpeedAndAccessProvider interface, add ExpressionBuilderTest

* Change apply -> get

* More fine-grained usage of try statement

* revert DEFAULT to true

* docs: remove confusing statement

* better name for subclass

* no need for the extra line in test

* simple max_speed_fallback handling, still explicit

* migrate to if-then notation

* fix benchmarks for if-then notation

* made Clause methods shorter

* introduce different Op

* merge speed_factor and max_speed into speed via introduced 'multiply with' and 'limit to' operators; cleanup

* further simplify custom model: remove max_speed_fallback

* bug fix

* docs: adapt to know notation

* multiply with -> by

* minor cleanup

* support for StringEncodedValue

* UI fixes for new format; make isSharedEncodedValues method private again

* bug fix for findMaxSpeed calculation

* test perf: disable cache for comparison

* test perf: again

* enable cache to permanently store internal Weighting classes

* uhm, test perf: without cache but push separately

* Revert "uhm, test perf: without cache but push separately"

This reverts commit 6bb9fd0.

* minor improvements

* removed SpeedAndAccessProvider

* make sure that the internal cache will never be too big

* fix package of JaninoCustomWeightingHelperSubclass

* rename ExpressionBuilder to CustomModelParser

* made CustomModelParser parser public and move create method to it from CustomWeighting

* comment regarding internal cache method

* create -> createWeighting

* move CustomModel to different package to hide useInternalCache methods

* limit size of the whole script, not single expressions

* Rename CustomModelParser#create etc.

* minor

* rename internal and throw exception if found in query

* fix contentString

* Improve profiles.md

* Fix road_surface->surface and else: "" -> else: null

* Explain how to use else statement in JSON

* Fix GH maps example

* Warn instead of error in case the edge distance of very long edges differs from way geometry length

(cherry picked from commit dfee21c)

* rename

* error message e.g. in case of encoded value wasn't added

* distanceInfluence: use default value only if not initialized

* less cryptic error message

Co-authored-by: Andi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants