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.plugins.main.GraphData; 010 import graphlab.plugins.reports.extension.GraphReportExtension; 011 012 public class OrderOneReport implements GraphReportExtension { 013 public String getName() { 014 return "order one"; 015 } 016 017 public String getDescription() { 018 return "Number of vertices with degree 1"; 019 } 020 021 public Object calculate(GraphData gd) { 022 int ret = 0; 023 GraphModel graph = gd.getGraph(); 024 for (VertexModel v : graph) { 025 if (graph.getInDegree(v) + graph.getOutDegree(v) == 1) { 026 ret++; 027 } 028 } 029 return ret; 030 } 031 }