Jump to content

Path Optimization

- - - - -

  • Please log in to reply
2 replies to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Right now I'm using this to sort my data points for a quick sort for a collection of points.

   public class MapOptimization

    {

        private double[,] MappingPoints;

        private Point[] MapPoints;

        private int PointCount;

        public int LoadPoints(double[,] DataSet)

        {

            PointCount = DataSet.GetLength(0);

            MapPoints = new Point[PointCount];

            MappingPoints = new double[PointCount, 2];

            for (int i = 0; i < PointCount; i++)

            {

                MapPoints[i].X = Math.Round(DataSet[i, 0], 5);     // Round off to 5 Digits

                MapPoints[i].Y = Math.Round(DataSet[i, 1], 5);

            }

            // Move DataSet to MappingPoints, Checking each Point For Duplicates.

            // Return How Many Valid Points Loaded

            return PointCount;

        }

        public double[,] Optimize()

        {

            var sortedPoints = MapPoints.OrderBy(p => p.X).ThenBy(p => p.Y);


            int i = 0;

            foreach (Point TempPoint in sortedPoints)

            {

                MappingPoints[i, 0] = TempPoint.X;

                MappingPoints[i, 1] = TempPoint.Y;

                i++;

            }

            return MappingPoints;

        }

    }



But I am looking for help in truly optimizing the path.

An Example map would be something like this
Posted Image

What's the best way of determining the optimal path to stop at each point at least once with minimal movement?

#2
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Ok, looks like I need a form of the Traveling Salesman Algorithm, off to Wiki :D

#3
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
yeah but unless i am mistaken about your problem, if your problem can be limited to two dimensions of possible travel, it translates into unidirectional TSP which is solvable using Dynamic programming creating a 2D map of the possible paths and choosing the optimum one.

I am not able to figure out if that is the case with your problem or not.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users