liveBook · Manning

Queue

As explained in Applied Reinforcement Learning

A queue is a data structure that processes elements in first-in, first-out order.

A queue processes items first in, first out (FIFO): remove the item at the front, then add new items at the back. In breadth-first search, this keeps route choices moving outward one level at a time. section 7.2

Delivery-route search

Breadth-first search queues route nodes from a depot, removes the next node to check it, and adds routes extended by one customer to the back. section 7.2

Listing 7.4 Initialize BFS.
import random
import itertools
 
NODES = ["Depot"] + [f"C{i}" for i in range(1, 10)]  #A
distances = { (a, b):random.randint(5, 20)
   ➥for a in NODES for b in NODES if a != b } #B
 
root = RouteNode(route=["Depot"], cost=0) #C
 
queue = deque([root])  #D
best_route = None #D
best_cost = float('inf') #D

The initialization shows a Python deque holding the root route node. section 7.2

How Applied Reinforcement Learning covers it

How deep it goes
Defines FIFO and explains front-removal and back-addition, without examining queue internals.
Examples
Illustrates queue order with delivery routes extended by successive customer stops.
What you can do after
Apply it via Python's deque to hold nodes during breadth-first traversal.
How it connects
Connects queues to breadth-first search and route-tree exploration.

Also explained in

Compare how 30 books explain queue →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Applied Reinforcement Learning. The section links point to the parts of the book it draws on.