Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in python please! Connections between airports can be modelled as a graph. The nodes represent airports and the edges represent direct flight routes between two
in python please!
Connections between airports can be modelled as a graph. The nodes represent airports and the edges represent direct flight routes between two airports. Two nodes are connected by a edge if there is a direct flight between the two airports (for simplicity we assume that if there is a direct flight from airport X to airport Y, then there is also a direct flight from airport Y to airport X). The matrix direct_flights represents a network of 100 US airports as described above. We ask you to determine the number routes to get from O'Hare Airport (ORD) to Los Angeles International Airport (LAX) either directly or with one layover. 1) Compute a 100 x 100-matrix A such that the entry in the i-th row and the j-th column of A is the number of walks from node i to node ; of length at most 2. Store this matrix as atmost_1_layover. 2) Assuming that ORD is airport # 29 (the 30th row/column of the adjacency matrix when one-indexing) and LAX is airport # 89 (the 90 th row/column of the adjacency matrix when one-indexing). Find the number of ways of flying from ORD to LAX either directly or with one layover. Save this as num_options. The setup code gives the following variables: Name Type Description Network of direct connections, 100 x 100 adjacency matrix direct_flights numpy array Your code snippet should define the following variables: Name Type Description atmost_1_layover numpy array Network of connections with one layover, 100 x 100 adjacency matrix num_options integer Number of routes from ORD to LAX with at most one layover Connections between airports can be modelled as a graph. The nodes represent airports and the edges represent direct flight routes between two airports. Two nodes are connected by a edge if there is a direct flight between the two airports (for simplicity we assume that if there is a direct flight from airport X to airport Y, then there is also a direct flight from airport Y to airport X). The matrix direct_flights represents a network of 100 US airports as described above. We ask you to determine the number routes to get from O'Hare Airport (ORD) to Los Angeles International Airport (LAX) either directly or with one layover. 1) Compute a 100 x 100-matrix A such that the entry in the i-th row and the j-th column of A is the number of walks from node i to node ; of length at most 2. Store this matrix as atmost_1_layover. 2) Assuming that ORD is airport # 29 (the 30th row/column of the adjacency matrix when one-indexing) and LAX is airport # 89 (the 90 th row/column of the adjacency matrix when one-indexing). Find the number of ways of flying from ORD to LAX either directly or with one layover. Save this as num_options. The setup code gives the following variables: Name Type Description Network of direct connections, 100 x 100 adjacency matrix direct_flights numpy array Your code snippet should define the following variables: Name Type Description atmost_1_layover numpy array Network of connections with one layover, 100 x 100 adjacency matrix num_options integer Number of routes from ORD to LAX with at most one layoverStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started