/** * Empty constructor. */ public CBGraph() { getNodeTable().addColumns(LABEL_SCHEMA); getEdgeTable().addColumns(EDGE_SCHEMA); }
/** * @see prefuse.data.Graph#createLinkTable() */ protected Table createLinkTable() { Table links = super.createLinkTable(); links.addColumns(TREE_LINKS_SCHEMA); return links; }
public static Graph getHoneycomb(int levels) { Graph g = new Graph(); g.getNodeTable().addColumns(LABEL_SCHEMA); ArrayList layer1 = halfcomb(g, levels); ArrayList layer2 = halfcomb(g, levels); for ( int i=0; i<(levels<<1); ++i ) { Node n1 = (Node)layer1.get(i); Node n2 = (Node)layer2.get(i); g.addEdge(n1, n2); } return g; }
/** * Builds a completely unconnected (edge-free) graph with the given * number of nodes * @param n the number of nodes * @return a graph with n nodes and no edges */ public static Graph getNodes(int n) { Graph g = new Graph(); g.getNodeTable().addColumns(LABEL_SCHEMA); for ( int i=0; i < n; i++ ) { Node node = g.addNode(); node.setString(LABEL, String.valueOf(i)); } return g; }
/** * Returns a clique of given size. A clique is a graph in which every node * is a neighbor of every other node. * @param n the number of nodes in the graph * @return a clique of size n */ public static Graph getClique(int n) { Graph g = new Graph(); g.getNodeTable().addColumns(LABEL_SCHEMA); Node nodes[] = new Node[n]; for ( int i = 0; i < n; ++i ) { nodes[i] = g.addNode(); nodes[i].setString(LABEL, String.valueOf(i)); } for ( int i = 0; i < n; ++i ) { for ( int j = i; j < n; ++j ) if ( i != j ) g.addEdge(nodes[i], nodes[j]); } return g; }
/** * Returns a left deep binary tree * @param depth the depth of the tree * @return the generated tree */ public static Tree getLeftDeepTree(int depth) { Tree t = new Tree(); t.getNodeTable().addColumns(LABEL_SCHEMA); Node r = t.addRoot(); r.setString(LABEL, "0,0"); deepHelper(t, r, 2, depth, true); return t; }
/** * Returns a right deep binary tree * @param depth the depth of the tree * @return the generated Tree */ public static Tree getRightDeepTree(int depth) { Tree t = new Tree(); t.getNodeTable().addColumns(LABEL_SCHEMA); Node r = t.addRoot(); r.setString(LABEL, "0,0"); deepHelper(t, r, 2, depth, false); return t; }
/** * Returns a balanced tree of the requested breadth and depth. * @param breadth the breadth of each level of the tree * @param depth the depth of the tree * @return a balanced tree */ public static Tree getBalancedTree(int breadth, int depth) { Tree t = new Tree(); t.getNodeTable().addColumns(LABEL_SCHEMA); Node r = t.addRoot(); r.setString(LABEL, "0,0"); if ( depth > 0 ) balancedHelper(t, r, breadth, depth-1); return t; }
/** * Returns a graph structured as an m-by-n grid. * @param m the number of rows of the grid * @param n the number of columns of the grid * @return an m-by-n grid structured graph */ public static Graph getGrid(int m, int n) { Graph g = new Graph(); g.getNodeTable().addColumns(LABEL_SCHEMA); Node[] nodes = new Node[m*n]; for ( int i = 0; i < m*n; ++i ) { nodes[i] = g.addNode(); nodes[i].setString(LABEL, String.valueOf(i)); if ( i >= n ) g.addEdge(nodes[i-n], nodes[i]); if ( i % n != 0 ) g.addEdge(nodes[i-1], nodes[i]); } return g; }
/** * Builds a "star" graph with one central hub connected to the given * number of satellite nodes. * @param n the number of points of the star * @return a "star" graph with n points, for a total of n+1 nodes */ public static Graph getStar(int n) { Graph g = new Graph(); g.getNodeTable().addColumns(LABEL_SCHEMA); Node r = g.addNode(); r.setString(LABEL, "0"); for ( int i=1; i <= n; ++i ) { Node nn = g.addNode(); nn.setString(LABEL, String.valueOf(i)); g.addEdge(r, nn); } return g; }
t.getNodeTable().addColumns(LABEL_SCHEMA);