Exemple #1
0
        public void Execute(IJobExecutionContext context)
        {
            TaskExecuter te = new TaskExecuter();
            TaskGetter   tg = new TaskGetter();

            var obj = tg.GetTask();

            uOw.UpdateContext();

            if (obj == null)
            {
                return;
            }

            var task1   = parsermanager.Get(obj.TaskId);
            var endTime = parsermanager.Get(obj.TaskId).EndDate;

            if (endTime == null)
            {
                te.ExecuteTask(obj.TaskId, obj.GoodUrl);
                var task_s = parsermanager.Get(obj.TaskId);
                task_s.Status = (Common.Enum.Status.Infinite);
                parsermanager.Update(task_s);
            }
            else if (endTime != null && DateTime.Now <= endTime)
            {
                te.ExecuteTask(obj.TaskId, obj.GoodUrl);
                var task_s = parsermanager.Get(obj.TaskId);
                task_s.Status = (Common.Enum.Status.Coming);
                parsermanager.Update(task_s);
            }
            else
            {
                var task_s = parsermanager.Get(obj.TaskId);
                task_s.Status = (Common.Enum.Status.Finished);
                parsermanager.Update(task_s);
            }
        }
Exemple #2
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            this.Invoke(FireToggleButtons, false);
            try
            {
                var problemToSolve = TaskGetter.Invoke();
                SimulatedAnnealingAlgorithm simulatedAnnealing;
                switch (problemToSolve.ProblemName)
                {
                case "Quadratic":
                    simulatedAnnealing = new SimulatedAnnealingAlgorithm(new QuadraticFunction(), 2, 10, 0.01, 1000, 0.99);
                    break;

                case "Rastrigin":
                    simulatedAnnealing = new SimulatedAnnealingAlgorithm(new RastriginFunction(), problemToSolve.DefaultDimensions, problemToSolve.Parameters);
                    break;

                case "Rosenbrock":
                    simulatedAnnealing = new SimulatedAnnealingAlgorithm(new RosenbrockFunction(), problemToSolve.DefaultDimensions, problemToSolve.Parameters);
                    break;

                case "IHCP":
                    UtilitiesMethods utilitiesMethods = new UtilitiesMethods();
                    DirectProblem    directProblem    = new DirectProblem(utilitiesMethods.f, utilitiesMethods.g, utilitiesMethods.h, 1, 1, 15, 480, 1, 1, 1);
                    InverseHeatConductionProblemFunction inverseHeatConductionProblemFunction = new InverseHeatConductionProblemFunction(directProblem, 0);
                    simulatedAnnealing = new SimulatedAnnealingAlgorithm(inverseHeatConductionProblemFunction, 3, problemToSolve.Parameters);
                    break;

                default:
                    throw new Exception("Problem not implemented.");
                }
                Task <double> task   = null;
                var           parent = this;
                SetResultText("Calculating...");
                task = Task.Run(() =>
                {
                    cts = new CancellationTokenSource();
                    CancellationToken token = cts.Token;
                    try
                    {
                        Task.Run(() =>
                        {
                            try
                            {
                                while (true)
                                {
                                    Thread.Sleep(100);
                                    token.ThrowIfCancellationRequested();
                                }
                            }
                            catch (Exception ep)
                            {
                                parent.Invoke(tmpEvent, "Process stoped.");
                                parent.Invoke(FireToggleButtons, true);
                            }
                        }, token);
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message, "Information");
                    }
                    double solutionValue = 0;
                    if (simulatedAnnealing != null)
                    {
                        solutionValue = simulatedAnnealing.Solve();
                        parent.Invoke(tmpEvent, "Problem name: " + problemToSolve.ProblemName + ", Dimensions: " + problemToSolve.DefaultDimensions + Environment.NewLine +
                                      "Real solution: " + simulatedAnnealing.Function.Solution + Environment.NewLine +
                                      "Founded solution: " + solutionValue + Environment.NewLine + simulatedAnnealing.GetCurrentProblemGUISolution());
                        parent.Invoke(FireToggleButtons, true);
                    }
                    return(solutionValue);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information");
            }
        }