예제 #1
0
        private void startAlg(object sender, EventArgs e)
        {
            try
            {
                if (Graph1 == null || Graph2 == null)
                {
                    MessageBox.Show("Dane wejsciowe zawieraja bledy");
                }
                else if (Graph1.Vertexes.Count != Graph2.Vertexes.Count)
                {
                    MessageBox.Show("Grafy są różnych rozmiarów");
                }
                else
                {
                    WMH.TabuSearch.CostFinder      cf = new TabuSearch.CostFinder();
                    WMH.TabuSearch.NeighbourFinder nf = new TabuSearch.NeighbourFinder(cf, ltm);
                    WMH.TabuSearch.Implementation.AspirationCriteria ac = new TabuSearch.Implementation.AspirationCriteria(cf);
                    /*WMH.TabuSearch.TabuSearch*/ alg = new TabuSearch.TabuSearch(nf, tl, ltm, cf, ac, isc, ncsc, csc);

                    progressBar1.Minimum = 0;
                    progressBar1.Maximum = isc.MaxIterations;

                    buttonResult.IsEnabled = false;
                    BackgroundWorker bw = new BackgroundWorker();
                    bw.WorkerReportsProgress = true;
                    bw.DoWork             += BackgroundWorkerDoWork;
                    bw.RunWorkerCompleted += BackgroundWorkerComplete;

                    /*BackgroundWorker*/ progressWorker       = new BackgroundWorker();
                    progressWorker.WorkerReportsProgress      = true;
                    progressWorker.WorkerSupportsCancellation = true;
                    progressWorker.DoWork          += ProgressWorkerDoWork;
                    progressWorker.ProgressChanged += ProgressWorkerProgress;

                    progressWorker.RunWorkerAsync();
                    int t = 0;
                    bw.RunWorkerAsync();
                    //for (int i = 0; i < 10; i++)
                    //{
                    //    t = alg.test;
                    //    System.Threading.Thread.Sleep(1000);
                    //}
                    //WMH.TabuSearch.CostFinder cf = new TabuSearch.CostFinder();
                    //WMH.TabuSearch.NeighbourFinder nf = new TabuSearch.NeighbourFinder(cf, ltm);
                    //WMH.TabuSearch.Implementation.AspirationCriteria ac = new TabuSearch.Implementation.AspirationCriteria(cf);
                    //WMH.TabuSearch.TabuSearch alg = new TabuSearch.TabuSearch(nf, tl, ltm, cf, ac, isc);
                    //result = alg.FindSolution(Graph1, Graph2);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #2
0
파일: App.xaml.cs 프로젝트: Pemek/WMH
        private void StartAlgorithm(int vertexNumber, int ltmLenght, int stmLenght, int endCryt, int noChangeFor, double costLessThan, int?numberOfLoop)
        {
            string currentDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string pathG1, pathG2, pathResult;

            if (numberOfLoop != null)
            {
                pathG1     = currentDir + "\\g1\\graph" + numberOfLoop;
                pathG2     = currentDir + "\\g2\\graph" + numberOfLoop;
                pathResult = currentDir + "\\result\\res" + numberOfLoop;
            }
            else
            {
                pathG1     = currentDir + "\\g1\\graph";
                pathG2     = currentDir + "\\g2\\graph";
                pathResult = currentDir + "\\result\\res";
            }
            Graph Graph1 = GraphGenerator.generateGraph(vertexNumber);

            WMH.Model.FileOperation.FileOperationGraph.SaveToFile(pathG1, Graph1.Vertexes);
            Graph Graph2 = GraphGenerator.generateGraph(vertexNumber);

            WMH.Model.FileOperation.FileOperationGraph.SaveToFile(pathG2, Graph2.Vertexes);

            LongTermMemory        ltm  = new LongTermMemory(ltmLenght);
            TabuList              tl   = new TabuList(stmLenght);
            IterationStopCriteria isc  = new IterationStopCriteria(endCryt);
            NoChangesStopCriteria ncsc = new NoChangesStopCriteria(noChangeFor);
            CostStopCriteria      csc  = new CostStopCriteria(costLessThan);

            WMH.TabuSearch.CostFinder      cf = new TabuSearch.CostFinder();
            WMH.TabuSearch.NeighbourFinder nf = new TabuSearch.NeighbourFinder(cf, ltm);
            WMH.TabuSearch.Implementation.AspirationCriteria ac = new TabuSearch.Implementation.AspirationCriteria(cf);
            WMH.TabuSearch.TabuSearch alg = new TabuSearch.TabuSearch(nf, tl, ltm, cf, ac, isc, ncsc, csc);

            System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew();
            IList <Edge> result = alg.FindSolution(Graph1, Graph2);

            stopWatch.Stop();


            WMH.Model.FileOperation.FileOperationResult.SaveResultToFile(result, pathResult, stopWatch);
        }