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.samples.extensions; 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 public class OrderKReport implements GraphReportExtension, Parametrizable { 015 //you can set a (display) name and a description for the parameter, this is optional. 016 @Parameter(name = "k", description = "the degree of desired vertices") 017 public int k; 018 019 020 public String checkParameters() { 021 if (k <= 0) return "K must be positive"; 022 else 023 return null; 024 } 025 026 public String getName() { 027 return "order k"; 028 } 029 030 public String getDescription() { 031 return "Number of vertices with degree k"; 032 } 033 034 public Object calculate(GraphData gd) { 035 int ret = 0; 036 GraphModel graph = gd.getGraph(); 037 for (VertexModel v : graph) { 038 if (graph.getInDegree(v) + graph.getOutDegree(v) == k) { 039 ret++; 040 } 041 } 042 return ret; 043 } 044 045 }