EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
Python代写
您的位置: 主页 > 编程案例 > Python代写 >
代写Python:code代写 Dijkstra’s algorithm代写 functions代写 - Python代写
发布时间:2021-07-25 21:36:52浏览次数:
MATH1058 coursework [40% of the total marks]Python code代写 Shortest Path Length (SPL): given a directed graph tt = (V, A), two nodes s, t V , and a length function A : A R+Consider the following problem:Shortest Path Length (SPL): given a directed graph tt = (V, A), two nodes s, t  V , and a length function A : A   R+, find the length of a shortest s–t   path.Python code代写In this coursework, you are asked to write a Python code which implements   two variants of Dijkstra’s algorithm for the solution of SPL, run your code to produce data on how the two variants behave in terms of computing time as the size of the graph increases, analyze this data in Excel, and, finally, write up your findings in LaTeX. The LaTeX report is conceived to be similar to a research paper, albeit in a smaller scale.Python Python code代写Write a Python script dijkstra.py containing two functions, dijkstra1() and dijkstra2(), capable of computing the length of a shortest path between the   first node of the graph (0) and a second node other_node supplied as input.Note that, in this activity, we are only interested in the length of a shortest path, rather than in which arcs it contains. The functions should have two inputs: the successors list of the graph, successors, and the destination node other_node.Assume that successors is implemented as a list of dictionaries where, for all i in V, successors[i] is a dictionary whose keys are the indices of the nodes adjacent to node i and whose values are the lengths of the arcs from i to such nodes.The function dijkstra1() should contain an implementation of Dijkstra’s algo- rithm in the version seen in the lectures (which solves the “Single Source Shortest Path” problem by computing the shortest path length between 0 and each other node in the graph), modified to return, at the very end of the algorithm, the length of a shortest path between s=0 and t=other_node.Python code代写The function dijkstra2() should contain a modified implementation  which,  after the destination node other_node has been reached, halts the execution of the algorithm (this is correct; do you see why?). Its return value should be the same as dijkstra1().Comparing the practical efficiency of these two versions of the algorithm is the main aim of this activity.Notes on the implementation Python code代写Consider the following example of a successors listsuccessors  =  [{1  :  2,  2  :  5},{2 : 3},{3 : 4},{0  :  21,  1:  8}]which encodes the graph reported in Figure~1.Figure 1: Graph represented by successorsAs an example of how to navigate a graph encoded with this data structure,  given a Python variable  v  equal  to  the  index  of  a  node  v  V  of  the  graph, you can loop over the forward star of v (called δ+( v )inthelectures) with the following code:for w, lvw in successors[v].items():print( node , w, is a successor of node , v) print( the length of the corresponding arc is , lvw)Suggestion: compute the shortest paths  from  node  0  to  each  other  node  in the previous graph on a piece of paper, and check in Python whether your implementations produce the correct results. You could also construct a larger graph and test them there.Python code代写Data generationDownload   the   file   graph_generation.py   from   Blackboard   and   im- port it (with import graph_generation) in your script dijkstra.py. graph_generation.py contains a function graph_timings() which, given as inputthename of a function (written by you) containing an implementation of an algorithm for the solution of the SPL problem to be tested (dijkstra1() or dijkstra2())your(8 digit) student IDgenerates a set of graphs (based on your ID) and runs the supplied implementa- tions (dijkstra1() or dijkstra2()) on all of them. The function not only runs  the supplied implementation, but also measures the amount of microseconds taken to compute the shortest path length between node s=0 and each other node t=other_node in the graph, recording it in an Excel file (see further).Python code代写You can run the function on both implementations with:graph_generation.generate_timings(`dijkstra1`,  ID) graph_generation.generate_timings(`dijkstra2`,  ID)When running, the function produces an output similar to this one:Your implementation named dijkstra1 will be run on a total of 8 graphs Working on graph number 1 of size n = |V| = 8 and m = |A| = 12Python code代写Working on graph number 2 of size n = |V| = 16 and m = |A|  =  56 Working on graph number 3 of size n = |V| = 16 and m = |A|  =  24 Working on graph number 4 of size n = |V| = 32 and m = |A| = 112 Working on graph number 5 of size n = |V| = 24 and m = |A|  =  36 Working on graph number 6 of size n = |V| = 48 and m = |A| = 168 Working on graph number 7 of size n = |V| = 32 and m = |A|  =  48 Working on graph number 8 of size n = |V| = 64 and m = |A| = 224Excel Python code代写When called as specified before, generate_timings() produces two .xls files: dijkstra1_data.xls and dijkstra2_data.xls. Each  of  them  features  a  col- umn for each graph on which the experiments have been run, containing:thenumber of nodes in the graph n = |V|thenumber of arcs in the graph m = |A|exactlyn-1 rows reporting the computing time (in microseconds) measured when running the implementation you supplied as input on each of the  n-1 nodes in V different from 0.You are asked to create a new spreadsheet called analysis.xls. To begin with, it should contain the following quantities, for each graph:the average time (we will call it “empirical time” from now on, omitting “average”)taken by each of the two implementations of Dijkstra’s algorithm you wrotethe theoretical complexity of Dijkstra’s algorithm (in the version of the algorithm seen in the lectures), computed as a function of the number of nodesPython code代写Analysis Python code代写Let y1 and y2 be the empirical computing time of one of the two implementations as measured by generate_timings() (and then averaged by you on each graph) and let n = |V | be the number of nodes of the graph.PartI:Youare asked to estimate two functions, namely, y1 = c1nk1 and y2 = c2nk2 , corresponding to the empirical computing time of, respectively, dijkstra1() and dijkstra2(), from the data you haveThis can be done by linear (actually,  affine) regression.  Indeed,  for  n,k, c   0, y = cnk implies log y = log c + k log n; letting yr := log y and nr := log n, we deduce yr = log c + knr; one could, therefore, plot yr versus nr and, then, infer k and log c (respectively, slope intercept of the affine function yr = log c + knr) by affineIn Excel, slope and intercept of an affine function can be estimated with the functions SLOPE andINTERCEPT.

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。