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 005 package graphlab.plugins.graphgenerator.generators; 006 007 import graphlab.graph.graph.EdgeModel; 008 import graphlab.graph.graph.GraphModel; 009 import graphlab.graph.graph.VertexModel; 010 import graphlab.platform.lang.CommandAttitude; 011 import graphlab.platform.parameter.Parameter; 012 import graphlab.platform.parameter.Parametrizable; 013 import graphlab.plugins.graphgenerator.GraphGenerator; 014 import graphlab.plugins.graphgenerator.core.PositionGenerators; 015 import graphlab.plugins.graphgenerator.core.SimpleGeneratorInterface; 016 import graphlab.plugins.graphgenerator.core.extension.GraphGeneratorExtension; 017 018 import java.awt.*; 019 020 /** 021 * @author Mohammad Ali Rostami 022 * @email ma.rostami@yahoo.com 023 */ 024 @CommandAttitude(name = "generate_wheel", abbreviation = "_g_w" 025 , description = "generate a n vertices wheel graph") 026 public class WheelGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface { 027 private GraphModel g; 028 @Parameter(name = "n") 029 public static Integer n = 5; 030 private VertexModel[] v; 031 032 public String getName() { 033 return "Wheel Graph"; 034 } 035 036 public String getDescription() { 037 return "Wheel Graph"; 038 } 039 040 public void setWorkingGraph(GraphModel g) { 041 this.g = g; 042 } 043 044 public VertexModel[] getVertices() { 045 VertexModel[] ret = new VertexModel[n]; 046 for (int i = 0; i < n; i++) 047 ret[i] = new VertexModel(); 048 this.v = ret; 049 return ret; 050 } 051 052 public EdgeModel[] getEdges() { 053 EdgeModel[] ret = new EdgeModel[2 * n - 2]; 054 int counter = 0; 055 for (int i = 1; i < n - 1; i++) { 056 ret[counter] = new EdgeModel(v[i], v[i + 1]); 057 counter++; 058 } 059 060 ret[counter] = new EdgeModel(v[n - 1], v[1]); 061 counter++; 062 063 for (int i = 1; i < n; i++) { 064 ret[counter] = new EdgeModel(v[0], v[i]); 065 counter++; 066 } 067 return ret; 068 } 069 070 public Point[] getVertexPositions() { 071 Point p[] = new Point[n]; 072 Point p1[] = PositionGenerators.circle(500, 200, 200, n - 1); 073 Point p2 = new Point(200, 200); 074 System.arraycopy(p1, 0, p, 1, n - 1); 075 p[0] = p2; 076 return p; 077 } 078 079 public String checkParameters() { 080 return null; 081 } 082 083 public GraphModel generateGraph() { 084 return GraphGenerator.getGraph(false, this); 085 } 086 087 /** 088 * generates a Wheel Graph with given parameters 089 */ 090 public static GraphModel generateWheel(int n) { 091 WheelGenerator.n = n; 092 return GraphGenerator.getGraph(false, new WheelGenerator()); 093 } 094 095 }