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 = "is_eulerian", abbreviation = "_ie")
020    public class IsEulerian implements GraphReportExtension {
021        public Object calculate(GraphData gd) {
022            GraphModel graph = gd.getGraph();
023            return isEulerian(graph);
024        }
025    
026        /**
027         * @return true if given graph is Eulerian
028         */
029        public static boolean isEulerian(GraphModel graph) {
030            int cc = graph.getVerticesCount();
031            if (cc == 0) return false;
032            if (cc < 2)
033                return true;
034            if (!AlgorithmUtils.isConnected(graph))
035                return false;
036            ArrayList<Integer> degrees = AlgorithmUtils.getDegreesList(graph);
037            for (int d : degrees) {
038                if (d % 2 != 1) return false;
039            }
040            return true;
041        }
042    
043        public String getName() {
044            return "Is Eulerian";
045        }
046    
047        public String getDescription() {
048            return "Is Eulerian";
049        }
050    }