Beispiel #1
0
        public void run_szenario(int times, String sz, String s)
        {
            int render_every = 5120; //model evaluations

            //n mal laufen lassen für empirische Auswertung
            //(bei den direkten Heuristiken (greedy,insertion,savings nicht nötig, daher n = 1)
            for (int i = 0; i < times; i++)
            {
                //solange ein Prozess läuft mache nichts!
                while (optimizer_running)
                {
                    Thread.Sleep(5000);
                }

                String problemInstance = File.ReadAllText(sz + ".json");
                model = new MEPModel.MEP();
                model.LoadModelString(problemInstance);
                scenario = sz + "_" + s + "_" + i;
                Console.WriteLine("Starting Szenario:" + scenario);
                //setze Kontext
                model.AllowTripContinuation     = true;
                model.PermutateOptions          = false;
                model.AllowUnprofitableRequests = true;
                model.AvgTravelSpeed            = 400;
                model.HotelCostPerNight         = -100;
                model.HourlyWage          = -60;
                model.MilageAllowance     = -0.1;
                model.RevenuePerDayOnsite = 2000;

                Solver.Solver so = null;
                switch (s)
                {
                case "Greedy":
                    so = new GreedySolver(model);
                    break;

                case "SA":
                    so = new SimulatedAnnealingSolver(model, 10000, 1600, render_every, 64);    //somit maximal 10.000*16 = 160.000 modell evaluationen!
                    break;

                case "GA":
                    so = new GeneticSolver(model, 19, 5120, 5, render_every);     //somit maximal 100 * 1.600 = 160.000 modell evaluationen!
                    break;

                case "Insertion":
                    so = new NearestInsertionSolver(model);
                    break;

                case "Savings":
                    so = new SavingsSolver(model);
                    break;
                }
                start = DateTime.Now;
                Start_Optimizer(so);
            }
        }
Beispiel #2
0
        private void btnRunAsync_Click(object sender, RoutedEventArgs e)
        {
            output_to_file = false;
            tokensource    = new CancellationTokenSource();
            if (model != null && model.Requests.Count > 0)
            {
                btnRunAsync.IsEnabled = false;
                set_model_parameter();
                //clear optimizer Output:
                txtOptimizerOutput.Text = "";

                Solver.Solver s = null;
                if (rbGeneticAlgorithm.IsChecked == true)
                {
                    s = new GeneticSolver(model, Convert.ToInt32(txtGenerations.Text), Convert.ToInt32(txtPopulationSize.Text), Convert.ToInt32(txtMutationProbability.Text), Convert.ToInt32(txtReportProgress.Text));
                }
                if (rbBruteForce.IsChecked == true)
                {
                    if (model.GetNumberOfElements() > 11)
                    {
                        MessageBox.Show("I´m sorry Dave, I`m afraid I can`t do that!");
                    }
                    else
                    {
                        s = new BruteForceSolver(model);
                    }
                }
                if (rbSimulatedAnnealing.IsChecked == true)
                {
                    s = new SimulatedAnnealingSolver(model, Convert.ToInt32(txtStartTemp.Text), Convert.ToInt32(txtSteps.Text), Convert.ToInt32(txtReportProgress.Text), Convert.ToInt32(txtParallelAnnealings.Text));
                }
                if (rbGreedy.IsChecked == true)
                {
                    s = new GreedySolver(model);
                }
                if (rbInsertion.IsChecked == true)
                {
                    s = new NearestInsertionSolver(model);
                }
                if (rbSavings.IsChecked == true)
                {
                    s = new SavingsSolver(model);
                }

                if (s != null)
                {
                    Start_Optimizer(s);
                }
            }
        }
Beispiel #3
0
        private void Start_Optimizer(Solver.Solver s)
        {
            optimizer_running = true;
            if (s != null)
            {
                model.CancelToken = tokensource.Token;

                //hier fehlt noch die Cancelation genauso wie die cancel token überprüfung in allen optimizern
                optimizerTask = new Task <Result>(() => s.Optimize(), model.CancelToken);
                s.ProgressHandler.ProgressChanged += Prog_ProgressChanged;
                //optimizerTask.Start();
                //await optimizerTask;

                //Func<Solver.Solver, Result> func = (so) => { return so.Optimize(); };
                Task.Factory.StartNew((obj) =>
                {
                    var so = obj as Solver.Solver;
                    return(so.Optimize());
                }, s, model.CancelToken).ContinueWith((tResult) =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        //gibt nochmal das letzte ergebnis aus:
                        UpdateViewModel(tResult.Result);
                        if (!output_to_file)
                        {
                            txtOptimizerOutput.Text += getRouteDescription();
                        }
                        if (output_to_file)
                        {
                            File.WriteAllText(scenario + "_" + start.ToString("dd_HH_mm_ss") + "_" + DateTime.Now.ToString("dd_HH_mm_ss") + ".txt", txtOptimizerOutput.Text);
                            txtOptimizerOutput.Text = "";
                        }
                        btnRunAsync.IsEnabled = true;
                        optimizer_running     = false;
                    });
                });
            }
        }
 public void CanSolve()
 {
     var solver = new Solver.Solver(TestGridGenerator.TheRealTest());
     solver.SolveProblem();
 }
 public void CanSolve()
 {
     var solver = new Solver.Solver(TestGridGenerator.GridWithInfinateLoop());
     solver.SolveProblem();
 }
 public void CanSolve()
 {
     var solver = new Solver.Solver(TestGridGenerator.SquareGridWithFourStageSolution());
     solver.SolveProblem();
 }
 public void CanSolve()
 {
     var solver = new Solver.Solver(TestGridGenerator.SingleColumnWithExitOnBottom());
     solver.SolveProblem();
 }
 public void CanSolve()
 {
     var solver = new Solver.Solver(TestGridGenerator.SingleRowWithExitOnLeft());
     solver.SolveProblem();
 }
Beispiel #9
0
 public void MyTestInitialize()
 {
     this.grid = new Grid(sGrid);
     this.solver = new Solver.Solver();
     Assert.IsNotNull(grid);
 }
Beispiel #10
0
 public void MyTestInitialize()
 {
     this.grid   = new Grid(sGrid);
     this.solver = new Solver.Solver();
     Assert.IsNotNull(grid);
 }