Documentation ¶
Index ¶
- Constants
- Variables
- type Distance
- type Graph
- func (graph *Graph) AddEdge(from, to int64, weight float64) error
- func (graph *Graph) AddShortcut(from, to, via int64, weight float64) error
- func (graph *Graph) AddTurnRestriction(from, via, to int64) error
- func (graph *Graph) ComputePath(middleID int64, forwardPrev, backwardPrev map[int64]int64) []int64
- func (graph *Graph) CreateVertex(label int64) error
- func (graph *Graph) ExportEdgesToFile(fname string) error
- func (graph *Graph) ExportShortcutsToFile(fname string) error
- func (graph *Graph) ExportToFile(fname string) error
- func (graph *Graph) ExportVerticesToFile(fname string) error
- func (graph *Graph) FindVertex(labelExternal int64) (idx int64, ok bool)
- func (graph *Graph) Freeze()
- func (graph *Graph) GetEdgesNum() int64
- func (graph *Graph) GetShortcutsNum() int64
- func (graph *Graph) GetVerticesNum() int64
- func (graph *Graph) ImportRestrictionsFromFile(fname string) error
- func (graph *Graph) Isochrones(source int64, maxCost float64) (map[int64]float64, error)
- func (graph *Graph) PrepareContractionHierarchies()
- func (graph *Graph) Preprocess(pqImportance *importanceHeap)
- func (graph *Graph) SetVerbose(flag bool)
- func (graph *Graph) ShortestPath(source, target int64) (float64, []int64)
- func (graph *Graph) ShortestPathManyToMany(sources, targets []int64) ([][]float64, [][][]int64)
- func (graph *Graph) ShortestPathManyToManyWithAlternatives(sourcesAlternatives, targetsAlternatives [][]VertexAlternative) ([][]float64, [][][]int64)
- func (graph *Graph) ShortestPathOneToMany(source int64, targets []int64) ([]float64, [][]int64)
- func (graph *Graph) ShortestPathOneToManyWithAlternatives(sourceAlternatives []VertexAlternative, ...) ([]float64, [][]int64)
- func (graph *Graph) ShortestPathWithAlternatives(sources, targets []VertexAlternative) (float64, []int64)
- func (graph *Graph) Unfreeze()
- func (graph *Graph) VanillaShortestPath(source, target int64) (float64, []int64)
- func (graph *Graph) VanillaTurnRestrictedShortestPath(source, target int64) (float64, []int64)
- type ShortcutPath
- type Vertex
- type VertexAlternative
Constants ¶
const (
Infinity = float64(^uint(0) >> 1)
)
Variables ¶
var ( // ErrGraphIsFrozen Graph is frozen, so it can not be modified. ErrGraphIsFrozen = fmt.Errorf("Graph has been frozen") )
Functions ¶
This section is empty.
Types ¶
type Distance ¶
type Distance struct {
// contains filtered or unexported fields
}
Distance Information about contraction between source vertex and contraction vertex distance - used in Dijkstra local searches previousOrderPos - previous contraction order (shortest path tree) previousSourceID - previously found source vertex (shortest path tree)
type Graph ¶
type Graph struct { Vertices []Vertex // contains filtered or unexported fields }
Graph Graph object
mapping Internal map for 1:1 relation of internal IDs to user's IDs Vertices Slice of vertices of graph shortcuts Found and stored shortcuts based on contraction hierarchies
func ImportFromFile ¶
ImportFromFile Imports graph (prepared by ExportToFile(fname string) function) from file of CSV-format Header of CSV-file containing information about edges:
from_vertex_id - int64, ID of source vertex to_vertex_id - int64, ID of arget vertex weight - float64, Weight of an edge
Header of CSV-file containing information about vertices:
vertex_id - int64, ID of vertex order_pos - int, Position of vertex in hierarchies (evaluted by library) importance - int, Importance of vertex in graph (evaluted by library)
Header of CSV-file containing information about shortcuts between vertices:
from_vertex_id - int64, ID of source vertex to_vertex_id - int64, ID of target vertex weight - float64, Weight of an shortcut via_vertex_id - int64, ID of vertex through which the shortcut exists
func NewGraph ¶ added in v1.7.8
func NewGraph() *Graph
NewGraph returns pointer to created Graph and does preallocations for processing purposes
func (*Graph) AddEdge ¶
AddEdge Adds new edge between two vertices
from User's definied ID of first vertex of edge to User's definied ID of last vertex of edge weight User's definied weight of edge
func (*Graph) AddShortcut ¶ added in v1.7.5
AddShortcut Adds new shortcut between two vertices
from - User's definied ID of first vertex of shortcut to - User's definied ID of last vertex of shortcut via - User's defined ID of vertex through which the shortcut exists weight - User's definied weight of shortcut
func (*Graph) AddTurnRestriction ¶ added in v1.2.0
AddTurnRestriction Adds new turn restriction between two vertices via some other vertex
from User's definied ID of source vertex via User's definied ID of prohibited vertex (between source and target) to User's definied ID of target vertex
func (*Graph) ComputePath ¶
ComputePath Returns slice of IDs (user defined) of computed path
func (*Graph) CreateVertex ¶
CreateVertex Creates new vertex and assign internal ID to it
label User's definied ID of vertex
func (*Graph) ExportEdgesToFile ¶ added in v1.7.5
ExportVerticesToFile Exports edges information to CSV-file with header:
from_vertex_id - int64, ID of source vertex to_vertex_id - int64, ID of target vertex weight - float64, Weight of an edge
func (*Graph) ExportShortcutsToFile ¶ added in v1.7.5
ExportShortcutsToFile Exports shortcuts information to CSV-file with header:
from_vertex_id - int64, ID of source vertex to_vertex_id - int64, ID of target vertex weight - float64, Weight of an shortcut via_vertex_id - int64, ID of vertex through which the shortcut exists
func (*Graph) ExportToFile ¶
ExportToFile Exports graph to file of CSV-format Header of edges CSV-file:
from_vertex_id - int64, ID of source vertex to_vertex_id - int64, ID of target vertex weight - float64, Weight of an edge
Header of vertices CSV-file:
vertex_id - int64, ID of vertex order_pos - int, Position of vertex in hierarchies (evaluted by library) importance - int, Importance of vertex in graph (evaluted by library)
Header of shortcuts CSV-file:
from_vertex_id - int64, ID of source vertex to_vertex_id - int64, ID of target vertex weight - float64, Weight of an shortcut via_vertex_id - int64, ID of vertex through which the shortcut exists
func (*Graph) ExportVerticesToFile ¶ added in v1.7.5
ExportVerticesToFile Exports vertices information to CSV-file with header:
vertex_id - int64, ID of vertex order_pos - int, Position of vertex in hierarchies (evaluted by library) importance - int, Importance of vertex in graph (evaluted by library)
func (*Graph) FindVertex ¶ added in v1.7.3
FindVertex Returns index of vertex in graph
labelExternal - User defined ID of vertex If vertex is not found then returns (-1; false)
func (*Graph) Freeze ¶ added in v1.5.0
func (graph *Graph) Freeze()
Freeze Freeze graph. Should be called after contraction hierarchies had been prepared.
func (*Graph) GetEdgesNum ¶ added in v1.7.7
GetEdgesNum Returns number of edges in graph
func (*Graph) GetShortcutsNum ¶ added in v1.7.7
GetShortcutsNum Returns number of shortcuts in graph
func (*Graph) GetVerticesNum ¶ added in v1.7.7
GetVerticesNum Returns number of vertices in graph
func (*Graph) ImportRestrictionsFromFile ¶ added in v1.2.1
ImportRestrictionsFromFile Imports turn restrictions from file of CSV-format into graph
Header of CSV-file: from_vertex_id;via_vertex_id;to_vertex_id; int;int;int
func (*Graph) Isochrones ¶ added in v1.6.0
Isochrones Returns set of vertices and corresponding distances restricted by maximum travel cost for source vertex source - source vertex (user defined label) maxCost - restriction on travel cost for breadth search See ref. https://wiki.openstreetmap.org/wiki/Isochrone and https://en.wikipedia.org/wiki/Isochrone_map Note: implemented breadth-first searching path algorithm does not guarantee shortest pathes to reachable vertices (until all edges have cost 1.0). See ref: https://en.wikipedia.org/wiki/Breadth-first_search Note: result for estimated costs could be also inconsistent due nature of data structure
func (*Graph) PrepareContractionHierarchies ¶ added in v1.7.2
func (graph *Graph) PrepareContractionHierarchies()
PrepareContractionHierarchies Compute contraction hierarchies
func (*Graph) Preprocess ¶
func (graph *Graph) Preprocess(pqImportance *importanceHeap)
Preprocess Computes contraction hierarchies and returns node ordering
func (*Graph) SetVerbose ¶ added in v1.7.8
SetVerbose sets verbose parameter for debugging purposes
func (*Graph) ShortestPath ¶
ShortestPath Computes and returns shortest path and it's cost (extended Dijkstra's algorithm)
If there are some errors then function returns '-1.0' as cost and nil as shortest path
source - user's definied ID of source vertex target - user's definied ID of target vertex
func (*Graph) ShortestPathManyToMany ¶ added in v1.7.8
ShortestPathManyToMany computes and returns shortest paths and theirs's costs (extended Dijkstra's algorithm) between multiple sources and targets
If there are some errors then function returns '-1.0' as cost and nil as shortest path
sources - set of user's definied IDs of source vertices targets - set of user's definied IDs of target vertices
func (*Graph) ShortestPathManyToManyWithAlternatives ¶ added in v1.7.8
func (graph *Graph) ShortestPathManyToManyWithAlternatives(sourcesAlternatives, targetsAlternatives [][]VertexAlternative) ([][]float64, [][][]int64)
ShortestPathManyToManyWithAlternatives Computes and returns shortest paths and their cost (extended Dijkstra's algorithm), with multiple alternatives for source and target vertices with additional distances to reach the vertices (useful if source and target are outside of the graph)
If there are some errors then function returns '-1.0' as cost and nil as shortest path
sourcesAlternatives - set of user's definied IDs of source vertices with additional penalty targetsAlternatives - set of user's definied IDs of target vertices with additional penalty
func (*Graph) ShortestPathOneToMany ¶ added in v1.2.8
ShortestPathOneToMany computes and returns shortest paths and theirs's costs (extended Dijkstra's algorithm) between single source and multiple targets
If there are some errors then function returns '-1.0' as cost and nil as shortest path
source - user's definied ID of source vertex targets - set of user's definied IDs of target vertices
func (*Graph) ShortestPathOneToManyWithAlternatives ¶ added in v1.7.8
func (graph *Graph) ShortestPathOneToManyWithAlternatives(sourceAlternatives []VertexAlternative, targetsAlternatives [][]VertexAlternative) ([]float64, [][]int64)
ShortestPathOneToManyWithAlternatives Computes and returns shortest path and it's cost (extended Dijkstra's algorithm) between single source and multiple targets with multiple alternatives for source and target vertices with additional distances to reach the vertices (useful if source and target are outside of the graph)
If there are some errors then function returns '-1.0' as cost and nil as shortest path
sourceAlternatives - user's definied ID of source vertex with additional penalty targetsAlternatives - set of user's definied IDs of target vertices with additional penalty
func (*Graph) ShortestPathWithAlternatives ¶ added in v1.7.8
func (graph *Graph) ShortestPathWithAlternatives(sources, targets []VertexAlternative) (float64, []int64)
ShortestPathWithAlternatives Computes and returns shortest path and it's cost (extended Dijkstra's algorithm), with multiple alternatives for source and target vertices with additional distances to reach the vertices (useful if source and target are outside of the graph)
If there are some errors then function returns '-1.0' as cost and nil as shortest path
sources - user's definied ID of source vertex with additional penalty targets - user's definied ID of target vertex with additional penalty
func (*Graph) Unfreeze ¶ added in v1.5.0
func (graph *Graph) Unfreeze()
Unfreeze Freeze graph. Should be called if graph modification is needed.
func (*Graph) VanillaShortestPath ¶
VanillaShortestPath Computes and returns shortest path and it's cost (vanilla Dijkstra's algorithm)
If there are some errors then function returns '-1.0' as cost and nil as shortest path
source User's definied ID of source vertex target User's definied ID of target vertex
func (*Graph) VanillaTurnRestrictedShortestPath ¶ added in v1.2.0
VanillaTurnRestrictedShortestPath Computes and returns turns restricted shortest path and it's cost (vanilla Dijkstra's algorithm)
If there are some errors then function returns '-1.0' as cost and nil as shortest path
source User's definied ID of source vertex target User's definied ID of target vertex
type ShortcutPath ¶ added in v1.7.7
ShortcutPath Representation of shortcut between vertices
From - ID of source vertex To - ID of target vertex ViaVertex - ID of vertex through which the shortcut exists Cost - summary cost of path between two vertices
type Vertex ¶
type Vertex struct { Label int64 // contains filtered or unexported fields }
Vertex All information about vertex
func (*Vertex) Importance ¶ added in v1.7.0
Importance Returns importance (in terms of contraction hierarchies) of vertex
func (*Vertex) OrderPos ¶ added in v1.7.0
OrderPos Returns order position (in terms of contraction hierarchies) of vertex
func (*Vertex) SetImportance ¶ added in v1.7.0
SetImportance Sets order position (in terms of contraction hierarchies) for vertex
func (*Vertex) SetOrderPos ¶ added in v1.7.0
SetOrderPos Sets order position (in terms of contraction hierarchies) for vertex
type VertexAlternative ¶ added in v1.7.8
Source Files ¶
- bidirectional_ch_n_to_n.go
- bidirectional_ch_one_to_n.go
- contraction.go
- dijkstra_bidirectional.go
- dijkstra_local.go
- errors.go
- export.go
- graph.go
- heap_dist.go
- heap_importance.go
- heap_min.go
- heap_typed.go
- import.go
- incident_edge.go
- isochrones.go
- shortcut.go
- vanilla_dijkstra.go
- vanilla_dijkstra_turn_restricted.go
- vertex.go
- vertex_alternatives.go