Esempio n. 1
0
        /// <summary>
        /// Creates a new instance of the VRP REST service client.
        /// </summary>
        /// <param name="settings">Solver settngs information.</param>
        /// <param name="servers">Available servers.</param>
        /// <param name="solveServiceValidator">Solver service validator.</param>
        /// <returns>Discovery service.</returns>
        public IDiscoveryService CreateService(SolveInfoWrap settings,
                                               ICollection <AgsServer> servers,
                                               ISolveServiceValidator solveServiceValidator)
        {
            Debug.Assert(settings != null);
            Debug.Assert(servers != null);
            Debug.Assert(solveServiceValidator != null);

            var serviceInfo = settings.DiscoveryService;

            if (serviceInfo == null)
            {
                // Creates discovery service stub to do nothing.
                return(new DiscoveryServiceStub());
            }
            else
            {
                try
                {
                    // Creates full discovery service.
                    return(new DiscoveryService(serviceInfo, servers, solveServiceValidator));
                }
                // If we couldn't connect to service - return stub.
                catch (InvalidOperationException ex)
                {
                    Logger.Error(ex);
                    return(new DiscoveryServiceStub());
                }
            }
        }
        /// <summary>
        /// Creates a new instance of the VRP REST service client.
        /// </summary>
        /// <param name="settings">Solver settngs information.</param>
        /// <param name="servers">Available servers.</param>
        /// <param name="solveServiceValidator">Solver service validator.</param>
        /// <returns>Discovery service.</returns>
        public IDiscoveryService CreateService(SolveInfoWrap settings,
            ICollection<AgsServer> servers,
            ISolveServiceValidator solveServiceValidator)
        {
            Debug.Assert(settings != null);
            Debug.Assert(servers != null);
            Debug.Assert(solveServiceValidator != null);

            var serviceInfo = settings.DiscoveryService;

            if (serviceInfo == null)
            {
                // Creates discovery service stub to do nothing.
                return new DiscoveryServiceStub();
            }
            else
            {
                try
                {
                    // Creates full discovery service.
                    return new DiscoveryService(serviceInfo, servers, solveServiceValidator);
                }
                // If we couldn't connect to service - return stub.
                catch (InvalidOperationException ex)
                {
                    Logger.Error(ex);
                    return new DiscoveryServiceStub();
                }
            }
        }
        /// <summary>
        /// Creates new instance of the <see cref="SolveInfoWrap"/> class with
        /// current solve settings.
        /// </summary>
        /// <returns>Object holding current solve settings.</returns>
        private SolveInfoWrap _CreateSolveInfo()
        {
            if (_userServicesInfo.SolveInfo == null)
            {
                _userServicesInfo.SolveInfo = new UserSolveInfo();
            }

            SolveInfoWrap wrap = new SolveInfoWrap(
                _servicesInfo.SolveInfo,
                _userServicesInfo.SolveInfo);

            _solveServiceValidator.Validate(wrap.VrpService);
            _solveServiceValidator.Validate(wrap.RouteService);
            _solveServiceValidator.Validate(wrap.DiscoveryService);

            // We need to check sync VRP settings only if we have to use it.
            if (_servicesInfo.SolveInfo.SolverSettingsInfo.UseSyncronousVrp)
            {
                _solveServiceValidator.Validate(wrap.SyncVrpService);
            }

            return(wrap);
        }
 /// <summary>
 /// Method provides initialization of U-Turn policies.
 /// </summary>
 /// <param name="settings">Settings.</param>
 private void _InitUTurnPolicies(SolveInfoWrap settings)
 {
     // Validate settings for U-Turn policies.
     if (settings.UTurnAtIntersections)
     {
         settings.UTurnAtDeadEnds = true;
     }
 }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        private void _InitRestrictions(SolveInfoWrap settings,
            NetworkDescription netDesc)
        {
            Debug.Assert(settings != null);
            Debug.Assert(netDesc != null);

            Dictionary<string, Restriction> restrictions = new Dictionary<
                string, Restriction>();

            // add all available restrictions with default data
            foreach (NetworkAttribute attr in netDesc.NetworkAttributes)
            {
                if (attr.UsageType == NetworkAttributeUsageType.Restriction &&
                    !String.IsNullOrEmpty(attr.Name))
                {
                    restrictions.Add(attr.Name.ToLower(), new Restriction(
                        attr.Name,
                        String.Empty, // description
                        true, // editable is true by default
                        _IsRestrictionEnabled(attr.Name,
                            netDesc.EnabledRestrictionNames)));
                }
            }

            // override restrictions according to settings
            foreach (string name in settings.RestrictionNames)
            {
                RestrictionInfo ri = settings.GetRestriction(name);
                if (ri != null)
                {
                    string key = name.ToLower();

                    Restriction rest = null;
                    if (restrictions.TryGetValue(key, out rest))
                    {
                        // override restriction
                        restrictions[key] = new Restriction(
                            rest.NetworkAttributeName, // NOTE: use name from server
                            ri.Description,
                            ri.IsEditable,
                            ri.IsTurnedOn);
                    }
                    else
                        Logger.Warning(String.Format(LOG_UNKNOWN_RESTRICTION, name));
                }
            }

            // attach to events
            foreach (Restriction rest in restrictions.Values)
                rest.PropertyChanged += new PropertyChangedEventHandler(Restriction_PropertyChanged);

            _restrictions.AddRange(restrictions.Values);
        }
 /// <summary>
 /// Method provides initialization of Curb approach policies.
 /// </summary>
 /// <param name="settings">Settings.</param>
 private void _InitCurbApproachPolicies(SolveInfoWrap settings)
 {
     // Validate settings for Curb Approach policies.
     if (settings.UTurnAtStops)
     {
         settings.StopOnOrderSide = true;
     }
 }
        private void _InitAttrParameters(SolveInfoWrap settings)
        {
            Debug.Assert(settings != null);

            foreach (RouteAttrInfo attr in settings.AttrParameters)
            {
                bool isValid = false;

                // check if attribute settings are valid
                if (!String.IsNullOrEmpty(attr.AttrName) &&
                    !String.IsNullOrEmpty(attr.ParamName) &&
                    attr.Value != null)
                {
                    // find parameter in network description
                    NetworkAttributeParameter param = null;
                    if (_FindParamInNetworkDesc(attr.AttrName, attr.ParamName, out param))
                    {
                        // check if parameter value is valid
                        if (_IsParamValueValid(attr.Value, param.Type))
                            isValid = true;
                    }
                }

                if (!isValid)
                {
                    Logger.Warning(String.Format(LOG_INVALID_NETWORK_ATTR,
                        attr.AttrName,
                        attr.ParamName));
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        internal SolverSettings(SolveInfoWrap settings,
            NetworkDescription netDesc)
        {
            Debug.Assert(settings != null);
            Debug.Assert(netDesc != null);

            _settings = settings;
            _netDesc = netDesc;

            // Init restrictions.
            if (_netDesc != null)
                _InitRestrictions(settings, netDesc);

            // parameters
            _InitAttrParameters(settings);

            // Initialize U-Turn and curb approach policies.
            _InitUTurnPolicies(settings);
            _InitCurbApproachPolicies(settings);
        }