Exemplo n.º 1
0
        public override void Generate(int nodeCount, NodeHolder nodeHolder, EdgeHolder edgeHolder, string SelectedAlgorithm)
        {
            var arg = new PaintEventArgs(Drawing_panel.CreateGraphics(), new Rectangle());

            for (int i = 0; i < nodeCount; i++)
            {
                var interval = (Drawing_panel.Width - 80) / (nodeCount - 1);

                var p = new Point(40 + (interval * i), Drawing_panel.Height / 2);

                if (!nodeHolder.AnyIntersecting(p))
                {
                    var node = NodeFactory.Create(SelectedAlgorithm, nodeHolder.NodeCount, new WinformsNodeVisualiser(arg, p.X, p.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder);

                    nodeHolder.AddNode(node);
                }
                else
                {
                    MessageBox.Show("Nodes do not fit in screen");
                    break;
                }
            }
            ;

            for (int i = 0; i < nodeCount; i++)
            {
                if (i != nodeCount - 1)
                {
                    var node1 = nodeHolder.GetNodeAt(i);
                    var node2 = nodeHolder.GetNodeAt(i + 1);

                    edgeHolder.AddEgde(new WinformsEdge(arg, node1, node2));
                }
            }
        }
Exemplo n.º 2
0
        public override void Generate(int nodeCount, NodeHolder nodeHolder, EdgeHolder edgeHolder, string SelectedAlgorithm)
        {
            var arg = new PaintEventArgs(Drawing_panel.CreateGraphics(), new Rectangle());

            var radius = (Math.Min(Drawing_panel.Height, Drawing_panel.Width) - 80) / 2;
            var origin = new Point(Drawing_panel.Width / 2, Drawing_panel.Height / 2);

            for (int i = 0; i < nodeCount; i++)
            {
                var angle = 360 / (float)(nodeCount - 1) * i;

                var p = i == 0 ? origin : PointOnCircle(radius, angle, origin);

                if (!nodeHolder.AnyIntersecting(p))
                {
                    var node = NodeFactory.Create(SelectedAlgorithm, nodeHolder.NodeCount, new WinformsNodeVisualiser(arg, p.X, p.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder);

                    nodeHolder.AddNode(node);
                }
                else
                {
                    i--;
                }
            }
            ;

            for (int i = 0; i < nodeCount; i++)
            {
                var node1 = nodeHolder.GetNodeAt(0);
                var node2 = nodeHolder.GetNodeAt(i);

                edgeHolder.AddEgde(new WinformsEdge(arg, node1, node2));
            }
        }
        public override void Generate(int nodeCount, NodeHolder nodeHolder, EdgeHolder edgeHolder, string SelectedAlgorithm)
        {
            var arg = new PaintEventArgs(Drawing_panel.CreateGraphics(), new Rectangle());

            var queue = new Queue <int>();

            var totalHeight = Math.Floor(Math.Log(nodeCount, 2)) + 1;

            var verticalInterval = (int)((Drawing_panel.Height - 80) / (totalHeight - 1));

            for (int i = 0; i < nodeCount; i++)
            {
                var currentDepth = (int)Math.Floor(Math.Log(i + 1, 2));

                var horizontalInterval = (int)((Drawing_panel.Width) / (Math.Pow(2, currentDepth) + 1));

                var currentIndex = (int)(i - (Math.Pow(2, currentDepth) - 1) + 1);

                Console.WriteLine("i: {0}, depth: {1}, currentIndex: {2}", i, currentDepth, currentIndex);

                var p = new Point((currentIndex) * horizontalInterval, (currentDepth) * verticalInterval + 40);

                if (!nodeHolder.AnyIntersecting(p))
                {
                    var node = NodeFactory.Create(SelectedAlgorithm, nodeHolder.NodeCount, new WinformsNodeVisualiser(arg, p.X, p.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder);

                    nodeHolder.AddNode(node);
                }
                else
                {
                    throw new Exception("Reached to screen limits");
                }
            }
            ;

            for (int i = 1; i < nodeCount; i++)
            {
                queue.Enqueue(i);
            }

            for (int i = 0; i < nodeCount; i++)
            {
                var parent = nodeHolder.GetNodeAt(i);

                for (int j = 0; j < 2; j++)
                {
                    if (!queue.Any())
                    {
                        break;
                    }

                    var firstChildId = queue.Dequeue();
                    var child        = nodeHolder.GetNodeAt(firstChildId);

                    edgeHolder.AddEgde(new WinformsEdge(arg, parent, child));
                }
            }
        }
Exemplo n.º 4
0
        public override void Generate(int nodeCount, NodeHolder nodeHolder, EdgeHolder edgeHolder, string SelectedAlgorithm)
        {
            var arg = new PaintEventArgs(Drawing_panel.CreateGraphics(), new Rectangle());

            var horizontalInterval = (Drawing_panel.Width - 80) / 3;
            var verticalInterval   = (Drawing_panel.Height - 80) / ((nodeCount / 2) - (nodeCount % 2 == 0 ? 1 : 0));

            for (int i = 0; i < nodeCount; i++)
            {
                var x = i < nodeCount / 2 ?
                        40 + horizontalInterval :
                        40 + (horizontalInterval * 2);

                var y = 40 + (verticalInterval * (i < (nodeCount / 2) ?
                                                  i :
                                                  i - (nodeCount / 2)));

                var p = new Point(x, y);

                if (!nodeHolder.AnyIntersecting(p))
                {
                    var node = NodeFactory.Create(SelectedAlgorithm, nodeHolder.NodeCount, new WinformsNodeVisualiser(arg, p.X, p.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder);

                    nodeHolder.AddNode(node);
                }
                else
                {
                    i--;
                }
            }
            ;

            for (int i = 0; i < nodeCount / 2; i++)
            {
                for (int j = nodeCount / 2; j < nodeCount; j++)
                {
                    var node1 = nodeHolder.GetNodeAt(i);
                    var node2 = nodeHolder.GetNodeAt(j);

                    edgeHolder.AddEgde(new WinformsEdge(arg, node1, node2));
                }
            }
        }
        public override void Generate(int nodeCount, NodeHolder nodeHolder, EdgeHolder edgeHolder, string SelectedAlgorithm)
        {
            var arg = new PaintEventArgs(Drawing_panel.CreateGraphics(), new Rectangle());

            nodeCount = DeserializationContext.Nodes.Count;

            for (int i = 0; i < nodeCount; i++)
            {
                var _node = DeserializationContext.Nodes[i];

                var node = NodeFactory.Create(SelectedAlgorithm, _node.Id, new WinformsNodeVisualiser(arg, _node._Position.X, _node._Position.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder, _node._PredefinedState);

                nodeHolder.AddNode(node);
            }
            ;

            for (int i = 0; i < nodeCount; i++)
            {
                for (int j = i; j < nodeCount; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    if (!DeserializationContext.Nodes[i]._Neighbours.Contains(j))
                    {
                        continue;
                    }

                    var node1 = nodeHolder.GetNodeAt(i);
                    var node2 = nodeHolder.GetNodeAt(j);

                    edgeHolder.AddEgde(new WinformsEdge(arg, node1, node2));
                }
            }
        }
Exemplo n.º 6
0
        public override void Generate(int nodeCount, NodeHolder nodeHolder, EdgeHolder edgeHolder, string SelectedAlgorithm)
        {
            var arg = new PaintEventArgs(Drawing_panel.CreateGraphics(), new Rectangle());

            var radius = (Math.Min(Drawing_panel.Height, Drawing_panel.Width) - 80) / 2;
            var origin = new Point(Drawing_panel.Width / 2, Drawing_panel.Height / 2);

            var randomizer = new Random();

            for (int i = 0; i < nodeCount; i++)
            {
                var angle = 360 / (float)nodeCount * i;

                var p = PointOnCircle(radius, angle, origin);

                if (!nodeHolder.AnyIntersecting(p))
                {
                    var node = NodeFactory.Create(SelectedAlgorithm, nodeHolder.NodeCount, new WinformsNodeVisualiser(arg, p.X, p.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder, randomizer.Next(0, 3));

                    nodeHolder.AddNode(node);
                }
                else
                {
                    i--;
                }
            }
            ;
            //for (int i = 0; i < nodeCount; i++)
            //{
            //    var p = new Point(randomizer.Next(40, Drawing_panel.Width - 40), randomizer.Next(40, Drawing_panel.Height - 40));

            //    if (!nodeHolder.AnyIntersecting(p))
            //    {
            //        var node = NodeFactory.Create(SelectedAlgorithm, nodeHolder.NodeCount, new WinformsNodeVisualiser(arg, p.X, p.Y, nodeHolder.NodeCount, ParentForm), ParentForm.cb_selfStab.Checked, nodeHolder);

            //        nodeHolder.AddNode(node);
            //    }
            //    else
            //    {
            //        i--;
            //    }
            //};

            for (int i = 0; i < nodeCount; i++)
            {
                if (i != nodeCount - 1)
                {
                    var node1 = nodeHolder.GetNodeAt(i);
                    var node2 = nodeHolder.GetNodeAt(i + 1);

                    edgeHolder.AddEgde(new WinformsEdge(arg, node1, node2));
                }
            }

            foreach (var node1 in nodeHolder.GetCopyList())
            {
                for (int i = 0; i < Grade; i++)
                {
                    if (node1.Neighbours.Count >= Grade)
                    {
                        break;
                    }
                    var nextNodeId = randomizer.Next(0, nodeCount);
                    while (nextNodeId == node1.Id || node1.IsNeigbourOf(nextNodeId))
                    {
                        nextNodeId = randomizer.Next(0, nodeCount);
                    }

                    edgeHolder.AddEgde(new WinformsEdge(arg, node1, nodeHolder.GetNodeById(nextNodeId)));
                }
                //foreach (var node2 in nodeHolder.GetCopyList().Where(n => n != node1))
                //{
                //    if (randomizer.Next() % 100 > 10) continue;

                //    if (node1.Neighbours.ContainsKey(node2.Id)) continue;

                //    edgeHolder.AddEgde(new WinformsEdge(arg, node1, node2));
                //}
            }
        }