var table; var xaxis = []; var yaxis = []; var vertices = []; var xvertices = []; var yvertices = []; var edges = []; place_nodes_x = []; place_nodes_y = []; var V; var k; var t = -1; function preload() { //my table is comma separated value "csv“ and has a header specifying the columns labels table = loadTable('a3980edges.csv', 'csv'); } function setup() { //count the columns var width = 2000, height = 2000, margin = 20, w = width - 2 * margin, h = height - 2 * margin; createCanvas(width, height); for (var i = 0; i < table.getRowCount(); i++) { yaxis[i] = table.getNum(i, 2); xaxis[i] = table.getNum(i, 1); if(!xvertices.includes(table.getNum(i, 1))){ xvertices.push(table.getNum(i, 1)); } if(!yvertices.includes(table.getNum(i, 2))){ yvertices.push(table.getNum(i, 2)); } } xvertices.sort(function(a, b){return a-b}); yvertices.sort(function(a, b){return a-b}); minx = min(xaxis); miny = min(yaxis); maxx = max(xaxis); maxy = max(yaxis); V = xvertices.length; place_nodes_x = create_random_array(V, 50, 700); place_nodes_y = create_random_array(V, 50, 700); area = width*height; print(area, V); // var myVertex = new vertex(2, 3, 4, 5); // var myVertex2 = new vertex(10, 10, 10, 10); // var myEdge = new edge(myVertex, myVertex2); // var ans = delta(myVertex, myVertex2); // var check = new vector(3, 4); // // console.log(absolute_value(check)); // // console.log(ans); //Graph Algorithm Setup k = Math.sqrt(area/V); print(k); for (var i = 0; i < V; i++) { vertices.push(new vertex(0, 0, place_nodes_x[i], place_nodes_y[i], xvertices[i])); } for (var i = 0; i < xaxis.length; i++) { v1 = xlookup(xaxis[i]); v2 = xlookup(yaxis[i]); edges.push(new edge(v1, v2)); } // console.log(edges); // noLoop(); } function draw(){ background(255); shift = 10; //randomly disperse nodes for (var i = 0; i < vertices.length; i++) { fill('aqua'); ellipse(vertices[i].pos.x, vertices[i].pos.y, 10, 10); if (mouseX<=vertices[i].pos.x+shift && mouseX>=vertices[i].pos.x-shift && mouseY<=vertices[i].pos.y+shift && mouseY>=vertices[i].pos.y-shift){ fill("black"); pos_string=""+vertices[i].value; text(pos_string,mouseX,mouseY);fill("pink"); } } for (var i = 0; i < edges.length; i++) { stroke('grey');strokeWeight(1); if ((mouseX<=edges[i].v1.pos.x+shift && mouseX>=edges[i].v1.pos.x-shift && mouseY<=edges[i].v1.pos.y+shift && mouseY>=edges[i].v1.pos.y-shift) || (mouseX<=edges[i].v2.pos.x+shift && mouseX>=edges[i].v2.pos.x-shift && mouseY<=edges[i].v2.pos.y+shift && mouseY>=edges[i].v2.pos.y-shift)){ stroke('black');strokeWeight(3); } else { stroke('grey'); } line(edges[i].v1.pos.x, edges[i].v1.pos.y, edges[i].v2.pos.x, edges[i].v2.pos.y); } stroke('black');strokeWeight(1); for (var i = 0; i < edges.length; i++) { stroke('grey'); line(edges[i].v1.pos.x, edges[i].v1.pos.y, edges[i].v2.pos.x, edges[i].v2.pos.y); } stroke('black'); for (var i = 0; i < 5; i++) { graph_algorithm(); // t = cool(t); } } function create_random_array(num_elements,min,max) { var nums = new Array; for (var element=0; element