コード例 #1
0
        private SolveResult _CreateSolveResult(VrpResult vrpResult, List <Violation> violations)
        {
            Debug.Assert(vrpResult != null);

            // convert job messages
            var msgList = new List <ServerMessage>();

            if (vrpResult.Messages != null)
            {
                foreach (JobMessage msg in vrpResult.Messages)
                {
                    msgList.Add(_ConvertJobMessage(msg));
                }
            }

            // violations
            List <Violation> vltList = violations;

            if (vltList == null)
            {
                vltList = new List <Violation>();
            }

            // status
            bool isSucceeded = IsSolveSucceeded(vrpResult.SolveHR);

            return(new SolveResult(msgList.ToArray(), vltList.ToArray(),
                                   !isSucceeded));
        }
コード例 #2
0
        protected override List <Violation> GetViolations(
            VrpResult vrpResult)
        {
            List <Violation> list = base.GetViolations(vrpResult);

            list.AddRange(_prevViolations);

            return(list);
        }
コード例 #3
0
        /// <summary>
        /// Converts VRP operation result to route's result.
        /// </summary>
        /// <param name="vrpResult">VRP solve operation result.</param>
        /// <param name="request">Request used for obtaining the response.</param>
        /// <returns>Route results.</returns>
        protected virtual IList <RouteResult> ConvertResult(
            VrpResult vrpResult,
            SubmitVrpJobRequest request)
        {
            Debug.Assert(vrpResult != null);
            Debug.Assert(request != null);

            var conv = new VrpResultConverter(_context.Project, _schedule, _context.SolverSettings);

            return(conv.Convert(vrpResult.ResultObjects, vrpResult.RouteResponse, request));
        }
コード例 #4
0
        protected override List <Violation> GetViolations(VrpResult vrpResult)
        {
            List <Violation> violations = base.GetViolations(vrpResult);

            if (_violations != null)
            {
                violations.AddRange(_violations);
            }

            return(violations);
        }
コード例 #5
0
        /// <summary>
        /// Processes (converts) solve operation result.
        /// </summary>
        /// <param name="vrpResult">VRP solve operation result.</param>
        /// <param name="request">Request used for obtaining the response.</param>
        /// <returns>Solve operation result.</returns>
        private SolveResult _ProcessSolveResult(VrpResult vrpResult, SubmitVrpJobRequest request)
        {
            Debug.Assert(vrpResult != null);
            Debug.Assert(request != null);

            List <Violation> violations = null;

            if (CanProcessResult(vrpResult.SolveHR))
            {
                violations = ProcessResult(vrpResult, request);
            }

            return(_CreateSolveResult(vrpResult, violations));
        }
コード例 #6
0
        /// <summary>
        /// Processes result.
        /// </summary>
        /// <param name="vrpResult">VRP solve operation result.</param>
        /// <param name="request">Request used for obtaining the response.</param>
        /// <returns>Founded violations.</returns>
        protected virtual List <Violation> ProcessResult(
            VrpResult vrpResult,
            SubmitVrpJobRequest request)
        {
            Debug.Assert(vrpResult != null);
            Debug.Assert(request != null);

            // get violations
            List <Violation> violations = GetViolations(vrpResult);

            VrpOperation nextStep = null;

            if (CanConvertResult(vrpResult.SolveHR))
            {
                if (vrpResult.ResultObjects != null)
                {
                    // convert VRP result
                    IList <RouteResult> routeResults = ConvertResult(vrpResult, request);

                    // check if we need next step
                    nextStep = GetNextStepOperation(routeResults, violations);
                    if (nextStep == null)
                    {
                        SetRouteResults(routeResults); // final step, set results to schedule
                    }
                }
            }
            else if (!_options.FailOnInvalidOrderGeoLocation)
            {
                if (!_HasRestrictedDepots(violations))
                {
                    List <Order> restrictedOrders = _GetRestrictedOrders(violations);
                    if (restrictedOrders.Count > 0)
                    {
                        nextStep = _GetRestrictedOrdersOperation(restrictedOrders, violations);
                    }
                }
            }

            _nextStep = nextStep;

            return(violations);
        }
コード例 #7
0
        /// <summary>
        /// Gets violations.
        /// </summary>
        /// <param name="vrpResult">VRP solve operation result.</param>
        /// <returns>Founded violations.</returns>
        protected virtual List <Violation> GetViolations(VrpResult vrpResult)
        {
            Debug.Assert(null != vrpResult);

            var list = new List <Violation>();

            var conv = new VrpResultConverter(_context.Project, _schedule,
                                              _context.SolverSettings);

            var results = vrpResult.ResultObjects;

            int hr = vrpResult.SolveHR;

            if (ComHelper.IsHRSucceeded(hr) && vrpResult.ResultObjects != null)
            {
                list.AddRange(conv.GetOrderViolations(results.ViolatedStops, hr));
            }

            else if (hr == (int)NAError.E_NA_VRP_SOLVER_EMPTY_INFEASIBLE_ROUTES)
            {
                list.AddRange(conv.GetRouteViolations(results.Routes, hr));
            }

            else if (hr == (int)NAError.E_NA_VRP_SOLVER_NO_SOLUTION)
            {
                list.AddRange(conv.GetOrderViolations(results.ViolatedStops, hr));
            }

            else if (hr == (int)NAError.E_NA_VRP_SOLVER_PREASSIGNED_INFEASIBLE_ROUTES)
            {
                list.AddRange(conv.GetRouteViolations(results.Routes, hr));
                list.AddRange(conv.GetOrderViolations(results.ViolatedStops, hr));
            }
            else if (hr == (int)NAError.E_NA_VRP_SOLVER_INVALID_INPUT)
            {
                list.AddRange(conv.GetDepotViolations(results.ViolatedStops));
                list.AddRange(conv.GetRestrictedOrderViolations(results.ViolatedStops));
            }

            return(list);
        }
コード例 #8
0
        protected override IList <RouteResult> ConvertResult(
            VrpResult vrpResult,
            SubmitVrpJobRequest request)
        {
            // convert current route results
            List <RouteResult> routeResults = new List <RouteResult>(
                base.ConvertResult(vrpResult, request));

            // add route results from previous solve for those routes that
            // were not used in the last solve
            List <RouteResult> prevRouteResults = new List <RouteResult>();

            foreach (RouteResult rr in _prevRouteResults)
            {
                if (!_ContainsRoute(routeResults, rr.Route))
                {
                    prevRouteResults.Add(rr);
                }
            }

            routeResults.AddRange(prevRouteResults);

            return(routeResults);
        }
コード例 #9
0
        /// <summary>
        /// Does solve.
        /// </summary>
        /// <param name="jobRequest">VRP request.</param>
        /// <param name="cancelTracker">Cancel tracker (Can be NULL).</param>
        /// <returns>Function returning VRP solve operation result.</returns>
        public Func <SolveOperationResult <SubmitVrpJobRequest> > Solve(
            SubmitVrpJobRequest jobRequest,
            ICancelTracker cancelTracker)
        {
            Debug.Assert(null != jobRequest);

            var result = default(VrpResult);

            var resultProvider = Functional.MakeLambda(() =>
            {
                var operationResult               = new SolveOperationResult <SubmitVrpJobRequest>();
                operationResult.SolveResult       = _ProcessSolveResult(result, jobRequest);
                operationResult.NextStepOperation = _nextStep;

                return(operationResult);
            });

            if (jobRequest.Orders.Features.Length == 0)
            {
                result = new VrpResult()
                {
                    SolveHR = 0,
                };

                return(resultProvider);
            }

            var factory = _context.VrpServiceFactory;

            using (var client = factory.CreateService(VrpRequestBuilder.JsonTypes))
            {
                var requestTime = new Stopwatch();
                requestTime.Start();

                // send request
                var response = _SendRequest(
                    client,
                    jobRequest,
                    cancelTracker);

                // create VRP result
                result = new VrpResult()
                {
                    Messages      = response.Messages,
                    SolveHR       = response.SolveHR,
                    ResultObjects = response.RouteResult,
                };

                if (CanProcessResult(result.SolveHR))
                {
                    _ValidateVrpResults(response);

                    // calc. statistics
                    requestTime.Stop();

                    var stat = new SolveStatistics()
                    {
                        RequestTime = requestTime.Elapsed
                    };

                    _LogJobStatistics(response.JobID, stat);
                }

                if (!_options.GenerateDirections && result.ResultObjects != null)
                {
                    result.ResultObjects.Directions = null;
                }

                return(resultProvider);
            }
        }
コード例 #10
0
        protected override List <Violation> GetViolations(VrpResult vrpResult)
        {
            List <Violation> violations = base.GetViolations(vrpResult);

            Order     violatedOrder = null;
            Violation specViolation = null;

            foreach (Violation v in violations)
            {
                if (v.ViolationType == ViolationType.Specialties &&
                    v.ObjectType == ViolatedObjectType.Order)
                {
                    violatedOrder = v.AssociatedObject as Order;
                    specViolation = v;
                    break;
                }
            }

            if (violatedOrder != null)
            {
                List <Guid> specIds = new List <Guid>();
                foreach (DriverSpecialty spec in violatedOrder.DriverSpecialties)
                {
                    if (spec.Id != AssignOrdersReqBuilder.ASSIGNMENT_SPEC_ID)
                    {
                        specIds.Add(spec.Id);
                    }
                }

                foreach (VehicleSpecialty spec in violatedOrder.VehicleSpecialties)
                {
                    if (spec.Id != AssignOrdersReqBuilder.ASSIGNMENT_SPEC_ID)
                    {
                        specIds.Add(spec.Id);
                    }
                }

                bool removeSpecViolation = true;
                if (specIds.Count > 0)
                {
                    foreach (Guid specId in specIds)
                    {
                        foreach (GPFeature feature in _jobRequest.Routes.Features)
                        {
                            if (!_IsSpecBelongToRoute(specId, feature))
                            {
                                removeSpecViolation = false;
                                break;
                            }
                        }
                        if (!removeSpecViolation)
                        {
                            break;
                        }
                    }
                }

                if (removeSpecViolation)
                {
                    violations.Remove(specViolation);
                }
            }

            if (_violations != null)
            {
                violations.AddRange(_violations);
            }

            return(violations);
        }