コード例 #1
0
ファイル: Connection.cs プロジェクト: Spawek/linkallocator
 public Connection(string _name, Device _src, Device _dst, int _capacity)
 {
     name = _name;
     source = _src;
     destination = _dst;
     currCapacity = _capacity;
     maxCapacity = _capacity;
 }
コード例 #2
0
ファイル: Link.cs プロジェクト: Spawek/linkallocator
        public string name; //channel?

        #endregion Fields

        #region Constructors

        public Link(string _name, Device _src, Device _dst, int _capacityNeeded)
        {
            if (_capacityNeeded <= 0)
                throw new ArgumentException("capacityNeeded has to be > 0");

            name = _name;
            mainSource = _src;
            mainDestination = _dst;
            capacityNeeded = _capacityNeeded;
        }
コード例 #3
0
ファイル: Link.cs プロジェクト: Spawek/linkallocator
        public Link(string _name, List<Device> _src, List<Device> _dst, int _capacityNeeded)
        {
            if (_capacityNeeded <= 0)
                throw new ArgumentException("capacityNeeded has to be > 0");
            if (_src.Count == 0)
                throw new ApplicationException("no source in link");
            if (_dst.Count == 0)
                throw new ApplicationException("no destinationn in link");

            name = _name;
            mainSource = _src[0];
            additionalSources = _src.GetRange(1, _src.Count - 1);
            mainDestination = _dst[0];
            additionalDestinations = _dst.GetRange(1, _dst.Count - 1);
            capacityNeeded = _capacityNeeded;
        }
コード例 #4
0
ファイル: Topology.cs プロジェクト: Spawek/linkallocator
        private List<Connection> FindShortestReversedPathForLinkAndGivenDestination(Link link, Device source, Device destination)
        {
            Device currDev = destination;
            List<Connection> path = new List<Connection>();
            while (currDev != source)
            {
                Connection currPath = currDev.outgoingConnections.Find(x => x.destination.mark == currDev.mark - 1);
                if (currPath == null)
                    throw new ApplicationException("dsadsads");
                path.Add(currPath);

                currDev = currPath.destination;
            }

            path.Reverse();

            return path;
        }
コード例 #5
0
ファイル: Topology.cs プロジェクト: Spawek/linkallocator
        private List<Connection> FindShortestPathForLinkAndGivenDestination(Link link, Device source, Device destination)
        {
            Device currDev = destination;
            List<Connection> path = new List<Connection>();
            while (currDev != source)
            {
                Connection currPath = currDev.incomingConnections.Find(x => x.source.mark == currDev.mark - 1);
                path.Add(currPath);

                currDev = currPath.source;
            }

            path.Reverse();

            return path;
        }
コード例 #6
0
ファイル: Topology.cs プロジェクト: Spawek/linkallocator
        /// <summary>
        /// reversed BFS uses one-way links in reversed direction
        /// (uses incoming connections instead of outgoing connections)
        /// </summary>
        /// <param name="link"></param>
        /// <param name="destination"></param>
        private void CreateMarksWithReversedBFS(Link link, Device startPoint)
        {
            Queue<Device> frontier = new Queue<Device>();
            frontier.Enqueue(startPoint);
            ResetMarks(NOT_SEEN);
            startPoint.mark = START_POINT;

            while (frontier.Count != 0)
            {
                Device curr = frontier.Dequeue();

                foreach (Connection c in curr.incomingConnections)
                {
                    if (c.source.mark == NOT_SEEN && c.CanAllocateLink(link))
                    {
                        c.source.mark = curr.mark + 1;
                        frontier.Enqueue(c.source);
                    }
                }
            }
        }
コード例 #7
0
ファイル: Topology.cs プロジェクト: Spawek/linkallocator
 private static void VerifyPathSource(List<Connection> path, Device expectedSource)
 {
     if (path[0].source != expectedSource)
         throw new PathValidationException("Path source is wrong!");
 }
コード例 #8
0
ファイル: Topology.cs プロジェクト: Spawek/linkallocator
 private static void VerifyPathDestination(List<Connection> path, Device expectedDestination)
 {
     if (path[path.Count - 1].destination != expectedDestination)
         throw new PathValidationException("Path destination is wrong!");
 }