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.extensions.reports;
006    
007    import graphlab.plugins.main.GraphData;
008    import graphlab.plugins.reports.extension.GraphReportExtension;
009    
010    /**
011     * @author Azin Azadi
012     */
013    public class ChromaticNumber implements GraphReportExtension, ColoringListener {
014    
015        public String getName() {
016            return "Chromatic Number";
017        }
018    
019        public String getDescription() {
020            return "The chromatic number of graph";
021        }
022    
023        Partitioner p;
024        int ct;
025        boolean found;
026    
027        public Object calculate(GraphData gd) {
028            p = new Partitioner(gd.getGraph());
029            ct = 1;
030            found = false;
031            while (!found) {
032                found = isColorable(ct++);
033            }
034            return ct;
035        }
036    
037        public boolean isColorable(int t) {
038            return p.findAllPartitionings(t, this);
039        }
040    
041        public boolean coloringFound(final int t) {
042            found = true;
043            return true;
044        }
045    }