Skip to content

Refactor Path class #1110

Open
Open

Description

@karussell

Currently we cannot avoid edge extraction required for stuff like in #904. Also the path class does too much and after #1091 will do a bit more. @boldtrn maybe you can also think about a good API approach how you would write #1091 if you would implement it from scratch to find a better solution.

Furthermore I'm currently trying to refactor a bigger portion of the code to make the DataFlagEncoder obsolete and replace it by 'bit-range' objects (which could be shared between encoders or we could even live completely without encoders - just encoding manager, weighting and a few properties). But while doing this the Path class turns out to depend on the FlagEncoder which should not be and instead it should rely on the EncodingManager, which isn't easily possible as the Algorithm objects only know the weighting. Hence a further reason to refactor this class.

Maybe the end result could be something like:

ShortestPathTree tree = algo.createTree(request);
List<String> propertiesToExtract = Arrays.asList("times", "distances", "instructions", "surface", "highway");
PathDetails pathDetails = tree.extract(encodingManager, propertiesToExtract);
// then support methods like getDistance& getDistances, getTime&getTimes, getInstructions(), getEdges, getNodes
// and some more generic ones like: getDetails("surface"), getDetails("highway"), ...
// TODO what about the path merging? Maybe we should call the extract step after all trees are merged?

Activity

  1. boldtrn commented on Jul 14, 2017

    @boldtrn
    Member

    @boldtrn maybe you can also think about a good API approach how you would write #1091 if you would implement it from scratch to find a better solution.

    Sure :). I always feel like the Path class could be threaded with a chain of responsibilty pattern, like a PipeLine that enriches the object itself. But we could still keep the Visitor pattern (forEveryEdge) to actually process the edges. Haven't thought this through though, there might be some pitfalls here.

    Maybe the end result could be something like

    I think this should be possible. We could probably do the same for instructions and maybe a couple more things?

  2. karussell commented on May 12, 2018

    @karussell
    MemberAuthor

    For #1112 we would also benefit from this refactoring. But separating SPT and extract is not sufficient. Instead we would need to be able to store "scalar" values that we 'already have' in the Path class like weight (or time or transfers or ticket costs or toll costs) and return this directly so that there is an actual speed up if no geometry and no instructions were requested.

    For some implementations of RoutingAlgorithm e.g. for AlternativeRoute we call extract as part of the implementation and so a second call of extract should not fail (as it does now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions