Exemplo n.º 1
0
        public void Search()
        {
            Thread thread = new Thread(() =>
            {
                while (true)
                {
                    var idea    = _currentNeighbourhood.Nearby();
                    var fitness = _model.Fitness(idea);

                    if (AbandonSite(idea, fitness))
                    {
                        Console.WriteLine($"Abandoning {_currentNeighbourhood.Output().Fitness:0.0} {idea}");
                        continue;
                    }

                    _dance(fitness, idea, _id);

                    if (_cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
            });

            thread.Start();
        }
Exemplo n.º 2
0
        public Scout(FirstModel model, int id,
                     Action <double, Idea, int> dance,
                     Action <Idea, double> report,
                     CancellationToken cancellationToken)
        {
            _model             = model;
            _id                = id;
            _dance             = dance;
            _report            = report;
            _cancellationToken = cancellationToken;
            var newIdea = Idea.NewIdea();

            _currentNeighbourhood = new Neighbourhood(newIdea, _model.Fitness(newIdea));
        }
Exemplo n.º 3
0
        public void Search()
        {
            var thread = new Thread(() =>
            {
                while (true)
                {
                    if (_cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    var neighbourhood = _neighbourhoodFunc();
                    if (neighbourhood == null)
                    {
                        continue;
                    }

                    var idea = neighbourhood.Nearby();
                    neighbourhood.RegisterSearch(idea, _model.Fitness(idea));
                }
            });

            thread.Start();
        }