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.plugins.graphgenerator.GraphGenerator;
011    import graphlab.plugins.graphgenerator.core.PositionGenerators;
012    
013    import java.awt.*;
014    
015    /**
016     * @author azin azadi
017    
018     */
019    @CommandAttitude(name = "generate_cn", abbreviation = "_g_cn", description = "generated a Circle with n vertices")
020    public class CircleGenerator extends PathGenerator {
021    
022        public String getName() {
023            return "Circle";
024        }
025    
026        public String getDescription() {
027            return "Genrates a Circle(Cn)";
028        }
029    
030        @Override
031        public EdgeModel[] getEdges() {
032            EdgeModel[] pre = super.getEdges();
033            int l = pre.length;
034            EdgeModel[] ret = new EdgeModel[l + 1];
035            System.arraycopy(pre, 0, ret, 0, l);
036            ret[l] = new EdgeModel(v[l], v[0]);
037            return ret;
038        }
039    
040        public VertexModel[] getVertices() {
041    
042            VertexModel[] ret = new VertexModel[n];
043            for (int i = 0; i < n; i++)
044                ret[i] = new VertexModel();
045            v = ret;
046            return ret;
047        }
048    
049        public GraphModel generateGraph() {
050            return GraphGenerator.getGraph(false, this);
051        }
052    
053        public Point[] getVertexPositions() {
054            return PositionGenerators.line(5, 5, 100, 100, n);
055        }
056    
057        /**
058         * generates a Circle Graph with given parameters
059         */
060        public static GraphModel generateCircle(int n) {
061            CircleGenerator.n = n;
062            return GraphGenerator.getGraph(false, new CircleGenerator());
063        }
064    
065    }