001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.graphgenerator.generators; 005 006 import graphlab.graph.graph.EdgeModel; 007 import graphlab.graph.graph.GraphModel; 008 import graphlab.graph.graph.VertexModel; 009 import graphlab.platform.lang.CommandAttitude; 010 import graphlab.platform.parameter.Parameter; 011 import graphlab.platform.parameter.Parametrizable; 012 import graphlab.plugins.graphgenerator.GraphGenerator; 013 import graphlab.plugins.graphgenerator.core.PositionGenerators; 014 import graphlab.plugins.graphgenerator.core.SimpleGeneratorInterface; 015 import graphlab.plugins.graphgenerator.core.extension.GraphGeneratorExtension; 016 017 import java.awt.*; 018 019 /** 020 * User: root 021 */ 022 @CommandAttitude(name = "generate_sn", abbreviation = "_g_sn") 023 public class StarGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface { 024 @Parameter(name = "S(N) Generator's N") 025 public static Integer n = 10; 026 GraphModel g; 027 VertexModel[] v; 028 029 public void setWorkingGraph(GraphModel g) { 030 this.g = g; 031 } 032 033 public VertexModel[] getVertices() { 034 VertexModel[] ret = new VertexModel[n]; 035 for (int i = 0; i < n; i++) 036 ret[i] = new VertexModel(); 037 v = ret; 038 return ret; 039 } 040 041 public EdgeModel[] getEdges() { 042 EdgeModel[] ret = new EdgeModel[n - 1]; 043 for (int i = 1; i < n; i++) { 044 ret[i - 1] = new EdgeModel(v[0], v[i]); 045 } 046 return ret; 047 } 048 049 public Point[] getVertexPositions() { 050 Point[] ret = new Point[n]; 051 Point[] points = PositionGenerators.circle(5, 5, 100, 100, n - 1); 052 System.arraycopy(points, 0, ret, 1, n - 1); 053 ret[0] = new Point(100 / 2, 100 / 2); 054 return ret; 055 } 056 057 public String getName() { 058 return "Star"; 059 } 060 061 public String getDescription() { 062 return "Generates a star"; 063 } 064 065 public String checkParameters() { 066 return null; 067 } 068 069 public GraphModel generateGraph() { 070 return GraphGenerator.getGraph(false, this); 071 } 072 073 /** 074 * generates a Star Graph with given parameters 075 */ 076 public static GraphModel generateStar(int n) { 077 StarGenerator.n = n; 078 return GraphGenerator.getGraph(false, new StarGenerator()); 079 } 080 081 }