can someone please explain to me in details what does every function in this code do ?
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
class Graph(object): J - J J F - -1 J -1 import sys J - def __init__(self, nodes, init_graph): self.nodes = nodes self.graph = self.construct_graph(nodes, init_graph) def construct_graph(self, nodes, init_graph): This method makes sure that the graph is symmetrical. In other words, if there's graph = {} for node in nodes: graph [node] = {} graph.update (init_graph) for node, edges in graph.items(): for adjacent_node, value in edges.items(): if graph[adjacent_node].get(node False) == False: graph [adjacent_node] [node] = value return graph def get_nodes (self): "Returns the nodes of the graph." return self.nodes def get_outgoing_edges(self, node): "Returns the neighbors of a node." connections = [] for out_node in self.nodes: if self.graph[node].get(out_node, False) != False: connections.append(out_node) return connections - def value(self, node1, node2): "Returns the value of an edge between two nodes." return self.graph [node1] [node2] def dijkstra_algorithm (graph, start_node): class Graph(object): J - J J F - -1 J -1 import sys J - def __init__(self, nodes, init_graph): self.nodes = nodes self.graph = self.construct_graph(nodes, init_graph) def construct_graph(self, nodes, init_graph): This method makes sure that the graph is symmetrical. In other words, if there's graph = {} for node in nodes: graph [node] = {} graph.update (init_graph) for node, edges in graph.items(): for adjacent_node, value in edges.items(): if graph[adjacent_node].get(node False) == False: graph [adjacent_node] [node] = value return graph def get_nodes (self): "Returns the nodes of the graph." return self.nodes def get_outgoing_edges(self, node): "Returns the neighbors of a node." connections = [] for out_node in self.nodes: if self.graph[node].get(out_node, False) != False: connections.append(out_node) return connections - def value(self, node1, node2): "Returns the value of an edge between two nodes." return self.graph [node1] [node2] def dijkstra_algorithm (graph, start_node):
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
How many objects are eligible for garbage collection at the end of the main() method? A. None. B. One. C. Two. D. Three. E. The code does not compile. F. None of the above. package store; public...
-
After watching the presentation titled The Sacred/Secular Divide, interact with your classmates by discussing the following questions: How does the tendency to push religion away from the public...
-
More U.S. law originates from one country than from any other. Which country? (a) France (b) England (c) Germany (d) Spain (e) Canada
-
Cheese Please Ltd produces cheese topping for the fast pizza industry. At the beginning of April, 20 000 kilograms of cheese topping was in process, 100% complete as to raw materials and 60% complete...
-
Rapture Corporation had the following transactions. 1. Issued $200,000 of bonds payable. 2. Paid utilities expense. 3. Issued 500 shares of preferred stock for $45,000. 4. Sold land and a building...
-
Problem 4. A thin-walled cylindrical tank, under internal pressure, p, is compressed by a force, F = 75 kN. The inner diameter of the cylinder is d = 90 mm, and the wall thickness, t = 5.5 mm. The...
-
Alpha and Beta are divisions within the same company. The managers of both divisions are evaluated based on their own divisions return on investment (ROI). Assume the following information relative...
-
Briefly describe static linking and dynamic linking. Include the advantages and disadvantages of dynamic linking over static linking. Describe a Windows DLL. Write a DLL and export the function void...
-
Often, within the United States, people tend to talk about supply chain management in healthcare without truly considering what those words mean. Supply chain management can directly impact costs,...
-
Mr. Ibrahim is a deputy sales director for a multinational company operating in the Arab region. He has just been told that his salesperson "Sami" has been stealing from the company by submitting...
-
Are the number and influence of domestic safety regulations increasing or decreasing in the motor carrier industry? Are the number and influence of domestic environmental regulations increasing or...
-
The market of notebooks assumes that S&D is the domestic supply and demand curve and that the world price is PW, identify the area representing the government revenue when a Tariff raises the...
-
In the final week of the course, you synthesize the knowledge of health care costs, revenue, and expenses, along with the underlying economic drivers of these considerations to evaluate ways to...
-
A force of 5N is inclined at an angle of 45 to a second force of 8N, both forces acting at a point. Calculate the magnitude of the resultant of these two forces and the direction of the resultant...
-
How has the too-big-to-fail policy been limited in the FDICIA legislation? How might limiting the too-big-to-fail policy help reduce the risk of a future banking crisis?
-
Matthew borrows $250,000 to invest in bonds. During 2012, his interest on the loan is $30,000. Matthew's interest income from the bonds is $10,000. This is Matthew's only investment income. a....
-
If Charles, a 16-year-old child model, earns $50,000 a year and is completely self supporting even though he lives with his parents, can his parents claim him as a dependent? Why or why not?...
-
Robert Ramos (age 36) is a single taxpayer, living at 8765 Bay Dr., Monterey, CA 93940. His Social Security number is 976-23-5132. Robert's earnings and income tax withholding as the manager of a...
-
What is the glass ceiling?
-
1. Whole Foods is a natural and organic foods retailer started by John Mackey and Renee Lawson in 1978. The company is headquartered in Austin, Texas. Today it operates 456 stores in the United...
-
This stagecoach likely makes a stop near you. Wells Fargo \& Company owns Wells Fargo Bank, which is one of the largest banks in the US with more than 8,800 bank branches in 40-plus states. Community...
Study smarter with the SolutionInn App