Example #1
0
        public void Can_build_solution()
        {
            var solution = Optimizer.BuildSolution(
                SetMaximumDriverEligibility(Drivers.Take(1).ToList(), true),
                PlaceholderDriver,
                Jobs.Take(5).ToList());

            Assert.That(solution != null, "Solution is null");
            Assert.That(solution.RouteSolutions.Any(), "Solution has no route solutions");
        }
Example #2
0
        public void Can_only_send_hazmat_jobs_to_hazmat_drivers()
        {
            var hazmatJobs = Jobs.Where(p => p.IsHazmat).ToList();
            var hazmatIneligibleDrivers = Drivers.Where(p => !p.IsHazmatEligible).ToList();

            var solution = Optimizer.BuildSolution(
                hazmatIneligibleDrivers,
                PlaceholderDriver,
                hazmatJobs);

            Assert.That(hazmatJobs.Any(), "No hazmat mock jobs identified");
            Assert.That(hazmatIneligibleDrivers.Any(), "No hazmat ineligible mock drivers identified");
            Assert.That(solution.UnassignedJobNodes.Count > 0 && solution.RouteSolutions.Count == 0, "Ineligible driver has been assigned a hazmat job");
        }
Example #3
0
        public void Can_test_route_stop_second_window()
        {
            var drivers = SetMaximumDriverEligibility(Drivers.Where(p => p.OrderType == 1)).Take(1).ToList();
            var job     = Jobs.FirstOrDefault(p => p.OrderType == 3);

            var solution = Optimizer.BuildSolution(drivers, PlaceholderDriver, new List <Job>()
            {
                job
            });

            foreach (var rs in solution.RouteSolutions)
            {
                Console.WriteLine("Driver {0}", rs.DriverNode.Driver.DisplayName);
                foreach (var node in rs.Nodes)
                {
                    Console.WriteLine("\tJob Priority {0}", node.Priority);
                }
            }
        }
Example #4
0
        public void Can_prioritize_orders()
        {
            var priorityJobs = Jobs.Where(p => p.Priority >= 3).Take(5).ToList();
            var otherJobs    = Jobs.Where(p => p.Priority < 3).Take(15).ToList();
            var drivers      = SetMaximumDriverEligibility(Drivers, true).Take((priorityJobs.Count / 5) + 1).ToList();

            var solution = Optimizer.BuildSolution(
                drivers,
                PlaceholderDriver,
                priorityJobs.Concat(otherJobs).ToList());

            var priorityJobIds = new HashSet <int>(priorityJobs.Select(p => p.Id));

            foreach (var rs in solution.RouteSolutions)
            {
                foreach (JobNode node in rs.Nodes)
                {
                    priorityJobIds.Remove(node.Job.Id);
                }
            }

            Assert.That(priorityJobIds.Count == 0, "Not all priority jobs were given in a route solution");
        }
Example #5
0
        public void Can_driver_only_do_appropriate_order_types()
        {
            var type3Drivers = SetMaximumDriverEligibility(Drivers.Where(p => p.OrderType == 3));
            var type2Orders  = Jobs.Where(p => p.OrderType == 2).Take(4).ToList();
            var type3Orders  = Jobs.Where(p => p.OrderType == 3).Take(4).ToList();

            Assert.That(type3Drivers.Any(), "No mock drivers identified");
            Assert.That(type2Orders.Any(), "No mock jobs - order type 2 identified");
            Assert.That(type3Orders.Any(), "No mock jobs - order type 3 identified");

            var solutionUnfeasible = Optimizer.BuildSolution(
                type3Drivers,
                PlaceholderDriver,
                type2Orders);

            var solutionFeasible = Optimizer.BuildSolution(
                type3Drivers,
                PlaceholderDriver,
                type3Orders);

            Assert.That(solutionUnfeasible.UnassignedJobNodes.Count > 0 && solutionUnfeasible.RouteSolutions.Count == 0, "Ineligible driver has been assigned a job");
            Assert.That(solutionFeasible.UnassignedJobNodes.Count == 0 && solutionFeasible.RouteSolutions.Count > 0, "A job was unassigned");
        }
Example #6
0
        public void Can_test_prioritization_of_orders()
        {
            var type1Drivers = SetMaximumDriverEligibility(Drivers.Where(p => p.OrderType == 1));

            var priorityOrders = Jobs.Where(p => p.OrderType == 1).Take(32).ToList();
            var normalOrders   = Jobs.Where(p => p.OrderType == 3).Take(4).ToList();

            var jobs = new List <Job>();

            jobs.AddRange(priorityOrders);
            jobs.AddRange(normalOrders);

            var solution = Optimizer.BuildSolution(type1Drivers, PlaceholderDriver, jobs);

            int normalJobCount   = 0;
            int priorityJobCount = 0;

            foreach (var rs in solution.RouteSolutions)
            {
                Console.WriteLine("Driver {0}", rs.DriverNode.Driver.DisplayName);
                foreach (var node in rs.Nodes)
                {
                    Console.WriteLine("\tJob Priority {0}", node.Priority);
                    if (node.Priority == 3)
                    {
                        priorityJobCount++;
                    }
                    else
                    {
                        normalJobCount++;
                    }
                }

                Console.WriteLine("\n\tNormal Count: {0}     Priority Count: {1}", normalJobCount, priorityJobCount);
            }
        }