Esempio n. 1
0
        public override Path GetPath()
        {
            if (Destination != null)
            {
                Graph g = Database.Instance.Data.Graphs.FirstOrDefault().Value;

                Forklift f = Database.Instance.Data.Forklifts.FirstOrDefault().Value;

                Node from   = f.FrontNode;
                Node ignore = f.RearNode;

                Path p = g.ShortestPath(from, Destination, ignore);

                if (p.Nodes.Last().Equals(f.FrontNode))
                {
                    throw new JobException("Already at destination '" + f.FrontNode.Name + "'");
                }

                return(p);
            }

            // Neither directions or destination is set, cannot generate path
            return(null);
        }
Esempio n. 2
0
        public void ShortestPathTwoNodesNoPaths()
        {
            Graph g = new Graph(1);

            Node a = new Node("a");
            Node b = new Node("b");

            g.AddNode(a);
            g.AddNode(b);

            Path actual = g.ShortestPath(a, b);

            Assert.IsNull(actual);
        }
Esempio n. 3
0
        public void ShortestPathThreeNodesTwoPaths()
        {
            Graph g = new Graph(1);

            Node a = new Node("a");
            Node b = new Node("b");
            Node c = new Node("c");

            Edge ab = new Edge(20);
            Edge ac = new Edge(10);
            Edge cb = new Edge(5);

            g.AddNode(a);
            g.AddNode(b);
            g.AddNode(c);

            g.AddUndirectedEdge(new Tuple<Node, int>(a, 0), new Tuple<Node, int>(b, 0), ab);
            g.AddUndirectedEdge(new Tuple<Node, int>(a, 1), new Tuple<Node, int>(c, 0), ac);
            g.AddUndirectedEdge(new Tuple<Node, int>(c, 1), new Tuple<Node, int>(b, 1), cb);

            Path actual = g.ShortestPath(a, b);

            Path expected = new Path();
            expected.Nodes.Add(a);
            expected.Nodes.Add(c);
            expected.Nodes.Add(b);

            Assert.IsTrue(expected.Equals(actual));
        }
Esempio n. 4
0
        public void ShortestPathTwoNodes()
        {
            Graph g = new Graph(1);

            Node a = new Node("a");
            Node b = new Node("b");

            Edge ab = new Edge(10);

            g.AddNode(a);
            g.AddNode(b);

            g.AddUndirectedEdge(new Tuple<Node, int>(a, 0), new Tuple<Node, int>(b, 0), ab);

            Path actual = g.ShortestPath(a, b);

            Path expected = new Path();
            expected.Nodes.Add(a);
            expected.Nodes.Add(b);

            Assert.IsTrue(actual.Equals(expected));
        }
Esempio n. 5
0
        public override Path GetPath()
        {
            Node target = null;

            if (Destination != null)
            {
                target = Destination;
            }
            else if (PalletLocation != null)
            {
                target = PalletLocation.Location;
            }
            else
            {
                throw new NodeException("Cannot get path because of missing destination or pallet location (both are null)");
            }

            Graph g = Database.Instance.Data.Graphs.FirstOrDefault().Value;

            Forklift f = Database.Instance.Data.Forklifts.FirstOrDefault().Value;

            Node from   = f.FrontNode;
            Node ignore = f.RearNode;

            Path p = g.ShortestPath(from, target, ignore);

            if (Type == PalletJobType.fetch)
            {
                // Cannot fetch pallets with payload
                if (f.HasPallet)
                {
                    throw new JobException("Cannot fetch pallet with payload");
                }

                // To fetch a pallet from a node, the last node must have a pallet
                if (!p.Nodes.Last().HasPallet)
                {
                    throw new JobException("Cannot fetch pallet where there is none (Node '" + p.Nodes.Last().Name + "')");
                }
            }

            if (Type == PalletJobType.deliver)
            {
                // Cannot deliver without payload
                if (!f.HasPallet)
                {
                    throw new JobException("Cannot deliver pallet without payload");
                }

                if (p.Nodes.Last().HasPallet)
                {
                    throw new JobException("Cannot deliver pallet where there is already one (Node '" + p.Nodes.Last().Name + "')");
                }
            }

            if (p.Nodes.Last().Equals(f.FrontNode))
            {
                throw new JobException("Already at destination '" + f.FrontNode.Name + "'");
            }

            return(p);
        }