graphbrewer v0.1.0 Priorityqueue

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

Link to this type heuristic_costs()
heuristic_costs() :: non_neg_integer()
Link to this type key()
key() :: atom()
Link to this type path_costs()
path_costs() :: non_neg_integer()
Link to this type t()
t() :: %Priorityqueue{entries: %{optional(key()) => %{pcosts: path_costs(), hcosts: heuristic_costs(), tcosts: total_costs()}}}
Link to this type total_costs()
total_costs() :: non_neg_integer()

Link to this section Functions

Link to this function new()
new() :: t()

Returns a new struct of PriorityQueue with zero entries.

iex(15)> Priorityqueue.new %Priorityqueue{entries: %{}}

Link to this function pop(pq)
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}}

Link to this function push(pq, node, prop)
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}}}