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.platform.lang.CommandAttitude;
009    import graphlab.plugins.main.GraphData;
010    import graphlab.plugins.main.core.AlgorithmUtils;
011    import graphlab.plugins.reports.extension.GraphReportExtension;
012    
013    import java.util.ArrayList;
014    
015    /**
016     * @author Mohammad Ali Rostami
017     */
018    
019    @CommandAttitude(name = "max_and_min_degree", abbreviation = "_mmd")
020    public class MaxAndMinDegree implements GraphReportExtension {
021        public Object calculate(GraphData gd) {
022            GraphModel graph = gd.getGraph();
023            return maxAndMinDegree(graph);
024        }
025    
026        /**
027         * @return maximum and minimum degree of the given graph in the first and second index of an arraylist
028         */
029        private ArrayList<Integer> maxAndMinDegree(GraphModel graph) {
030            int maxDegree = 0, minDegree = AlgorithmUtils.Max_Int;
031            for (int d : AlgorithmUtils.getDegreesList(graph)) {
032                if (d > maxDegree) maxDegree = d;
033                if (d < minDegree) minDegree = d;
034            }
035            if (minDegree == AlgorithmUtils.Max_Int) minDegree = 0;
036            ArrayList<Integer> ret = new ArrayList<Integer>();
037            ret.add(maxDegree);
038            ret.add(minDegree);
039            return ret;
040        }
041    
042        public String getName() {
043            return "Max and Min Degree";
044        }
045    
046        public String getDescription() {
047            return "max and min degree of graph";
048        }
049    }