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     * User: Houshmand
021     */
022    @CommandAttitude(name = "generate_cmn", abbreviation = "_g_cmn", description = "generates Cm * Cn")
023    public class CmnGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface {
024        @Parameter(name = "M")
025        public static Integer m = 3;
026    
027        @Parameter(name = "N")
028        public static Integer n = 5;
029        GraphModel g;
030    
031        public void setWorkingGraph(GraphModel g) {
032            this.g = g;
033        }
034    
035        VertexModel[] v;
036    
037        public VertexModel[] getVertices() {
038            VertexModel[] ret = new VertexModel[n * m];
039            for (int i = 0; i < m * n; i++)
040                ret[i] = new VertexModel();
041            v = ret;
042            return ret;
043        }
044    
045        public EdgeModel[] getEdges() {
046            EdgeModel[] ret = new EdgeModel[2 * m * n];
047            int counter = 0;
048            for (int i = 0; i < n; i++) {
049                for (int j = 0; j < m; j++) {
050                    if (j > m - 2) ret[counter] = new EdgeModel(v[i * m + j], v[i * m]);
051                    else ret[counter] = new EdgeModel(v[i * m + j], v[i * m + j + 1]);
052                    counter++;
053                }
054            }
055            for (int i = 0; i < n; i++) {
056                for (int j = 0; j < m; j++) {
057                    if (i > n - 2) ret[counter] = new EdgeModel(v[i * m + j], v[j]);
058                    else ret[counter] = new EdgeModel(v[i * m + j], v[(i + 1) * m + j]);
059                    counter++;
060                }
061            }
062    
063    
064            return ret;
065        }
066    
067        public Point[] getVertexPositions() {
068            Point ret[] = new Point[m * n];
069            Point centerPoints[] = PositionGenerators.circle(0, 0, m * n, m * n, n);
070            for (int i = 0; i < n; i++) {
071                Point p[] = PositionGenerators.circle(m, centerPoints[i].x, centerPoints[i].y, m);
072                System.arraycopy(p, 0, ret, i * m, m);
073            }
074    
075    
076            return ret;
077        }
078    
079        public String getName() {
080            return "Cm * Cn";
081        }
082    
083        public String getDescription() {
084            return "Generate Cm*Cn";
085        }
086    
087        public String checkParameters() {
088            return null;
089        }
090    
091        public GraphModel generateGraph() {
092            return GraphGenerator.getGraph(false, this);
093        }
094    
095        /**
096         * generates a Cm*Cn Graph with given parameters
097         */
098        public static GraphModel generateCmn(int m, int n) {
099            CmnGenerator.m = m;
100            CmnGenerator.n = n;
101            return GraphGenerator.getGraph(false, new CmnGenerator());
102        }
103    }
104