///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        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);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes solver context.
        /// </summary>
        private void _InitContext()
        {
            Debug.Assert(!_isContextInited); // init once

            _context.VrpRequestAnalyzer = _CreateRequestAnalyzer(_options, _solverConfig);

            // VRP services
            var syncContextProvider  = _CreateSyncContextProvider(_options);
            var asyncContextProvider = new RestServiceContextProvider(
                _vrpServiceConfig.RestUrl,
                _vrpServiceConfig.ToolName,
                _vrpServer);

            _context.VrpServiceFactory = new VrpRestServiceFactory(
                syncContextProvider,
                asyncContextProvider,
                _vrpServiceConfig.SoapUrl);

            // route services
            _context.RouteService = new RestRouteService(
                _routeServiceConfig.RestUrl,
                _routeServiceConfig.LayerName,
                _routeServer);

            // Initialize discovery service.
            _discoveryService.Initialize();

            NetworkDescription netDesc = new NetworkDescription(
                _routeServiceConfig.SoapUrl,
                _routeServiceConfig.LayerName,
                _routeServer);

            _context.NetworkDescription = netDesc;

            _context.RegionName = _currentRegionName;

            // solver settings
            _context.SolverSettings = new SolverSettings(
                _solverConfig,
                netDesc);

            _isContextInited = true;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        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);
        }
        /// <summary>
        ///  Get max number of "non-restrictionusage" parameters which restrictions has.
        /// </summary>
        /// <param name="description">Network description.</param>
        /// <param name="restrictions">List of restrictions.</param>
        /// <returns>Max number.</returns>
        private int _GetNonRestrictionParametersMaximumCount(NetworkDescription description, 
            ICollection<Restriction> restrictions)
        {
            var count = 0;
            ICollection<NetworkAttribute> networkAttributes =
                description.NetworkAttributes;

            foreach (NetworkAttribute attribute in networkAttributes)
            {
                if (attribute.UsageType == NetworkAttributeUsageType.Restriction &&
                    _IsRestrictionEditable(attribute.Name, restrictions))
                {
                    var attributeParametersCount = attribute.Parameters.Count;

                    // If attribute have restrictionusage parameter - reduce number of parameters.
                    if (attribute.RestrictionUsageParameter != null)
                        attributeParametersCount--;

                    count = Math.Max(attributeParametersCount, count);
                }
            }

            return count;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        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);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        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);
        }