Skip to content

Modifying The Algorithm

Tim Baccaert edited this page Jul 27, 2017 · 5 revisions

The algorithm is contained within several files across the application. But from a top-down perspective you can find them in the following order:

  • server/interface/routes.py - request handling & controls the algorithm, modifier fiddling can be done here
  • server/logic/routing/routing.py - has useful calls to graph.py
  • server/logic/graph/graph.py - CFFI layer above the Rust shared object file
  • lib/interface/src/lib.rs - interface for the rust code, has some lower level algorithm tweaking capabilities
  • lib/graph/src/graph/graph.rs - actual implementation of the algorithm
  • lib/graph/src/graph/dijkstra.rs - actual implementation of the algorithm
  • lib/graph/src/graph/graphtrait.rs - actual implementation of the algorithm
  • and a couple of others which are less likely to be useful to you

Modifying POI/Rating impact

This can all be done inside the server/interface/routes.py file. Inside the function generate(request) you can go up to the function calculate_modifier(edge) where you can change the way the modifier is calculated. You have to provide separate formulas for bad and good tags. Bad tags should make an edge less attractive and good tags should make an edge more attractive to the algorithm.

Modifying other aspects of the algorithm

You can do most other tweaks in the lib/interface/src/lib.rs file. There's a function generate_route<G : GraphTrait<V=Node, E=Edge>>(graph : &'static G, start_node : usize, config : Configuration) -> DijkstraIterator which creates a DijkstraIterator. The function that creates this iterator accepts 2 closures called map_fn and filter_fn . You can use map_fn for edge manipulation and you can use filter_fn to limit edges in size. There's also something similar in the Python code called map_graph in the server/logic/graph/graph.py file that does this on the python level, however I would refrain from using it all over the place cause it imposes a bigger penalty on performance. It's currently used for modifier calculation and the initialization of the graph.

Known bugs

In the lib/interface/lib.rs modifier function you should consider changing the edge.modifier to be an additive modifier rather than a multiplicative one since this will solve a class of bugs related to edges with a single POI.

Partners

imec - IDLab - Ghent University

Clone this wiki locally