コード例 #1
0
        public void ReadGraph(string FileName)
        {
            StreamReader sw = new StreamReader(FileName);

            nodes = new List <NodeC>();
            int    a = int.Parse(sw.ReadLine());
            string name;
            int    x, y;

            for (int i = 0; i < a; i++)
            {
                name = sw.ReadLine();
                string   s = sw.ReadLine();
                string[] q = s.Split();
                x = int.Parse(q[0]);
                y = int.Parse(q[1]);
                NodeC node = new NodeC(x, y, name);
                nodes.Add(node);
            }
            int[,] c = new int[a, a];

            for (int i = 0; i < a; i++)
            {
                string   t = sw.ReadLine();
                string[] p = t.Split();
                for (int j = 0; j < a; j++)
                {
                    c[i, j] = int.Parse(p[j]);
                }
            }
            CreateEdge(c);
            sw.Close();
        }
コード例 #2
0
        public bool ChooseFriendTrue(NodeC n1, NodeC n2, double x, double y)
        {
            LineC l1 = new LineC(n1.x, n1.y, n2.x, n2.y); //line between nodes
            LineC l2 = new LineC(n1.x, n1.y, l1);         //line normal to l1 through n1
            LineC l3 = new LineC(n2.x, n2.y, l1);         //line normal to l1 through n2

            return(LineC.IsBetweenLines(x, y, l2, l3) && LineC.IsOnLine(x, y, 5000, l1));
        }
コード例 #3
0
        private GroupC GroupsGo(int n)
        {
            GroupC groups     = new GroupC(new List <NodeC>());
            NodeC  maxenemies = CheckMaxEnemies(cs);

            groups.nodesingroup.Add(maxenemies);
            AddFriends(maxenemies, groups, n);
            GroupColor(groups);
            return(groups);
        }
コード例 #4
0
 public int GetIndexInAllNodes(NodeC f)
 {
     for (int i = 0; i < nodes.Count; i++)
     {
         if (nodes[i] == f)
         {
             return(i);
         }
     }
     return(-1);
 }
コード例 #5
0
 public int GetNodeIndex(NodeC node)
 {
     for (int i = 0; i < nodes.Count; i++)
     {
         if (nodes[i] == node)
         {
             return(i);
         }
     }
     return(-1);
 }
コード例 #6
0
ファイル: GroupC.cs プロジェクト: NastyaP1/GraphProgram
        public int NumberOfEnemies(NodeC a)
        {
            int count = 0;

            for (int i = 0; i < a.edge.Count; i++)
            {
                if (nodesingroup.Contains(a.edge[i].Neighbour) && a.edge[i].relation == 2)
                {
                    count++;
                }
            }
            return(count);
        }
コード例 #7
0
        public void DrawNode(Graphics graphics, NodeC node)
        {
            Pen        pen      = new Pen(Color.Black, 3);
            Font       font     = new Font("Arial", 10, FontStyle.Regular);
            SolidBrush sb       = new SolidBrush(node.color);
            SolidBrush sbstring = new SolidBrush(Color.Black);

            graphics.DrawEllipse(pen, node.x - radius, node.y - radius, 3 * radius, 3 * radius);
            graphics.FillEllipse(sb, node.x - radius, node.y - radius, 3 * radius, 3 * radius);
            graphics.DrawString(node.name + ":" + c.GetIndexByName(node.name) + ":" + node.NumberOfEnemies() + ":" + node.NumberOfFriends() + ":" + node.GroupNumber, font, sbstring, node.x, node.y);
            graphics.DrawString(node.names, font, Brushes.Black, node.x - 20, node.y - 27);

            //graphics.DrawString(c.GetIndexByName(node.name) + ":" + node.Count.ToString(), font, sbstring, node.x, node.y);
        }
コード例 #8
0
 private void AddFriends(NodeC a, GroupC groups, int n)
 {
     for (int i = 0; i < a.edge.Count; i++)
     {
         if (cs.Contains(a) && cs.Contains(a.edge[i].Neighbour))
         {
             if (TestEdge(GetNodeIndex(a.edge[i].Neighbour), GetNodeIndex(a)) && a.edge[i].relation == 1)
             {
                 groups.nodesingroup.Add(a.edge[i].Neighbour);
             }
         }
     }
     for (int i = 0; i < groups.nodesingroup.Count; i++)
     {
         if (!groups.CheckInt(n, groups.NumberOfEnemies(groups.nodesingroup[i])))
         {
             groups.nodesingroup.Remove(groups.CheckMaxEnemies());
         }
     }
 }