예제 #1
0
        /// <summary>
        /// Tests all enumerations of a route.
        /// </summary>
        public void DoTestEnumerateBetween()
        {
            int count  = 10;
            int routes = 3;

            IMultiRoute multiRoute = this.BuildRoute(true);

            Assert.AreEqual(0, multiRoute.Count);

            // test with initializing the routes empty.
            var customersPerRoute = new List <List <int> >();

            Assert.AreEqual(0, multiRoute.Count);
            IRoute route;

            for (int routeIdx = 0; routeIdx < routes; routeIdx++)
            {
                customersPerRoute.Add(new List <int>());
                int customerStart = (routeIdx * count);
                route = multiRoute.Add();

                for (int customer = customerStart; customer < customerStart + count; customer++)
                {
                    customersPerRoute[routeIdx].Add(customer);
                    route.InsertAfter(customer - 1, customer);
                    //route.InsertAfterAndRemove(customer - 1, customer, -1);
                }
            }

            for (int routeToTest = 0; routeToTest < routes; routeToTest++)
            {
                route = multiRoute.Route(routeToTest);

                for (int from = (routeToTest * count); from < (routeToTest * count) + count; from++)
                {
                    for (int to = (routeToTest * count); to < (routeToTest * count) + count; to++)
                    {
                        IEnumerator <int> enumerator = route.Between(from, to).GetEnumerator();
                        for (int customer = from; customer - 1 != to; customer++)
                        {
                            if (customer == (routeToTest * count) + count)
                            {
                                customer = (routeToTest * count);
                            }

                            Assert.IsTrue(enumerator.MoveNext());
                            Assert.AreEqual(customer, enumerator.Current);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Tests adding customers.
        /// </summary>
        public void DoTestRemove()
        {
            IMultiRoute multiRoute = this.BuildRoute(true);

            Assert.AreEqual(0, multiRoute.Count);
            int count  = 10;
            int routes = 3;

            // test with initializing the routes empty.
            var customersPerRoute = new List <List <int> >();

            Assert.AreEqual(0, multiRoute.Count);
            for (int routeIdx = 0; routeIdx < routes; routeIdx++)
            {
                customersPerRoute.Add(new List <int>());
                int    customerStart = (routeIdx * count);
                IRoute route         = multiRoute.Add();

                for (int customer = customerStart; customer < customerStart + count; customer++)
                {
                    customersPerRoute[routeIdx].Add(customer);
                    route.InsertAfter(customer - 1, customer);
                    //route.InsertAfterAndRemove(customer - 1, customer, -1);
                }
            }

            // remove all the customers.
            while (customersPerRoute.Count > 0)
            {
                int routeIdx    = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(customersPerRoute.Count);
                int customerIdx = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(customersPerRoute[routeIdx].Count);

                int customer = customersPerRoute[routeIdx][customerIdx];
                customersPerRoute[routeIdx].RemoveAt(customerIdx);

                IRoute route = multiRoute.Route(routeIdx);
                route.Remove(customer);

                Assert.AreEqual(customersPerRoute[routeIdx].Count, route.Count);
                Assert.AreEqual(customersPerRoute[routeIdx].Count == 0, route.IsEmpty);
                Assert.AreEqual(true, route.IsRound);
                Assert.AreEqual(route.First, route.Last);

                if (customersPerRoute[routeIdx].Count == 0)
                {
                    customersPerRoute.RemoveAt(routeIdx);
                    multiRoute.Remove(routeIdx);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Tests removing adding every customer at every position.
        /// </summary>
        public void DoTestAddRemoveComplete()
        {
            int count  = 10;
            int routes = 3;

            for (int routeToTest = 0; routeToTest < routes; routeToTest++)
            {
                for (int customerToRemove = (routeToTest * count); customerToRemove < (routeToTest * count) + count; customerToRemove++)
                {
                    for (int customerToPlaceAfter = (routeToTest * count); customerToPlaceAfter < (routeToTest * count) + count; customerToPlaceAfter++)
                    {
                        if (customerToRemove != customerToPlaceAfter)
                        {
                            IMultiRoute multiRoute = this.BuildRoute(true);

                            Assert.AreEqual(0, multiRoute.Count);

                            // test with initializing the routes empty.
                            var customersPerRoute = new List <List <int> >();
                            Assert.AreEqual(0, multiRoute.Count);
                            IRoute route;
                            for (int routeIdx = 0; routeIdx < routes; routeIdx++)
                            {
                                customersPerRoute.Add(new List <int>());
                                int customerStart = (routeIdx * count);
                                route = multiRoute.Add();

                                for (int customer = customerStart; customer < customerStart + count; customer++)
                                {
                                    customersPerRoute[routeIdx].Add(customer);
                                    route.InsertAfter(customer - 1, customer);
                                }
                            }

                            route = multiRoute.Route(routeToTest);

                            route.Remove(customerToRemove);
                            route.InsertAfter(customerToPlaceAfter, customerToRemove);

                            Assert.IsTrue(route.Contains(customerToPlaceAfter, customerToRemove));
                            Assert.AreEqual(count, route.Count);
                            var customersInRoute = new HashSet <int>(route);
                            Assert.AreEqual(customersInRoute.Count, route.Count);
                        }
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Do get neighbour tests.
        /// </summary>
        protected void DoTestGetNeighbours()
        {
            int count  = 10;
            int routes = 3;

            IMultiRoute multiRoute = this.BuildRoute(true);

            Assert.AreEqual(0, multiRoute.Count);

            // test with initializing the routes empty.
            var customersPerRoute = new List <List <int> >();

            Assert.AreEqual(0, multiRoute.Count);
            IRoute route;

            for (int routeIdx = 0; routeIdx < routes; routeIdx++)
            {
                customersPerRoute.Add(new List <int>());
                int customerStart = (routeIdx * count);
                route = multiRoute.Add();

                for (int customer = customerStart; customer < customerStart + count; customer++)
                {
                    customersPerRoute[routeIdx].Add(customer);
                    route.InsertAfter(customer - 1, customer);
                    //route.InsertAfterAndRemove(customer - 1, customer, -1);
                }
            }

            for (int routeToTest = 0; routeToTest < routes; routeToTest++)
            {
                route = multiRoute.Route(routeToTest);

                int[] neighbours;
                for (int customer = (routeToTest * count); customer < (routeToTest * count) + count - 1; customer++)
                {
                    neighbours = route.GetNeigbours(customer);
                    Assert.IsTrue(neighbours[0] == customer + 1);
                }
                neighbours = route.GetNeigbours((routeToTest * count) + count - 1);
                Assert.IsTrue(neighbours[0] == (routeToTest * count));
            }
        }
예제 #5
0
        /// <summary>
        /// Tests adding customers.
        /// </summary>
        public void DoTestAdd()
        {
            IMultiRoute multiRoute = this.BuildRoute(true);

            Assert.AreEqual(0, multiRoute.Count);
            int count  = 10;
            int routes = 3;

            for (int routeIdx = 0; routeIdx < routes; routeIdx++)
            {
                int    customerStart = (routeIdx * count);
                IRoute route         = multiRoute.Add(customerStart);
                Assert.AreEqual(1, route.Count);
                Assert.AreEqual(false, route.IsEmpty);
                Assert.AreEqual(true, route.IsRound);
                for (int customer = customerStart + 1; customer < customerStart + count; customer++)
                {
                    route.InsertAfter(customer - 1, customer);

                    Assert.AreEqual(customer - customerStart + 1, route.Count);
                    Assert.AreEqual(false, route.IsEmpty);
                    Assert.AreEqual(true, route.IsRound);
                    Assert.AreEqual(customerStart, route.First);
                    Assert.AreEqual(customerStart, route.Last);
                }

                for (int customer = customerStart + 1; customer < customerStart + count - 1; customer++)
                {
                    Assert.IsTrue(route.Contains(customer));
                    Assert.IsTrue(route.Contains(customer, customer + 1));
                }
                Assert.IsTrue(route.Contains(customerStart + count - 1));
                Assert.IsTrue(route.Contains(customerStart + count - 1, customerStart));

                Assert.AreEqual(routeIdx + 1, multiRoute.Count);
                Assert.AreEqual(count * (routeIdx + 1), multiRoute.Size);
            }

            // test with initializing the routes empty.
            multiRoute = this.BuildRoute(true);

            Assert.AreEqual(0, multiRoute.Count);
            for (int routeIdx = 0; routeIdx < routes; routeIdx++)
            {
                int    customerStart = (routeIdx * count);
                IRoute route         = multiRoute.Add();
                Assert.AreEqual(0, route.Count);
                Assert.AreEqual(true, route.IsEmpty);
                Assert.AreEqual(true, route.IsRound);
                for (int customer = customerStart; customer < customerStart + count; customer++)
                {
                    route.InsertAfter(customer - 1, customer);

                    Assert.AreEqual(customer - customerStart + 1, route.Count);
                    Assert.AreEqual(false, route.IsEmpty);
                    Assert.AreEqual(true, route.IsRound);
                    Assert.AreEqual(customerStart, route.First);
                    Assert.AreEqual(customerStart, route.Last);
                }

                for (int customer = customerStart; customer < customerStart + count - 1; customer++)
                {
                    Assert.IsTrue(route.Contains(customer));
                    Assert.IsTrue(route.Contains(customer, customer + 1));
                }
                Assert.IsTrue(route.Contains(customerStart + count - 1));
                Assert.IsTrue(route.Contains(customerStart + count - 1, customerStart));

                Assert.AreEqual(routeIdx + 1, multiRoute.Count);
                Assert.AreEqual(count * (routeIdx + 1), multiRoute.Size);
            }
        }