LdDl / ch

Contraction Hierarchies (with bidirectional version of Dijkstra's algorithm) technique for computing shortest path in graph.
Apache License 2.0
46 stars 5 forks source link

[FEATURE REQUEST] Improve export/import functions #14

Closed LdDl closed 3 years ago

LdDl commented 3 years ago

Is your feature request related to a problem? Please describe. Current implementation of Export function is: https://github.com/LdDl/ch/blob/master/export.go#L19 It creates single file with informations about edges and contractions, but no info about vertices' order position and importance. Single CSV-file header:

//      from_vertex_id - int64, ID of source vertex
//      to_vertex_id - int64, ID of arget vertex
//      f_internal - int64, Internal ID of source vertex
//      t_internal - int64, Internal ID of target vertex
//      weight - float64, Weight of an edge
//      via_vertex_id - int64, ID of vertex through which the contraction exists (-1 if no contraction)
//      v_internal - int64, Internal ID of vertex through which the contraction exists (-1 if no contraction)

So after calling Import function we must evaluate every vertex's order position and importance again: this is not cool and can take a long time if graph too big. We need to export information about order position and importance to remove unnecessary calculations inside of Export function

Describe the solution you'd like and provide pseudocode examples if you can Export function has to create 2 files: one is for edges, and second one is for vertices. Edges file:

//      from_vertex_id - int64, ID of source vertex
//      to_vertex_id - int64, ID of arget vertex
//      f_internal - int64, Internal ID of source vertex
//      t_internal - int64, Internal ID of target vertex
//      weight - float64, Weight of an edge
//      via_vertex_id - int64, ID of vertex through which the contraction exists (-1 if no contraction)
//      v_internal - int64, Internal ID of vertex through which the contraction exists (-1 if no contraction)

Vertices file:

// Header of main CSV-file containing information about vertices:
//      vertex_id - int64, ID of vertex
//      internal_id - int64, internal ID of arget vertex
//      order_pos - int, Position of vertex in hierarchies (evaluted by library)
//      importance - int, Importance of vertex in graph (evaluted by library)

Describe alternatives you've considered and provide pseudocode examples if you can We can go even further and export third file: about contractions. So finally we can get such structure: Edges file (only real edges!):

//      from_vertex_id - int64, ID of source vertex
//      to_vertex_id - int64, ID of arget vertex
//      f_internal - int64, Internal ID of source vertex
//      t_internal - int64, Internal ID of target vertex
//      weight - float64, Weight of an edge

Vertices file:

// Header of main CSV-file containing information about vertices:
//      vertex_id - int64, ID of vertex
//      internal_id - int64, internal ID of arget vertex
//      order_pos - int, Position of vertex in hierarchies (evaluted by library)
//      importance - int, Importance of vertex in graph (evaluted by library)

Contractions file:

//      from_vertex_id - int64, ID of source vertex
//      to_vertex_id - int64, ID of arget vertex
//      f_internal - int64, Internal ID of source vertex
//      t_internal - int64, Internal ID of target vertex
//      weight - float64, Weight of an contraction
//      via_vertex_id - int64, ID of vertex through which the contraction exists
//      v_internal - int64, Internal ID of vertex through which the contraction exists

Additional context After moditification of Export function we should make proper update for Import function also. So Import function has to accept 2 (or 3, depends on what we are going to do with contractions) arguments.