public void TC_RedBlackTreeHeap()
        {
            var heap = new RedBlackTreeHeap <double>();

            HeapTest(heap, GetDoubleTestList());
            Assert.AreEqual("Red-Black Tree Heap", heap.GetName());
        }
示例#2
0
        public static ISearchHeap getHeapByParam(int param)
        {
            ISearchHeap heapStructure = null;

            switch (param)
            {
            case 1:
                heapStructure = new RedBlackTreeHeap();
                break;

            case 2:
                heapStructure = new FibonacciHeap();
                break;

            case 3:
                heapStructure = new FibonacciHeap2();
                break;

            case 4:
                heapStructure = new RegularBinaryHeap();
                break;

            case 5:
                heapStructure = new RegularTernaryHeap();
                break;

            case 6:
                heapStructure = new BinomialHeap();
                break;

            case 7:
                heapStructure = new LeftistHeap();
                break;

            default:
                break;
            }

            return(heapStructure);
            //heapStructure = new Heaps.RedBlackTreeHeap();
            //ISearchHeap heapStructure = new Heaps.FibonacciHeap1();
            //ISearchHeap heapStructure = new Heaps.FibonacciHeap2();
            //ISearchHeap heapStructure = new Heaps.RegularBinaryHeap();
            //ISearchHeap heapStructure = new Heaps.RegularTernaryHeap();
            //ISearchHeap heapStructure = new Heaps.BinomialHeap();
            //ISearchHeap heapStructure = new Heaps.LeftistHeap();
        }
示例#3
0
        public static void runPlanningExperiments(string domainsFolder, TimeSpan timeLimit, int param)
        {
            Logger logger = new Logger();
            List <SearchResults> allResults = new List <SearchResults>();

            //try
            //{

            //the number of computes that participate on this job. Computation is distributed among them.
            int numberOfComputes = 2;

            //if set to true, problem file that don't have histogram computed will be skipped. Otherwise all problems will be processed.
            bool onlyWhenHistogramExists = false;

            Problem     d;
            AStarSearch ast;
            //HillClimbingSearch ast;
            var directories = Directory.EnumerateDirectories(domainsFolder);

            allResults = new List <SearchResults>();
            foreach (var directory in directories)
            {
                var files = Directory.EnumerateFiles(directory).ToList();
                foreach (var SASFile in files)
                {
                    int indexOfFile = files.IndexOf(SASFile);
                    if (indexOfFile % numberOfComputes != param)                     //if (indexOfFile != param)
                    {
                        continue;
                    }
                    if (onlyWhenHistogramExists && !IsHistogramComputed(directory, SASFile))
                    {
                        continue;
                    }

                    logger.Log(" ----- new problem ----- ");
                    logger.Log(directory + "\\" + SASFile);

                    d = new Problem(SASFile, false);

                    Heuristic h = new FFHeuristic(d);

                    /*
                     * string histogramFolder = @"C:\Users\Ota\Documents\Visual Studio 2017\Projects\PADD\heuristicStats";
                     * var samples = HistogramVisualizer.Form1.getHistograms(histogramFolder);
                     * List<HistogramVisualizer.Histograms> selectedSamples = new List<HistogramVisualizer.Histograms>();
                     * foreach (var item in samples[Path.GetFileName(directory)].Values)
                     * {
                     *      selectedSamples.AddRange(item);
                     * }
                     */

                    //string trainedNetworkFile = Path.Combine("..", "trainedNetwork.bin");
                    //Heuristic h = new NNHeuristic(d, trainedNetworkFile);

                    //string dataFile = Path.Combine(directory, "histograms", "dataToLearn.tsv");
                    //Heuristic h = new FileBasedHeuristic(d, dataFile, false);

                    //Heuristic h = new FFHeuristic(d);
                    //Heuristic h = new RegHeuristic(new FFHeuristic(d));
                    //Heuristic h = new FileBasedHeuristic(d, dataFile, false);

                    //h = getHeuristicByParam(param, d);
                    //h = getHeuristicByParam(6, d);

                    ISearchHeap heapStructure = null;
                    //heapStructure = getHeapByParam(param);

                    //ISearchHeap heapStructure = new Heaps.MeasuredHeap();
                    heapStructure = new RedBlackTreeHeap();
                    //ISearchHeap heapStructure = new Heaps.FibonacciHeap1();
                    //ISearchHeap heapStructure = new Heaps.FibonacciHeap2();
                    //ISearchHeap heapStructure = new Heaps.RegularBinaryHeap();
                    //ISearchHeap heapStructure = new Heaps.RegularTernaryHeap();
                    //ISearchHeap heapStructure = new Heaps.BinomialHeap();
                    //ISearchHeap heapStructure = new Heaps.LeftistHeap();

                    ast = new AStarSearch(d, h, heapStructure);
                    //ast = new MultiHeuristicAStarSearch(d, h);
                    //ast = new MultiHeuristicAStarSearch(d, new List<Heuristic>() { h, hNN });
                    //ast = new IterativeDeepeningAStarSearch(d, null);

                    DirectoryInfo currentDirectory = new DirectoryInfo(directory);
                    FileInfo      currentFile      = new FileInfo(SASFile);

                    if (ast.OpenNodes is MeasuredHeap <IState> )
                    {
                        ((MeasuredHeap <IState>)ast.OpenNodes).SetLoggingOutputFile(currentDirectory.Name + "_" + currentFile.Name);
                    }

                    ast.TimeLimitOfSearch = timeLimit;
                    ast.Start();

                    var searchResult = ast.GetSearchResults(false);
                    searchResult.DomainName            = (Path.GetFileName(directory));
                    searchResult.ProblemName           = (Path.GetFileName(SASFile));
                    searchResult.Heuristic             = h.GetDescription();
                    searchResult.Algorithm             = ast.GetDescription() + "+" + heapStructure.GetName();
                    searchResult.BestHeuristicValue    = h.Statistics.BestHeuristicValue;
                    searchResult.AverageHeuristicValue = h.Statistics.AverageHeuristicValue;

                    //foreach (var item in ast.GetSolution().GetOperatorSeqIndices())
                    //    Console.Write(item + " ");
                    allResults.Add(searchResult);
                    if (ast.OpenNodes is MeasuredHeap <IState> )
                    {
                        ((MeasuredHeap <IState>)ast.OpenNodes).ClearStats();
                    }
                    logger.Log();
                }
                logger.Log(" ----- new domain ----- ");
            }


            //			catch (Exception e)
            //			{
            //			    using (var writer = new System.IO.StreamWriter("results" + Environment.MachineName + ".txt"))
            //			        foreach (var item in allResults)
            //			        {
            //			            writer.WriteLine(item.ToString());
            //			        }
            //}
            using (var writer = new System.IO.StreamWriter("results" + Environment.MachineName + ".txt"))
                foreach (var item in allResults)
                {
                    writer.WriteLine(item.ToString());
                }
        }