Example #1
0
        public Ant Execute(int antSize, float desirabilityInfluence, float pheromoneInfluence, float greedyInfluence)
        {
            _pheromoneGraph = new JobGraph(_allJobs.Count);

            for (int index = 0; index < _allJobs.Count; index++)
            {
                _allAnts.Add(new Ant(ref _allJobs, _allJobs[index], ref _pheromoneGraph));
            }

            // Assign an ant as best, as per the algorithm
            Ant   bestAnt            = _allAnts[0];
            float currentBestFitness = 0;

            while (!StopCondition())
            {
                _allAnts.ForEach(ant =>
                {
                    ant.TravelAllNodes();
                    float antFitness = CalculateTotalWeightedTardiness(ant);

                    if (antFitness > currentBestFitness)
                    {
                        currentBestFitness = antFitness;
                        bestAnt            = ant;
                    }

                    //Locally Update And Decay Pheromone
                    _pheromoneGraph.SetPheromoneBetweenTwoJobs();
                });
            }
        }
Example #2
0
        public void TravelAllNodes()
        {
            while (_tabuJobs.Count <= _allJobs.Count)
            {
                // Perform Job and add prevent it from being selected again.
                _timeEslasped += _currentJob.RequiredTimeToComplete;
                _tabuJobs.Add(_currentJob);

                List <Job> allowedJobs = GetAllowedJobs();

                double highestProbability = 0;
                Job    nextJob            = null;
                allowedJobs.ForEach(job =>
                {
                    double probability = CalculateProbabilityOfMovingToNode(job);

                    if (probability > highestProbability)
                    {
                        highestProbability = probability;
                        nextJob            = job;
                    }
                });

                double       evaporationRate = 0.2;
                const double q = 0.01;

                // Deposit Pheromone
                double totalDesirability = 0;
                _tabuJobs.ForEach(job => totalDesirability += CalculateDesirabilityOfMove(job));

                double pheromoneLevel = ((1 - evaporationRate) * (CalculateDesirabilityOfMove(_currentJob)) + (q / totalDesirability));

                _jobGraph.SetPheromoneBetweenTwoJobs(_currentJob.JobIndex, nextJob.JobIndex, pheromoneLevel);

                _currentJob = nextJob;
            }
        }