001    package graphlab.plugins.graphgenerator.generators;
002    // GraphLab Project: http://graphlab.sharif.edu
003    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
004    // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
005    
006    import graphlab.graph.graph.EdgeModel;
007    import graphlab.graph.graph.GraphModel;
008    import graphlab.graph.graph.GraphPoint;
009    import graphlab.graph.graph.VertexModel;
010    import graphlab.platform.lang.BoundedInteger;
011    import graphlab.platform.lang.CommandAttitude;
012    import graphlab.platform.parameter.Parameter;
013    import graphlab.platform.parameter.Parametrizable;
014    import graphlab.platform.StaticUtils;
015    import graphlab.plugins.graphgenerator.core.PositionGenerators;
016    import graphlab.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
017    
018    import java.awt.*;
019    
020    @CommandAttitude(name = "generate_helmn", abbreviation = "_g_prism", description = "generates a Prism graph of order n")
021    public class PrismGraph implements GraphGeneratorExtension, Parametrizable {
022    
023        //the depth should be positive, and also if it is very large the
024        //generated graph is too large to generate.
025        //@Parameter(description = "depth of the tree")
026        //public BoundedInteger depth = new BoundedInteger(3, 15, 1);
027        @Parameter(description = "n")
028        public static int n = 4;      //num of vertices
029    
030    
031        public String checkParameters() {
032            //d = depth.getValue();
033            //n = (int) (Math.pow(2, d + 1) - 1);
034            return null;    //the parameters are well defined.
035        }
036    
037        public String getName() {
038            return "Prism Graph";
039        }
040    
041        public String getDescription() {
042            return "generates a binary tree";
043        }
044    
045        public GraphPoint[] getVertexPositions() {
046            Point[] r = new Point[2 * n];
047    
048            Point p1[] = PositionGenerators.circle(20, 10, 10,  n);
049            Point p2[] = PositionGenerators.circle(30, 10, 10,  n);
050            System.out.println(p2[0]);
051            for (int i = 0; i < n; i++) {
052                r[i] = p1[i];
053                r[n + i] = p2[i];
054            }
055    
056            GraphPoint ret[] = new GraphPoint[2 * n];
057            for (int i = 0; i < 2 * n; i++) {
058                ret[i] = new GraphPoint(r[i].x, r[i].y);
059            }
060            return ret;
061        }
062    
063        public GraphModel generateGraph() {
064            GraphModel g = new GraphModel(false);
065            VertexModel[] v = new VertexModel[2 * n];
066            EdgeModel[] e = new EdgeModel[3 * n];
067    
068            //generating vertices
069            for (int i = 0; i < 2 * n; i++)
070                v[i] = new VertexModel();
071    
072            //generating edges
073            for (int i = 0; i < n; i++) {
074                e[i] = new EdgeModel(v[i], v[(i + 1) % n]);
075                if ((i + n + 1) == 2 * n) e[i + n] = new EdgeModel(v[i + n], v[n]);
076                else e[i + n] = new EdgeModel(v[i + n], v[i + n + 1]);
077                e[i + (2 * n)] = new EdgeModel(v[i], v[(i + n)]);
078            }
079    
080            g.insertVertices(v);
081            g.insertEdges(e);
082    
083            //generating and setting vertex positions
084            GraphPoint[] pos = getVertexPositions();
085            for (int i = 0; i < 2*n; i++)
086                v[i].setLocation(pos[i]);
087            return g;
088        }
089    
090    
091        public static void main(String[] args) {
092            graphlab.platform.Application.main(args);
093    //        StaticUtils.loadSingleExtension(graphlab.samples.extensions.PrismGraph.class);
094        }
095    
096    }