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    
005    package graphlab.plugins.graphgenerator.generators;
006    
007    import graphlab.graph.graph.EdgeModel;
008    import graphlab.graph.graph.GraphModel;
009    import graphlab.graph.graph.VertexModel;
010    import graphlab.platform.lang.CommandAttitude;
011    import graphlab.platform.parameter.Parameter;
012    import graphlab.platform.parameter.Parametrizable;
013    import graphlab.platform.StaticUtils;
014    import graphlab.plugins.graphgenerator.GraphGenerator;
015    import graphlab.plugins.graphgenerator.core.PositionGenerators;
016    import graphlab.plugins.graphgenerator.core.SimpleGeneratorInterface;
017    import graphlab.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
018    
019    import java.awt.*;
020    
021    /**
022     * Author: Saman Feghhi
023     * 
024     */
025    @CommandAttitude(name = "generate_kmno", abbreviation = "_g_kmno", description = "generates a Tripartite complete graph")
026    public class KmnoGenerator implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface
027    {
028    
029            @Parameter(name = "M")
030            public static int m = 3;
031    
032            @Parameter(name = "N")
033            public static int n = 3;
034    
035            @Parameter(name = "O")
036            public static int o = 3;
037    
038            GraphModel g;
039    
040            public void setWorkingGraph(GraphModel g)
041            {
042                    this.g = g;
043            }
044    
045            public String getName()
046            {
047                    return "Km,n,o";
048            }
049    
050            public String getDescription()
051            {
052                    return "Generate Km,n,o";
053            }
054    
055            VertexModel[] v;
056    
057            public VertexModel[] getVertices()
058            {
059                    VertexModel[] ret = new VertexModel[m + n + o];
060                    for (int i = 0; i < m + n + o; i++)
061                            ret[i] = new VertexModel();
062                    v = ret;
063                    return ret;
064            }
065    
066            public EdgeModel[] getEdges()
067            {
068                    EdgeModel[] ret = new EdgeModel[m * n + m * o + n * o];
069                    for (int i = 0; i < m; i++)
070                            for (int j = 0; j < n + o; j++)
071                                    ret[i * ( n + o ) + j] = new EdgeModel(v[i], v[m + j]);
072                    for (int i = 0; i < n; i++)
073                            for (int j = 0; j < o; j++)
074                                    ret[m * ( n + o ) + o * i + j] = new EdgeModel(v[m + i], v[m + n + j]);
075                    return ret;
076            }
077    
078            public Point[] getVertexPositions()
079            {
080                    int w = 1000, h = 1000;
081                    Point ret[] = new Point[m + n + o];
082                    int dx = 0, dy = 0;
083    
084                    if(m == 1)
085                            ret[0] = new Point(150, 260);
086                    else
087                    {
088                            dx = -300/(m - 1);
089                            dy = 520/(m - 1);
090                            for (int i = 0; i < m; i++)
091                                    ret[i] = new Point(300 + i * dx, i * dy);
092                    }
093    
094                    if(n == 1)
095                            ret[m] = new Point(850, 260);
096                    else
097                    {
098                            dx = 300/(n - 1);
099                            dy = 520/(n - 1);
100                            for (int i = 0; i < n; i++)
101                                    ret[m + i] = new Point(700 + i * dx, i * dy);
102                    }
103    
104                    if (o == 1)
105                            ret[m + n] = new Point(500, 800);
106                    else
107                    {
108                            dx = 600/(o - 1);
109                            dy = 0;
110                            for (int i = 0; i < o; i++)
111                                    ret[m + n + i] = new Point(200 + i * dx, 800 + i * dy);
112                    }
113    
114                    return ret;
115            }
116    
117            public String checkParameters()
118            {
119                    return null;
120            }
121    
122            public GraphModel generateGraph()
123            {
124                    return GraphGenerator.getGraph(false, this);
125            }
126    
127            /**
128             * generates a Km,n,o Graph with given parameters
129             */
130            public static GraphModel generateKmno(int m, int n, int o)
131            {
132                    KmnoGenerator.m = m;
133                    KmnoGenerator.n = n;
134                    KmnoGenerator.o = o;
135                    return GraphGenerator.getGraph(false, new KmnoGenerator());
136            }
137    
138        public static void main(String[] args) {
139            graphlab.platform.Application.main(args);
140            StaticUtils.loadSingleExtension(KmnoGenerator.class);
141    
142        }
143    }