Beispiel #1
0
        public static List<Road> FindPath(Node start, Node end)
        {
            if (Vertices == null || start == null || end == null)
                throw new ArgumentNullException();

            InitLists();
            SetStartEnd(start, end);
            Start.Cost = 0;
            Open.Add(Start);

            Vertex current;
            while (Open.Count > 0)
            {
                current = Open.Min();
                if (current == End)
                {
                    return TracePath();
                } 
                else
                {
                    MoveToClosed(current);
                    EstimateNeighbors(current);
                }
            }

            throw new Exception("No route found between " + start + " and " + end);
        }
Beispiel #2
0
        ////////// CONSTRUCTOR //////////
        public Vehicle(Project project, Node home, Destination dest, VehicleType type, int toDestTime, int toHomeTime)
        {
            _settings = project.Settings;
            ToDestRecord = new List<PointD>();
            ToHomeRecord = new List<PointD>();

            Home = home;
            Destination = dest;
            Type = type;

            if (ToDestTime > ToHomeTime)
                throw new ArgumentException("ToDestinationTime cannot be later than ToHomeTime");

            ToDestTime = toDestTime;
            ToHomeTime = toHomeTime;
            _toDestStarted = false;
            _toHomeStarted = false;
            
            Node end = FindEnd(project);
            _toDestPath = Pathfinder.FindPath(Home, end);
            _toHomePath = Pathfinder.FindPath(end, Home);

            Active = false;
            Speed = 0;
        }
 public GUIToolEditNode(Node node, Project project)
 {
     Node = node;
     Project = project;
     Setup();
     Load += ReadData;
     FormClosing += SaveData;
 }
Beispiel #4
0
 public Road(Node from, Node to, RoadType type, Partitions partition)
 {
     From = from;
     To = to;
     Type = type;
     Partition = partition;
     Vehicles = new List<Vehicle>();
 }
Beispiel #5
0
 private static void SetStartEnd(Node start, Node end)
 {
     foreach (Vertex vertex in Vertices)
     {
         if (vertex.Position == start.Position)
             Start = vertex;
         else if (vertex.Position == end.Position)
             End = vertex;
     }
 }
 protected void DrawArrow(Node node, bool left, PaintEventArgs args)
 {
     Point PosNode = GetDrawPosition(node.Position);
     Point offset;
     Pen arrow = new Pen(Color.White, 2);
     arrow.CustomEndCap = new AdjustableArrowCap(3, 3);
     if (left)
     {
         offset = new Point(PosNode.X - 4, PosNode.Y);
         args.Graphics.DrawLine(arrow, PosNode, offset);
     }
     else
     {
         offset = new Point(PosNode.X + 4, PosNode.Y);
         args.Graphics.DrawLine(arrow, PosNode, offset);
     }
 }
Beispiel #7
0
 private void SetIncoming(Node node)
 {
     if (!node.IncomingVehicles.Contains(this))
         node.IncomingVehicles.Add(this);
 }
Beispiel #8
0
 private void GoToNextRoad()
 {
     _currentRoad.Vehicles.Remove(this);
     _currentPathIndex++;
     _currentRoad.Vehicles.Add(this);
     Position = new PointD(_currentRoad.From.Position);
     CurrentNode = _currentRoad.From;
 }
Beispiel #9
0
 ////////// MOVE //////////
 private void Move(double distanceToMove)
 {
     CurrentNode = null;
     TranslateVehicle(distanceToMove);
     ControlOverreach();
     ShowAsIncoming();
 }
 private void StopConnection()
 {
     _firstNode = null;
     _firstController = null;
     _firstMoveObject = null;
     _firstNodeConnection = true;
     _firstControllerConnection = true;
     _firstMove = true;
     Viewport.HoverConnection = new Point(-1, -1);
 }
        private void RemoveNode(Node target)
        {
            foreach (Node node in Project.Nodes)
                for (int i = 0; i < node.Roads.Count; i++)
                    if (node.Roads[i].To == target)
                        node.Roads.Remove(node.Roads[i]);

            Project.Nodes.Remove(target);
            Viewport.Connections.Refresh();
        }
 private void AddRoad(Partitions partition)
 {
     object obj = Viewport.GetObjByGridPos();
     if (obj != null && obj is Node)
     {
         if (_firstNodeConnection)
         {
             _firstNode = (Node)obj;
             _firstNodeConnection = false;
             Viewport.HoverConnection = ((Node)obj).Position;
         }
         else
         {
             _firstNode.Roads.Add(new Road(_firstNode, (Node)obj, SelectedRoadType, partition));
             if (Control.ModifierKeys == Keys.Shift)
             {
                 _firstNode = (Node)obj;
                 Viewport.HoverConnection = ((Node)obj).Position;
             }
             else
             {
                 _firstNodeConnection = true;
                 Viewport.HoverConnection = new Point(-1, -1);
             }
             Viewport.Connections.Refresh();
         }
     }
 }