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 * @author azin azadi 021 */ 022 @CommandAttitude(name = "generate_kn", abbreviation = "_g_kn", description = "Generates a complete graph with n vertices") 023 public class CompleteGraphGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface { 024 GraphModel g; 025 @Parameter(name = "n") 026 public static Integer n = 3; 027 028 public void setWorkingGraph(GraphModel g) { 029 this.g = g; 030 } 031 032 VertexModel[] v; 033 034 public VertexModel[] getVertices() { 035 VertexModel[] ret = new VertexModel[n]; 036 for (int i = 0; i < n; i++) 037 ret[i] = new VertexModel(); 038 v = ret; 039 return ret; 040 } 041 042 public EdgeModel[] getEdges() { 043 EdgeModel[] ret = new EdgeModel[n * (n - 1) / 2]; 044 int t = 0; 045 for (int i = 0; i < n; i++) 046 for (int j = 0; j < i; j++) { 047 ret[t++] = new EdgeModel(v[i], v[j]); 048 } 049 return ret; 050 } 051 052 public Point[] getVertexPositions() { 053 return PositionGenerators.circle(5, 5, 100000, 100000, n); 054 } 055 056 public String getName() { 057 return "Complete Graph"; 058 } 059 060 public String getDescription() { 061 return "Generates a Complete Graph"; 062 } 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 Complete Graph with given parameters 075 */ 076 public static GraphModel generateCompleteGraph(int n) { 077 CompleteGraphGenerator.n = n; 078 return GraphGenerator.getGraph(false, new CompleteGraphGenerator()); 079 } 080 }