Beispiel #1
0
        public Result Test(StreamWriter tw, int graphSize, double saturation, bool useBrute)
        {
            Result res   = new Result();
            Graph  graph = RandomGraph.GenerateGraph(graphSize, saturation);

            res.vertices = graphSize;
            res.edges    = graph.EdgesCount;

            int[]     result;
            long      elapsedMs;
            Stopwatch watch;

            if (useBrute)
            {
                watch  = System.Diagnostics.Stopwatch.StartNew();
                result = BruteForce.Solve(ref graph);
                watch.Stop();
                elapsedMs = watch.ElapsedMilliseconds;
                bool tmp = graph.IsColoringValid();
                res.bruteChromaticNum = graph.ChromaticNumber();
                res.bruteTimeMs       = elapsedMs;
                res.bruteValid        = graph.IsColoringValid();
            }

            watch  = System.Diagnostics.Stopwatch.StartNew();
            result = SmallestLast.Solve(ref graph);
            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;
            res.smallestlastChromaticNum = graph.ChromaticNumber();
            res.smallestlastTimeMs       = elapsedMs;
            res.smallestlastValid        = graph.IsColoringValid();

            watch  = System.Diagnostics.Stopwatch.StartNew();
            result = DSatur.Solve(ref graph);
            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;
            res.dsaturChromaticNum = graph.ChromaticNumber();
            res.dsaturTimeMs       = elapsedMs;
            res.dsaturValid        = graph.IsColoringValid();

            watch  = System.Diagnostics.Stopwatch.StartNew();
            result = BFSColoring.Solve(ref graph);
            watch.Stop();
            elapsedMs           = watch.ElapsedMilliseconds;
            res.bfsChromaticNum = graph.ChromaticNumber();
            res.bfsTimeMs       = elapsedMs;
            res.bfsValid        = graph.IsColoringValid();

            tw.WriteLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12};{13};", res.bruteTimeMs, res.bruteChromaticNum, res.bruteValid,
                                       res.smallestlastTimeMs, res.smallestlastChromaticNum, res.smallestlastValid, res.smallestlastChromaticNum - res.bruteChromaticNum,
                                       res.bfsTimeMs, res.bfsChromaticNum, res.bfsValid, res.bfsChromaticNum - res.bruteChromaticNum,
                                       res.dsaturTimeMs, res.dsaturChromaticNum, res.dsaturValid, res.dsaturChromaticNum - res.bruteChromaticNum));

            return(res);
        }