1 / 11

Project P9 Graphs

Project P9 Graphs. CS1050: Understanding and Constructing Proofs. Spring 2006. Jarek Rossignac. Objectives. Learn how to represent, display, and traverse graphs. Learn how to compute a vertex spanniging tree Learn how to compute the topological distance between two nodes. Graph editor.

mura
Download Presentation

Project P9 Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Project P9Graphs CS1050: Understanding and Constructing Proofs Spring 2006 Jarek Rossignac

  2. Objectives • Learn how to represent, display, and traverse graphs. • Learn how to compute a vertex spanniging tree • Learn how to compute the topological distance between two nodes

  3. Graph editor To Load a graph: click in the graphic window and press "l". To add an edge: click the start point and drag to the end point These will be snapped to existing points if close enough. To move a point, click and drag it while pressing the space bar To toggle the display of point numbers: press "n" To resize and recenter: press "f" When run locally in Processing To save the graph: press "s" To make a picture: press "i"

  4. Assignment P9, individual • Modify the code as indicated to compute the Vertex Spanning Tree with vertex 0 as root and set the color of its edges and vertices to not 0. • Post on your PPP: • the image showing the result of your algorithm on the graph provided • the piece of the code that computes the coloring of the VST edges and vertices (with comments) • a discussion of its time complexity • a link to your source code • the applet to run your source codeyour source code

  5. Compute spanning tree by growing • Start from seed and grow by layers

  6. 18 points col[0]=1 (141,518) col[1]=2 (43,216) col[2]=3 (300,30) col[3]=3 (556,216) col[4]=2 (458,518) col[5]=2 (298,443) col[6]=2 (169.0,381.0) col[7]=3 (150.0,280.0) col[8]=3 (409.0,398.0) col[9]=3 (292.0,317.0) col[10]=4 (278.0,203.0) col[11]=4 (401.0,259.0) col[12]=4 (404.0,183.0) col[13]=4 (315.0,130.0) col[14]=4 (182.0,185.0) col[15]=5 (457.0,321.0) col[16]=6 (481.0,257.0) col[17]=5 (217.0,126.0) 30 edges col[0]=1 (0,1) col[1]=1 (1,2) col[2]=0 (2,3) col[3]=1 (3,4) col[4]=1 (4,0) col[5]=1 (0,5) col[6]=1 (6,0) col[7]=0 (6,5) col[8]=1 (7,6) col[9]=1 (8,5) col[10]=1 (6,9) col[11]=0 (5,9) col[12]=0 (8,4) col[13]=0 (7,9) col[14]=0 (8,9) col[15]=1 (9,10) col[16]=0 (10,7) col[17]=1 (9,11) col[18]=0 (10,11) col[19]=0 (11,8) col[20]=0 (11,12) col[21]=1 (12,3) col[22]=1 (2,13) col[23]=0 (13,12) col[24]=0 (13,10) Colors of points and edges col[25]=0 (10,14) col[26]=1 (11,15) col[27]=1 (15,16) col[28]=1 (14,17) col[29]=1 (14,7)

  7. Declarations int vn =5; // initial number of vertices int en =5; // initial number of edges int cap=128; // max nuber of edges and vertices pt[] P = new pt [cap]; // points edge[] E = new edge[cap]; // edges int [] colEdge = new int[cap]; // colors of edges int [] colVert = new int[cap]; // colors of points int mj=10; // user-controlled limit on depth of vertex spanning tree

  8. Set up void setup() { size(600, 600); // window size PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); for (int i=0; i<cap; i++) { // clear vertices, edges, colors P[i]=new pt(0,0); E[i]=new edge(0,0); colEdge[i]=0; colVert[i]=0;}; for (int i=0; i<vn; i++) { P[i].setFromValues(-sin((i+0.5)*TWO_PI/vn)* (width*0.45)+width/2.0,cos((i+0.5)*TWO_PI/vn)* (height*0.45)+height/2.0);}; for (int i=0; i<vn; i++) {E[i].setFromValues(i,in(i)); }; VST(); // vertex-spanning-tree }

  9. VST void VST() { // colors of edges and points in VSY // insert your code here // my placeholder code just to have something (please delete) for (int i=0; i<vn; i++) {colVert[i]=0;}; // resets vertex colors for (int i=0; i<en; i++) {colEdge[i]=0;}; // resets edge colors colVert[0]=1; // seeds the VST root at vertex for (int i=0; i<en; i++) { if(i%2==1) { colEdge[i]=1; colVert[E[i].s]=1; colVert[E[i].e]=1;};}; // changes colors of odd edges and their vertices }

  10. Edge class class edge{ int s,e; edge (int ps, int pe) {s = ps; e = pe;}; edge makeCopy() {return(new edge(s,e));}; void setFromValues(int ps, int pe) {s = ps; e = pe;}; void show() { line(P[s].x,P[s].y,P[e].x,P[e].y);}; void write() {println("("+s+","+e+")");}; }

  11. Results

More Related