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     */
023    @CommandAttitude(name = "generate_pn", abbreviation = "_g_pn")
024    public class PathGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface {
025        @Parameter(name = "N")
026        public static Integer n = 10;
027        VertexModel[] v;
028        GraphModel g;
029    
030        public void setWorkingGraph(GraphModel g) {
031            this.g = g;
032        }
033    
034        public String getName() {
035            return "Path";
036        }
037    
038        public String getDescription() {
039            return "Generates a path with n vertices";
040        }
041    
042        public VertexModel[] getVertices() {
043    
044            VertexModel[] ret = new VertexModel[n];
045            for (int i = 0; i < n; i++)
046                ret[i] = new VertexModel();
047            v = ret;
048            return ret;
049        }
050    
051        public EdgeModel[] getEdges() {
052            EdgeModel[] ret = new EdgeModel[n - 1];
053            for (int i = 0; i < n - 1; i++) {
054                ret[i] = new EdgeModel(v[i], v[i + 1]);
055            }
056            return ret;
057        }
058    
059        public Point[] getVertexPositions() {
060            return PositionGenerators.line(5, 5, 100, 100, n);
061        }
062    
063        public String checkParameters() {
064            return null;
065        }
066    
067        public GraphModel generateGraph() {
068            return GraphGenerator.getGraph(false, this);
069        }
070    
071    
072        /**
073         * generates a Path Graph with given parameters
074         */
075        public static GraphModel generatePath(int n) {
076            PathGenerator.n = n;
077            return GraphGenerator.getGraph(false, new PathGenerator());
078        }
079    }