コード例 #1
0
ファイル: Program.cs プロジェクト: ruslander/luntre
        static void Main(string[] args)
        {
            var all = new List<string>() { "10.10.10.1,2555", "10.10.10.2,2555", "10.10.10.3,2555" };

            List<Node> cluster;
            cluster = new List<Node>()
            {
                new Node("10.10.10.1,2555", all),
                new Node("10.10.10.2,2555", all),
                new Node("10.10.10.3,2555", all)
            };

            Console.ReadLine();

            Node offended = null;

            // leader stepdown
            foreach (var node in cluster)
            {
                if (node.State == NodeRole.Leader)
                {
                    offended = node;
                    node.Dispose();
                }
            }

            Console.ReadLine();

            // online again
            offended = new Node(offended.Host, all);

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: pjmagee/world-404
        private static void PrintNodeInTangibles(Node node)
        {
            Console.WriteLine($"{node} has {node.Intangibles.Count} intangibles.");

            foreach (var intangible in node.Intangibles)
            {
                Console.WriteLine($"{intangible}");
            }
        }
コード例 #3
0
        public void setup()
        {
            _link = new ManagedLink("A");

            ntw = new ManagedSwitch();
            ntw.Connect(_link);

            _node = new Node("A", new List<string>() { "A" }, _link);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: pjmagee/world-404
 private static void PrintNodeSiblings(Area area, Node node)
 {
     Console.WriteLine($"{node} has {node.Siblings.Count} siblings.");
     foreach (var sibling in node.Siblings)
     {
         Console.WriteLine($"{sibling} is owned by {sibling.Owner}.");
         Console.WriteLine($"{area} has {area.Siblings.Count} siblings.");
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: jacob-l/VideoCreator
 static Node ConfigureNode()
 {
     String json = ConfigurationManager.AppSettings["nodeConfig"];
     NodeConfig config = NodeConfigFactory.Create(json);
     Node node = new Node(config);
     node.Start();
     Thread.Sleep(100);
     return node;
 }
コード例 #6
0
        public void SimpleTest()
        {
            var prop = new Node("Property");
            var val = new Node("Value");

            val.Dependencies = new Collection<Node> { prop };

            var expected = new List<Node> { prop, val };

            var actual = DependencySorter.SortDependencies(new Collection<Node> { prop, val }).ToList();
            Assert.Equal(expected, actual);
        }
コード例 #7
0
        public void CircularDependency()
        {
            var a = new Node("A");
            var b = new Node("B");
            var c = new Node("C");
            var d = new Node("D");
            var e = new Node("E");

            a.Dependencies = new Collection<Node> { b, d };
            b.Dependencies = new Collection<Node> { c, e };
            c.Dependencies = new Collection<Node> { d, e };
            e.Dependencies = new Collection<Node> { a };

            Assert.Throws<InvalidOperationException>(() => DependencySorter.SortDependencies(new Collection<Node> { a, b, c, d, e }));
        }
コード例 #8
0
        public void PartiallySorted()
        {
            var a = new Node("A");
            var b = new Node("B");
            var c = new Node("C");
            var d = new Node("D");
            var e = new Node("E");

            a.Dependencies = new Collection<Node> { };
            b.Dependencies = new Collection<Node> { a };
            c.Dependencies = new Collection<Node> { b };
            d.Dependencies = new Collection<Node> { e };
            e.Dependencies = new Collection<Node> {  };

            var expected = new List<Node> { a, b, c, e, d };

            var actual = DependencySorter.SortDependencies(new Collection<Node> { a, b, c, d, e }).ToList();
            Assert.Equal(expected, actual);
        }
コード例 #9
0
 public void setup()
 {
     _n1 = new Node("10.10.10.1,2555", all);
     _n2 = new Node("10.10.10.2,2555", all);
     _n3 = new Node("10.10.10.3,2555", all);
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: jacob-l/VideoCreator
        static String StartTasks(Node node)
        {
            String main = "main" + Guid.NewGuid().ToString();
            node.AddTask(main);
            String localTasks = ConfigurationManager.AppSettings["thisTasks"];
            String[] tasks = localTasks.Split(' ');
            for (int i = 0; i < tasks.Length; i++ )
                node.AddTask(tasks[i]);

            Console.WriteLine("StartedTasks");
            return "/" + node.Name + "/" + main;
        }
コード例 #11
0
        public void addPoint(PointDouble point, Node node)
        {
            //if we have reached a leaf node
            if (node == null)
                node = new Node ();
            if (node._left == null && node._right == null) {
                node._bucket.Add (point);

                if (node._bucket.Count > _bucketSize) {

                    node._val = 0.0;
                    foreach (PointDouble pt in node._bucket)
                    {
                        if (node.split == Node.Type.X)
                            node._val += pt.Y;
                        else
                            node._val += pt.X;
                    }
                    node._val /= node._bucket.Count;

                    node._left = new Node ();
                    node._right = new Node ();

                    foreach(PointDouble pt in node._bucket)
                    {
                        if (node.split == Node.Type.X)
                            if (pt.Y > node._val)
                                node._left._bucket.Add(pt);
                            else
                                node._right._bucket.Add (pt);
                        else
                            if (pt.X < node._val)
                                node._left._bucket.Add(pt);
                            else
                                node._right._bucket.Add (pt);
                    }

                    node._left.split = node._right.split = node.split == Node.Type.X ? Node.Type.Y : Node.Type.X;

                    //is this risky?
                    node._bucket.Clear ();

                }
                return;
            }
            switch (node.split)
            {

            case Node.Type.X:
                if (point.Y > node._val){
                    addPoint(point, node._left);
                }else{
                    addPoint(point, node._right);
                }
                break;
            case Node.Type.Y:
                if (point.X < node._val){
                    addPoint(point, node._left);
                }else{
                    addPoint(point, node._right);
                }
                break;

            }
        }
コード例 #12
0
 public SpatialTree()
 {
     _root = new Node();
 }
コード例 #13
0
 public Node()
 {
     _bucket = new List<PointDouble>();
     _left = null;
     _right = null;
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: pjmagee/world-404
        private static void PrintNodeTangibles(Node node)
        {
            Console.WriteLine($"{node} has {node.Tangibles.Count} tangibles.");

            foreach (var tangible in node.Tangibles)
            {
                Console.WriteLine($"{tangible} is in {node}");
                PrintTangibleCommands(tangible);
            }
        }
コード例 #15
0
        // Выполняет подсчет сразу 3 свойств - средняя длина пути, диаметр и пути между вершинами.
        // Нужно вызвать перед получением этих свойств не изнутри.
        private void CountEssentialOptions()
        {
            if (edgesBetweenNeighbours.Count == 0)
            {
                for (int i = 0; i < container.Size; ++i)
                    edgesBetweenNeighbours.Add(-1);
            }

            double avg = 0;
            uint d = 0, uWay = 0;
            int k = 0;

            for (int i = 0; i < container.Size; ++i)
            {
                for (int j = i + 1; j < container.Size; ++j)
                {
                    int way = MinimumWay(i, j);
                    if (way == -1)
                        continue;
                    else
                        uWay = (uint)way;

                    if (distanceDistribution.ContainsKey(uWay))
                        ++distanceDistribution[uWay];
                    else
                        distanceDistribution.Add(uWay, 1);

                    if (uWay > d)
                        d = uWay;

                    avg += uWay;
                    ++k;
                }
            }

            Node[] nodes = new Node[container.Size];
            for (int t = 0; t < container.Size; ++t)
                nodes[t] = new Node();

            BFS((int)container.Size - 1, nodes);
            avg /= k;

            averagePathLength = avg;
            diameter = d;
            calledPaths = true;
        }
コード例 #16
0
        private void BFS(int i, Node[] nodes)
        {
            nodes[i].lenght = 0;
            nodes[i].ancestor = 0;
            bool b = true;
            Queue<int> q = new Queue<int>();
            q.Enqueue(i);
            int u;
            if (edgesBetweenNeighbours[i] == -1)
                edgesBetweenNeighbours[i] = 0;
            else
                b = false;

            while (q.Count != 0)
            {
                u = q.Dequeue();
                List<int> l = container.Neighbourship[u];
                for (int j = 0; j < l.Count; ++j)
                    if (nodes[l[j]].lenght == -1)
                    {
                        nodes[l[j]].lenght = nodes[u].lenght + 1;
                        nodes[l[j]].ancestor = u;
                        q.Enqueue(l[j]);
                    }
                    else
                    {
                        if (nodes[u].lenght == 1 && nodes[l[j]].lenght == 1 && b)
                        {
                            ++edgesBetweenNeighbours[i];
                        }
                    }
            }
            if (b)
                edgesBetweenNeighbours[i] /= 2;
        }
コード例 #17
0
 public void setup()
 {
     _node = new Node("10.10.10.1,2555", new List<string>() { "10.10.10.1,2555"});
 }
コード例 #18
0
        protected override SortedDictionary<UInt32, UInt32> CalculateConnectedComponentDistribution()
        {
            var connectedSubGraphDic = new SortedDictionary<UInt32, UInt32>();
            Queue<int> q = new Queue<int>();
            var nodes = new Node[container.Size];
            for (int i = 0; i < nodes.Length; i++)
                nodes[i] = new Node();
            var list = new List<int>();

            for (int i = 0; i < container.Size; i++)
            {
                UInt32 order = 0;
                q.Enqueue(i);
                while (q.Count != 0)
                {
                    var item = q.Dequeue();
                    if (nodes[item].lenght != 2)
                    {
                        if (nodes[item].lenght == -1)
                        {
                            order++;
                        }
                        list = container.Neighbourship[item];
                        nodes[item].lenght = 2;

                        for (int j = 0; j < list.Count; j++)
                        {
                            if (nodes[list[j]].lenght == -1)
                            {
                                nodes[list[j]].lenght = 1;
                                order++;
                                q.Enqueue(list[j]);
                            }

                        }
                    }
                }

                if (order != 0)
                {
                    if (connectedSubGraphDic.ContainsKey(order))
                        connectedSubGraphDic[order]++;
                    else
                        connectedSubGraphDic.Add(order, 1);
                }
            }
            return connectedSubGraphDic;
        }
コード例 #19
0
        public PointDouble GetClosestPoint(PointDouble point, Node node)
        {
            if (node == null)
                return new PointDouble();

            double distanceSqA = double.MaxValue;
            double distanceSqB = double.MaxValue;
            PointDouble closestPointA = null;
            PointDouble closestPointB = null;

            //this is a leaf node
            if (node._left == null && node._right == null)
            {
                foreach (PointDouble pt in node._bucket)
                {

                    if( (pt.X - point.X)*(pt.X - point.X) +
                       (pt.Y - point.Y)*(pt.Y - point.Y) < distanceSqA)
                    {
                        closestPointA = pt;
                        distanceSqA = (pt.X - point.X)*(pt.X - point.X) + (pt.Y - point.Y)*(pt.Y - point.Y);
                    }
                }
                return closestPointA;
            }

            switch (node.split)
            {
            case Node.Type.X:
                if (point.Y > node._val){
                    closestPointA = GetClosestPoint(point, node._left);
                }else{
                    closestPointA = GetClosestPoint(point, node._right);
                }
                break;
            case Node.Type.Y:
                if (point.X < node._val){
                    closestPointA = GetClosestPoint(point, node._left);
                }else{
                    closestPointA = GetClosestPoint(point, node._right);
                }
                break;
            }
            if (closestPointA != null)
                distanceSqA = (closestPointA.X - point.X)*(closestPointA.X - point.X) + (closestPointA.Y - point.Y)*(closestPointA.Y - point.Y);

            switch (node.split)
            {
            case Node.Type.X:
                if (point.Y > node._val){
                    if ((point.Y - node._val)*(point.Y - node._val) <= distanceSqA)
                        closestPointB = GetClosestPoint(point, node._right);
                }else{
                    if ((point.Y - node._val)*(point.Y - node._val) < distanceSqA)
                        closestPointB = GetClosestPoint(point, node._left);
                }
                break;
            case Node.Type.Y:
                if (point.X < node._val){
                    if ((point.X - node._val)*(point.X - node._val) <= distanceSqA)
                        closestPointB = GetClosestPoint(point, node._right);
                }else{
                    if ((point.X - node._val)*(point.X - node._val) < distanceSqA)
                        closestPointB = GetClosestPoint(point, node._left);
                }
                break;
            }
            if (closestPointB != null)
                distanceSqB = (closestPointB.X - point.X)*(closestPointB.X - point.X) + (closestPointB.Y - point.Y)*(closestPointB.Y - point.Y);
            return distanceSqA < distanceSqB ? closestPointA : closestPointB;
        }
コード例 #20
0
        // Возвращает число циклов 4, которые содержат данную вершину.
        private int CalculatCycles4(int i)
        {
            Node[] nodes = new Node[container.Size];
            for (int k = 0; k < container.Size; ++k)
                nodes[k] = new Node();
            int cyclesOfOrderi4 = 0;
            nodes[i].lenght = 0;
            nodes[i].ancestor = 0;
            Queue<int> q = new Queue<int>();
            q.Enqueue(i);
            int u;

            while (q.Count != 0)
            {
                u = q.Dequeue();
                List<int> l = container.Neighbourship[u];
                for (int j = 0; j < l.Count; ++j)
                    if (nodes[l[j]].lenght == -1)
                    {
                        nodes[l[j]].lenght = nodes[u].lenght + 1;
                        nodes[l[j]].ancestor = u;
                        q.Enqueue(l[j]);
                    }
                    else
                    {
                        if (nodes[u].lenght == 2 && nodes[l[j]].lenght == 1 && nodes[u].ancestor != l[j])
                        {
                            SortedList<int, int> cycles4I = new SortedList<int, int>();
                            cyclesOfOrderi4++;
                        }
                    }
            }

            return cyclesOfOrderi4;
        }
コード例 #21
0
        public void GetPointsInRange(PointDouble point, double radsquare, Node node, List<PointDouble> listOfPoints)
        {
            if (node == null)
                return;

            //this is a leaf node
            if (node._left == null && node._right == null)
            {
                foreach (PointDouble pt in node._bucket)
                {

                    if( (pt.X - point.X)*(pt.X - point.X) +
                        (pt.Y - point.Y)*(pt.Y - point.Y) < radsquare)
                    {
                        listOfPoints.Add(pt);
                    }
                }
                return;
            }

            switch (node.split)
            {
            case Node.Type.X:
                if (point.Y > node._val){
                    GetPointsInRange(point, radsquare, node._left, listOfPoints);
                    if ((point.Y - node._val)*(point.Y - node._val) <= radsquare)
                        GetPointsInRange(point, radsquare, node._right, listOfPoints);
                }else{
                    GetPointsInRange(point, radsquare,  node._right, listOfPoints);
                    if ((point.Y - node._val)*(point.Y - node._val) < radsquare)
                        GetPointsInRange(point, radsquare, node._left, listOfPoints);

                }

                break;
            case Node.Type.Y:
                if (point.X < node._val){
                    GetPointsInRange(point, radsquare, node._left, listOfPoints);
                    if ((point.X - node._val)*(point.X - node._val) <= radsquare)
                        GetPointsInRange(point, radsquare, node._right, listOfPoints);

                }else{
                    GetPointsInRange(point, radsquare, node._right, listOfPoints);
                    if ((point.X - node._val)*(point.X - node._val) < radsquare)
                        GetPointsInRange(point, radsquare, node._left, listOfPoints);

                }
                break;
            }
        }
コード例 #22
0
        // Возвращает длину минимальной пути между данными вершинами.
        private int MinimumWay(int i, int j)
        {
            if (i == j)
                return 0;

            Node[] nodes = new Node[container.Size];
            for (int k = 0; k < container.Size; ++k)
                nodes[k] = new Node();

            BFS(i, nodes);

            return nodes[j].lenght;
        }
コード例 #23
0
ファイル: Collision.cs プロジェクト: ocdy1001/MonogameCore
 public QuadTree()
 {
     root = new Node(null, new AABB(0,0,0,0), 0);
     minmax = new AABB(0,0,0,0);
     cols = new List<_collider>();
 }