コード例 #1
0
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TSPInstance instance = new TSPInstance(fileInput);

            int[] assignment = TSPUtils.GreedySolution(instance);
            TSPUtils.LocalSearch2OptFirst(instance, assignment);
            TSPSolution solution = new TSPSolution(instance, assignment);

            solution.Write(fileOutput);
        }
コード例 #2
0
        public void Write(string file)
        {
            double cost = TSPUtils.Fitness(Instance, Path);

            using (StreamWriter writer = File.CreateText(file)) {
                writer.WriteLine(cost);
                writer.WriteLine(Instance.NumberCities);
                for (int i = 0; i < Instance.NumberCities; i++)
                {
                    writer.WriteLine(Path[i] + 1);
                }
            }
        }
コード例 #3
0
        protected override int[] InitialSolution()
        {
            int[] solution;

            if (generatedSolutions == 0)
            {
                solution = TSPUtils.GreedySolution(Instance);
            }
            else
            {
                solution = TSPUtils.RandomSolution(Instance);
            }

            generatedSolutions++;
            return(solution);
        }
コード例 #4
0
 public MaxMinAntSystem2OptFirst4TSP(TSPInstance instance, int numberAnts, double rho,
                                     double alpha, double beta, int maxReinit,
                                     int candidateLength, double candidateWeight)
     : base(instance.NumberCities, TSPUtils.Fitness(instance, TSPUtils.RandomSolution(instance)),
            numberAnts, rho, alpha, beta, maxReinit)
 {
     Instance             = instance;
     this.candidateWeight = candidateWeight;
     // Build the candidate list.
     this.candidateLists = new List <Tuple <double, int> > [Instance.NumberCities];
     for (int i = 0; i < Instance.NumberCities; i++)
     {
         this.candidateLists[i] = new List <Tuple <double, int> >();
         for (int j = 0; j < Instance.NumberCities; j++)
         {
             if (i != j)
             {
                 this.candidateLists[i].Add(new Tuple <double, int>(Instance.Costs[i, j], j));
             }
         }
         this.candidateLists[i].Sort();
         this.candidateLists[i].RemoveRange(candidateLength, this.candidateLists[i].Count - candidateLength);
     }
 }
コード例 #5
0
 protected override double Fitness(int[] solution)
 {
     return(TSPUtils.Fitness(Instance, solution));
 }
コード例 #6
0
 protected override double Fitness(int[] individual)
 {
     return(TSPUtils.Fitness(Instance, individual));
 }
コード例 #7
0
 protected override void Repair(int[] individual)
 {
     TSPUtils.Repair(Instance, individual);
 }
コード例 #8
0
 protected override int[] GetNeighbor(int[] solution)
 {
     return(TSPUtils.GetNeighbor(Instance, solution));
 }
コード例 #9
0
 protected override void LocalSearch(int[] individual)
 {
     TSPUtils.LocalSearch2OptFirst(Instance, individual);
 }
コード例 #10
0
 protected override int[] InitialSolution()
 {
     return(TSPUtils.GRCSolution(Instance, RclTreshold));
 }
コード例 #11
0
 protected override double Distance(int[] a, int[] b)
 {
     return(TSPUtils.Distance(Instance, a, b));
 }
コード例 #12
0
 protected override void Repair(int[] solution)
 {
     TSPUtils.Repair(Instance, solution);
 }
コード例 #13
0
 protected override void LocalSearch(int[] solution)
 {
     TSPUtils.LocalSearch2OptBest(Instance, solution);
 }
コード例 #14
0
 protected override int[] GRCSolution()
 {
     return(TSPUtils.GRCSolution(Instance, RCLThreshold));
 }
コード例 #15
0
 protected override void PerturbateSolution(int[] solution, int perturbation)
 {
     TSPUtils.PerturbateSolution(solution, perturbation);
 }
コード例 #16
0
 protected override Tuple <int, int> GetTabu(int[] current, int[] neighbor)
 {
     return(TSPUtils.GetTabu(current, neighbor));
 }
コード例 #17
0
 protected override void Improve(int[] solution)
 {
     TSPUtils.LocalSearch2OptFirst(Instance, solution);
 }