Beispiel #1
0
        public override double GetArcCost(GenericNode N2)
        {
            Point n2point = (Point)N2;

            Cell lastVisited = Traverses.Last();
            Cell nextVisited = n2point.Traverses.Last();


            int lastVisitedIndex = Array.FindIndex(Form4points.allPoints, n => n.IsEqual(lastVisited));
            int nextVisitedIndex = Array.FindIndex(Form4points.allPoints, n => n.IsEqual(nextVisited));

            //Distance entre le dernier point visité et le point donné
            return(Form4points.distances[lastVisitedIndex, nextVisitedIndex]);
        }
Beispiel #2
0
        public override double CalculeHCost()
        {
            Cell   lastVisited      = Traverses.Last();
            Cell   farthestCell     = null;
            double farthestDistance = 0;

            foreach (Cell c in Restants)
            {
                double distance = Math.Sqrt(Math.Pow(lastVisited.X - c.X, 2) + Math.Pow(lastVisited.Y - c.Y, 2));
                if (distance > farthestDistance)
                {
                    farthestCell     = c;
                    farthestDistance = distance;
                }
            }

            Cell   target           = Traverses[0];
            double distanceToTarget = farthestCell != null?Math.Sqrt(Math.Pow(farthestCell.X - target.X, 2) + Math.Pow(farthestCell.Y - target.Y, 2)) : 0;

            //Distance entre le dernier point visité et le point le plus loin de celui-ci + le retour du point le plus loin à l'arrivée
            return(farthestDistance + distanceToTarget);
        }
Beispiel #3
0
 public override bool EndState()
 {
     //Aucun point restant à visiter et le dernier point visité est l'arrivée
     return(Restants.Length == 0 && Traverses.Last().IsEqual(Point.Arrivee));
 }