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    import java.util.Vector;
019    
020    /**
021     *
022     */
023    
024    @CommandAttitude(name = "generate_knd", abbreviation = "_g_knd")
025    public class KenserGraphGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface {
026        @Parameter(name = "D")
027        public static Integer d = 3;
028        @Parameter(name = "N")
029        public static Integer n = 4;
030        GraphModel g;
031    
032        public void setWorkingGraph(GraphModel g) {
033            this.g = g;
034        }
035    
036        VertexModel[] v;
037    
038        public VertexModel[] getVertices() {
039            VertexModel[] ret = new VertexModel[n];
040            for (int i = 0; i < n; i++)
041                ret[i] = new VertexModel();
042            v = ret;
043            return ret;
044        }
045    
046        public EdgeModel[] getEdges() {
047            Vector<EdgeModel> ret = new Vector<EdgeModel>();
048            for (int i = 0; i < n; i++) {
049                for (int j = i; j < (Math.min(n, i + d)); j++) {
050                    ret.add(new EdgeModel(v[i], v[j]));
051                }
052            }
053            EdgeModel[] ret1 = new EdgeModel[ret.size()];
054    
055            for (int i = 0; i < ret.size(); i++) {
056                ret1[i] = ret.get(i);
057            }
058    
059            return ret1;
060        }
061    
062        public Point[] getVertexPositions() {
063            return PositionGenerators.circle(5, 5, 100, 100, n);
064        }
065    
066        public String getName() {
067            return "K(n/d)";
068        }
069    
070        public String getDescription() {
071            return "Generate K(n/d)";
072        }
073    
074        public String checkParameters() {
075            return null;
076        }
077    
078        public GraphModel generateGraph() {
079            return GraphGenerator.getGraph(false, this);
080        }
081    
082        /**
083         * generates a kenser Graph with given parameters
084         */
085        public static GraphModel generateKenserGraph(int n, int d) {
086            KenserGraphGenerator.n = n;
087            KenserGraphGenerator.d = d;
088            return GraphGenerator.getGraph(false, new KenserGraphGenerator());
089        }
090    
091    
092    }