private void ExtractFromProfileAndStore()
        {
            if (_edgeFactor != null)
            {
                return;
            }

            var attributes = _enumerator.GetAttributes();

            _edgeFactor = _profile.Factor(attributes);

            _length         = _enumerator.EdgeLength();
            _weightForward  = 0;
            _weightBackward = 0;

            // WARNING: always store forward and reverse when we have the actual direction, the edge won't always be accessed in the same direction.
            if (_edgeFactor.Value.ForwardFactor != _edgeFactor.Value.BackwardFactor)
            {
                if (_edgeFactor.Value.ForwardFactor == 0)
                {
                    _weightBackward = _edgeFactor.Value.BackwardFactor * _length;
                    _coder.Set(_enumerator.Enumerator, _weightBackward.Value + (1 << 25));
                    return;
                }
                else if (_edgeFactor.Value.BackwardFactor == 0)
                {
                    _weightForward = _edgeFactor.Value.ForwardFactor * _length;
                    _coder.Set(_enumerator.Enumerator, _weightForward.Value + (1 << 26));
                    return;
                }
                else
                {
                    Console.WriteLine($"Cannot store weight for {_enumerator.GetAttributes()}");
                    return;
                }
            }

            _weightForward  = _edgeFactor.Value.ForwardFactor * _length;
            _weightBackward = _weightForward;
            if (_weightForward > (1 << 24))
            {
                Console.WriteLine($"Cannot store weight for {_enumerator.GetAttributes()}: > {1 << 24}");
                return;
            }

            _coder.Set(_enumerator.Enumerator, _weightForward.Value);
        }
Esempio n. 2
0
        internal static EdgeFactor FactorInEdgeDirection(this RouterDbEdgeEnumerator enumerator, Profile profile)
        {
            var factor = profile.Factor(enumerator.GetAttributes());

            if (!enumerator.Forward)
            {
                factor = factor.Reverse;
            }
            return(factor);
        }