Esempio n. 1
0
        public mainform()
        {
            InitializeComponent();

            CityData         = new ProblemAndSolver();
            this.tbSeed.Text = CityData.Seed.ToString();
        }
Esempio n. 2
0
        private void GenerateProblem()
        {
            if (!Regex.IsMatch(this.tbProblemSize.Text.Trim(), "^[0-9]+$"))
            {
                MessageBox.Show("Problem size must be a positive integer.");

            }
            else if (!Regex.IsMatch(this.txtSeed.Text.Trim(), "^[0-9]*$"))
            {
                MessageBox.Show("Problem seed must be a nonnegative integer (or blank).");
            }
            else
            {
                int problemSize = int.Parse(this.tbProblemSize.Text);
                int seed;
                if (this.txtSeed.Text.Trim() == "")
                {
                    CityData = new ProblemAndSolver(ProblemAndSolver.DEFAULT_SEED,problemSize);
                    lblProblem.Text = "--";
                }
                else if ((seed = int.Parse(this.txtSeed.Text)) != CityData.Seed || problemSize != CityData.Size)
                {
                    CityData = new ProblemAndSolver(seed, problemSize);
                    problemCounter = 1;
                    lblProblem.Text = problemCounter.ToString();
                }
                else
                {
                    CityData.GenerateProblem(problemSize);
                    problemCounter++;
                    lblProblem.Text = problemCounter.ToString();
                }
                this.Invalidate();
            }
        }
Esempio n. 3
0
        public mainform()
        {
            InitializeComponent();

            CityData = new ProblemAndSolver();
            this.tbSeed.Text = CityData.Seed.ToString();
        }
Esempio n. 4
0
File: Form1.cs Progetto: dnorth/TSP
 private void GenerateProblem()
 {
     if (!Regex.IsMatch(this.tbProblemSize.Text.Trim(), "^[0-9]+$"))
     {
         MessageBox.Show("Problem size must be a positive integer.");
     }
     else if (!Regex.IsMatch(this.txtSeed.Text.Trim(), "^[0-9]*$"))
     {
         MessageBox.Show("Problem seed must be a nonnegative integer (or blank).");
     }
     else
     {
         int problemSize = int.Parse(this.tbProblemSize.Text);
         int seed;
         if (this.txtSeed.Text.Trim() == "")
         {
             CityData        = new ProblemAndSolver(ProblemAndSolver.DEFAULT_SEED, problemSize);
             lblProblem.Text = "--";
         }
         else if ((seed = int.Parse(this.txtSeed.Text)) != CityData.Seed || problemSize != CityData.Size)
         {
             CityData        = new ProblemAndSolver(seed, problemSize);
             problemCounter  = 1;
             lblProblem.Text = problemCounter.ToString();
         }
         else
         {
             CityData.GenerateProblem(problemSize);
             problemCounter++;
             lblProblem.Text = problemCounter.ToString();
         }
         this.Invalidate();
     }
 }
Esempio n. 5
0
        public Mainform()
        {
            InitializeComponent();

            _cityData   = new ProblemAndSolver();
            tbSeed.Text = _cityData.Seed.ToString();
        }
Esempio n. 6
0
        public Form1()
        {
            InitializeComponent();

            CityData = new ProblemAndSolver();
            this.txtSeed.Text = CityData.Seed.ToString();
        }
Esempio n. 7
0
        /**
         * Return the next edge that will maximize the difference between including it and excluding it.
         */
        public Tuple <int, int> getNextEdge()
        {
            Tuple <int, int> bestEdgeSoFar = null;
            double           includeBound, excludeBound;
            double           difference, maxDifference = -1D;

            // Loop through all edges
            for (int i = 0; i < cm.GetLength(0); i++)
            {
                for (int j = 0; j < cm.GetLength(1); j++)
                {
                    // If this edge isn't eligible (zero cost), skip it.
                    if (cm[i, j] != 0)
                    {
                        continue;
                    }

                    // Ok, this edge is eligible, calculate the inc/exc difference

                    // For inclusion, make all entries in column i and row j infinite cost.
                    //  then reduce the matrix, adding to the bound as necessary.
                    // -- If this edge is used, later on in the core algorith we need toremember
                    //      to mark edge [j, i] as infinite as well.
                    double[,] tempCm = duplicateCM(cm);

                    tempCm[i, j] = double.PositiveInfinity;
                    tempCm[j, i] = double.PositiveInfinity;

                    for (int t = 0; t < tempCm.GetLength(0); t++)
                    {
                        tempCm[t, j] = double.PositiveInfinity;
                    }

                    for (int t = 0; t < tempCm.GetLength(1); t++)
                    {
                        tempCm[i, t] = double.PositiveInfinity;
                    }

                    includeBound = bound + ProblemAndSolver.reduceCM(ref tempCm);

                    // For exclusion, make the cost of [i, j] infinite, then
                    // b(Se) = b(Sparent) + min(rowi) + min(colj)
                    tempCm = duplicateCM(cm);

                    tempCm[i, j] = double.PositiveInfinity;
                    excludeBound = bound + ProblemAndSolver.reduceCM(ref tempCm);

                    // Calculate the differnce, check to see if this is lower than the lowest so far
                    difference = Math.Abs(excludeBound - includeBound);
                    if (difference > maxDifference)
                    {
                        maxDifference = difference;
                        bestEdgeSoFar = new Tuple <int, int>(i, j);
                    }
                }
            }

            return(bestEdgeSoFar);
        }
 public void addSolution(ProblemAndSolver.TSPSolution solution)
 {
     tabuList.AddFirst(solution);
     if (tabuList.Count == capacity)
     {
         tabuList.RemoveLast();
     }
 }
Esempio n. 9
0
 private void SetSeed()
 {
     if (Regex.IsMatch(this.tbSeed.Text, "^[0-9]+$"))
     {
         this.toolStrip1.Focus();
         CityData = new ProblemAndSolver(int.Parse(this.tbSeed.Text));
         this.Invalidate();
     }
     else
         MessageBox.Show("Seed must be an integer.");
 }
Esempio n. 10
0
 private void SetSeed()
 {
     if (Regex.IsMatch(this.tbSeed.Text, "^[0-9]+$"))
     {
         this.toolStrip1.Focus();
         CityData = new ProblemAndSolver(int.Parse(this.tbSeed.Text));
         this.Invalidate();
     }
     else
     {
         MessageBox.Show("Seed must be an integer.");
     }
 }
 public bool contains(ProblemAndSolver.TSPSolution otherSolution)
 {
     bool foundSolution = false;
     foreach (ProblemAndSolver.TSPSolution solution in tabuList)
     {
         if (solution.cost == otherSolution.cost)
         {
             if (solution.Equals(otherSolution))
             {
                 foundSolution = true;
             }
         }
     }
     return foundSolution;
 }
Esempio n. 12
0
 private SingleTestResult runTestIteration(int seed, int numCities, MethodInfo implementation,
     BackgroundWorker worker, TestSuiteProgressData progressData)
 {
     ProblemAndSolver ps = new ProblemAndSolver(seed, numCities);
     ps.UpdateForm = false;
     Stopwatch sw = new Stopwatch();
     sw.Start();
     implementation.Invoke(ps, new object[]{});
     sw.Start();
     return new SingleTestResult(ps.costOfBssf(), sw.ElapsedMilliseconds / 1000d);
 }
Esempio n. 13
0
File: Form1.cs Progetto: dnorth/TSP
 public Form1()
 {
     InitializeComponent();
     CityData = new ProblemAndSolver();
     GenerateProblem();
 }
Esempio n. 14
0
        public string[] Solve(ProblemAndSolver parent)
        {
            this.parent = parent;
            string[] results = new string[3];
            Dictionary <string, double> improvementRate = new Dictionary <string, double>();

            Population pop      = InitPopulation();
            Sequence   imdabest = pop.Best;
            Stopwatch  timer    = new Stopwatch();

            improvementRate[timer.Elapsed.ToString()] = imdabest.Score;
            timer.Start();
            int             iterationsSanChangement = 0;
            int             count       = 0;
            int             generations = 0;
            List <Sequence> bestones    = new List <Sequence>();

            bestones.Add(imdabest);

            while ((iterationsSanChangement < MaxGenerations && timer.Elapsed.TotalSeconds < 90) ||
                   pop.Size < 2)
            {
                generations++;
                CrossPopulation(ref pop);
                MutatePopulation(pop);
                PrunePopulation(pop);
                if (pop.Best.Score < imdabest.Score)
                {
                    iterationsSanChangement = 0;
                    count++;
                    imdabest = pop.Best;
                    improvementRate[timer.Elapsed.ToString()] = imdabest.Score;
                    bestones.Add(imdabest);
                }
                else
                {
                    iterationsSanChangement++;
                }
            }
            timer.Stop();

            parent.BSSF = imdabest.ToRoute();

            Console.WriteLine();

            results[ProblemAndSolver.COST]  = imdabest.Score.ToString(); // load results into array here, replacing these dummy values
            results[ProblemAndSolver.TIME]  = timer.Elapsed.ToString();
            results[ProblemAndSolver.COUNT] = count.ToString();          //*** should this be 1 or the number of greedy solutions that we find???
            StringBuilder bob = new StringBuilder();

            bob.Append("Time,Best Cost\r\n");
            foreach (var entry in improvementRate)
            {
                bob.Append(entry.Key);
                bob.Append(",");
                bob.Append(entry.Value);
                bob.Append("\r\n");
            }
            bob.Append("Best," + imdabest.Score.ToString() + "\r\n");
            bob.Append("Problem Size," + parent.GetCities().Length + "\r\n");
            bob.Append("Seed," + parent.Seed + "\r\n");
            bob.Append("Generations," + generations.ToString() + "\r\n");
            bob.Append("Total Time," + timer.Elapsed.ToString());
            bob.Append("\r\n");

            System.IO.File.AppendAllText(@"C:\Users\Matt\Desktop\tsp_results.csv", bob.ToString());
            return(results);
        }
Esempio n. 15
0
 public Form1()
 {
     InitializeComponent();
     CityData = new ProblemAndSolver();
     GenerateProblem();
 }