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.reports.basicreports;
006    
007    import graphlab.graph.graph.GraphModel;
008    import graphlab.graph.graph.VertexModel;
009    import graphlab.platform.parameter.Parameter;
010    import graphlab.platform.parameter.Parametrizable;
011    import graphlab.plugins.main.GraphData;
012    import graphlab.plugins.reports.extension.GraphReportExtension;
013    
014    /**
015     * @author azin azadi
016     */
017    
018    public class NumOfVerticesWithDegK implements GraphReportExtension, Parametrizable {
019        @Parameter(name = "K")
020        public static Integer k = 1;
021    
022        public String getName() {
023            return "Number of Vertices with Deg k";
024        }
025    
026        public String getDescription() {
027            return "Number of vertices in the Graph which degrees are k";
028        }
029    
030        public Object calculate(GraphData gd) {
031            int ret = 0;
032    
033            GraphModel g = gd.getGraph();
034            int t = (g.isDirected() ? 1 : 2);
035            for (VertexModel v : g) {
036                if ((g.getInDegree(v) + g.getOutDegree(v)) / t == k)
037                    ret++;
038            }
039            return ret;
040        }
041    
042        public String checkParameters() {
043            return (k < 0 ? "K must be positive" : null);
044        }
045    }