001 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 002 // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/ 003 package graphlab.plugins.graphgenerator.generators; 004 005 import graphlab.graph.graph.EdgeModel; 006 import graphlab.graph.graph.GraphModel; 007 import graphlab.graph.graph.GraphPoint; 008 import graphlab.graph.graph.VertexModel; 009 import graphlab.platform.parameter.Parameter; 010 import graphlab.platform.parameter.Parametrizable; 011 import graphlab.platform.StaticUtils; 012 import graphlab.platform.lang.CommandAttitude; 013 import graphlab.plugins.graphgenerator.core.PositionGenerators; 014 import graphlab.plugins.graphgenerator.core.extension.GraphGeneratorExtension; 015 016 import java.awt.*; 017 018 @CommandAttitude(name = "generate_banana_tree", abbreviation = "_g_banana", description = "generates a Banana graph") 019 public class BananaTreeGenerator implements GraphGeneratorExtension, Parametrizable { 020 021 //the depth should be positive, and also if it is very large the 022 //generated graph is too large to generate. 023 @Parameter(description = "N") 024 public int n = 3; 025 @Parameter(description = "K") 026 public int k = 3; //num of each star vertices 027 028 029 public String checkParameters() { 030 return null; //the parameters are well defined. 031 } 032 033 public String getName() { 034 return "Banana tree"; 035 } 036 037 public String getDescription() { 038 return "generates a banana tree with n k-stars"; 039 } 040 041 public GraphModel generateGraph() { 042 return generateBananaTree(n, k); 043 } 044 045 public static GraphModel generateBananaTree(int n, int k) { 046 //num of tree vertices 047 int t = (n * k) + 1; 048 GraphModel g = new GraphModel(false); 049 VertexModel root = new VertexModel(); 050 g.insertVertex(root); 051 root.setLocation(new GraphPoint(0, 0)); 052 VertexModel curv = null; 053 //generating edges and setting positions 054 Point[] fR = PositionGenerators.circle(3000, 0, 0, n); 055 VertexModel[] firstDepth = new VertexModel[n]; 056 057 //generating first level vertices 058 for (int i = 0; i < n; i++) { 059 Point center = fR[i]; 060 curv = new VertexModel(); 061 setloc(curv, center); 062 firstDepth[i] = curv; 063 g.insertVertex(curv); 064 g.insertEdge(new EdgeModel(root, curv)); 065 } 066 067 //generating second level vertices 068 for (int i = 0; i < n; i++) { 069 Point center = fR[i]; 070 VertexModel centerv = firstDepth[i]; 071 Point[] sR = PositionGenerators.circle(1000, center.x, center.y, k - 1); 072 for (int j = 0; j < k - 1; j++) { 073 curv = new VertexModel(); 074 g.insertVertex(curv); 075 setloc(curv, sR[j]); 076 g.insertEdge(new EdgeModel(centerv, curv)); 077 } 078 } 079 return g; 080 } 081 082 private static void setloc(VertexModel vv, Point gp) { 083 vv.setLocation(new GraphPoint(gp.x, gp.y)); 084 } 085 086 087 public static void main(String[] args) { 088 graphlab.platform.Application.main(args); 089 StaticUtils.loadSingleExtension(BananaTreeGenerator.class); 090 091 } 092 }