graphbrewer v0.1.7 Priorityqueue
The prioriy queue is used by the shortest path algorithm of the Graph
module. It keeps all the nodes that are to be evaluated and determines which node is to evaluated next.
As the name suggests it works as a queue. So the main methods are push
for adding an entry and pop
for getting the next one.
Link to this section Summary
Functions
Returns a new struct of PriorityQueue
with zero entries
Returns the next item in the queue. As the shortest path algorithm uses the principle of the a star algorithm, the queue returns the element with the lowest costs. In detail, the function returns the updated priority queue, the key (the node) of the element to be evaluated next and the data of that element
Adds a new entry to an existing priority queue. The entry must contain the path costs to the node, the costs of the latest hop to the node, the heuristic costs of the node and the node from which the added one is reached (needed for reconstructing the path later on)
Link to this section Types
t() :: %Priorityqueue{ entries: %{ optional(key()) => %{ pcosts: path_costs(), hcosts: heuristic_costs(), tcosts: to_costs(), from: node_id() } } }
Link to this section Functions
Returns a new struct of PriorityQueue
with zero entries.
Example
iex(15)> Priorityqueue.new
%Priorityqueue {entries: %{}}
pop(t()) :: {t(), key(), %{ costs_heur: heuristic_costs(), costs_hop: path_costs(), costs_to: path_costs(), from: key() }}
Returns the next item in the queue. As the shortest path algorithm uses the principle of the a star algorithm, the queue returns the element with the lowest costs. In detail, the function returns the updated priority queue, the key (the node) of the element to be evaluated next and the data of that element.
Example
iex> Priorityqueue.new |> Priorityqueue.push(:a, %{costs_to: 15, costs_hop: 3, costs_heur: 4, from: :s}) |> Priorityqueue.push(:b, %{costs_to: 10, costs_hop: 4, costs_heur: 3, from: :s}) |>
...> Priorityqueue.pop
{%Priorityqueue {entries: %{a: %{costs_heur: 4, costs_hop: 3, costs_to: 15, from: :s}}}, :b, %{costs_heur: 3, costs_hop: 4, costs_to: 10, from: :s}}
push(t(), key(), %{ costs_to: path_costs(), costs_hop: path_costs(), costs_heur: heuristic_costs(), from: key() }) :: t()
Adds a new entry to an existing priority queue. The entry must contain the path costs to the node, the costs of the latest hop to the node, the heuristic costs of the node and the node from which the added one is reached (needed for reconstructing the path later on).
Example
iex> pq = Priorityqueue.new |> Priorityqueue.push(:a, %{costs_to: 15, costs_hop: 3, costs_heur: 4, from: :s})
%Priorityqueue {entries: %{a: %{costs_heur: 4, costs_hop: 3, costs_to: 15, from: :s}}}