import networkx as nx import matplotlib.pyplot as plt # The keys of bus_stops are bus stops (integers), # and the values are lists of bus routes that have a stop at the bus stop. bus_stops = {} bus_stops[1] - ["541", "542" ] bus_stops(2] ["221", "224"] bus_stops[3] -["542"] bus_stops[4] = ["542", "278"] # ... Full contents of bus_stops not shown ... bus_graph = nx.Graph() target_route Your code goes below here!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

10.

 

The dictionary bus_stops maps integers representing bus stops to a list of the bus routes that stop at the bus stop. Given
target_route, a bus route, write code that:
a) adds appropriate nodes and edges to bus_graph; and
b) then displays the graph.
The nodes of the graph are the bus stops that appear in bus_stops.A node should be added for every bus stop the
provided bus route stops at and edges should be added between adjacent (sequentially increasing) bus stops. Assume that
all buses will start at bus stop 0. Don't forget to call draw_networkx.
For example, given the contents of bus_stops shown below, if the value of target_route was 542, there should be an
edge between 0, 1, 3, and 4 since 542 stops at those stops and begins at bus route 0. Note that there should not be an
edge between 1 and 4, O and 3, or O and 4 since there should only be edges between sequentially increasing bus stop
numbers. The full contents of bus_stops are not shown and your code should work for any contents of bus_stops (e.g.,
do not hard-code in nodes and edges for the bus routes and bus stops shown below)
import networkx as nx
import matplotlib.pyplot as plt
# The keys of bus_stops are bus stops (integers),
# and the values are lists of bus routes that have a stop at the bus stop.
bus_stops
{}
bus_stops [1] = ["541", "542"]
bus_stops[2] = ["221", "224"]
bus_stops[3] =["542"]
bus_stops [4] = ["542", "278"]
# ... Full contents of bus_stops not shown ...
bus_graph
nx.Graph()
target_route
# Your code goes below here!
Enter your answer here
Transcribed Image Text:The dictionary bus_stops maps integers representing bus stops to a list of the bus routes that stop at the bus stop. Given target_route, a bus route, write code that: a) adds appropriate nodes and edges to bus_graph; and b) then displays the graph. The nodes of the graph are the bus stops that appear in bus_stops.A node should be added for every bus stop the provided bus route stops at and edges should be added between adjacent (sequentially increasing) bus stops. Assume that all buses will start at bus stop 0. Don't forget to call draw_networkx. For example, given the contents of bus_stops shown below, if the value of target_route was 542, there should be an edge between 0, 1, 3, and 4 since 542 stops at those stops and begins at bus route 0. Note that there should not be an edge between 1 and 4, O and 3, or O and 4 since there should only be edges between sequentially increasing bus stop numbers. The full contents of bus_stops are not shown and your code should work for any contents of bus_stops (e.g., do not hard-code in nodes and edges for the bus routes and bus stops shown below) import networkx as nx import matplotlib.pyplot as plt # The keys of bus_stops are bus stops (integers), # and the values are lists of bus routes that have a stop at the bus stop. bus_stops {} bus_stops [1] = ["541", "542"] bus_stops[2] = ["221", "224"] bus_stops[3] =["542"] bus_stops [4] = ["542", "278"] # ... Full contents of bus_stops not shown ... bus_graph nx.Graph() target_route # Your code goes below here! Enter your answer here
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY