コード例 #1
0
        public MutualFriend(string init, string[] raw)
        {
            this.accountName = init;
            DFS dfs = new DFS(raw);

            this.relation = new string[dfs.NumOfVertex - 1][];
            int count = 0;

            for (int i = 0; i < dfs.NumOfVertex; i++)
            {
                if (dfs.vertex[i][0] != init && !isFriend(init, dfs.vertex[i][0], raw))
                {
                    this.relation[count]    = new string[dfs.NumOfVertex];
                    this.relation[count][1] = dfs.vertex[i][0];
                    this.relation[count][0] = 0.ToString();
                    count++;
                }
            }
            this.NumOfRelation = count;
        }
コード例 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (!radioButton1.Checked && !radioButton2.Checked)
            {
                MessageBox.Show("Belum memilih metode!");
                return;
            }
            if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
            {
                MessageBox.Show("Belum memilih account!");
                return;
            }
            textBox2.Clear();
            DFS          dfs          = new DFS(this.contents);
            string       init         = comboBox1.SelectedItem.ToString();
            string       dest         = comboBox2.SelectedItem.ToString();
            MutualFriend mutualfriend = new MutualFriend(init, this.contents);

            mutualfriend.search(this.contents);
            mutualfriend.sortRelation();
            textBox2.AppendText(" Friend Recommendations for " + init + " :\r\n");
            for (int i = 0; i < mutualfriend.NumOfRelation; i++)
            {
                if (int.Parse(mutualfriend.relation[i][0]) != 0)
                {
                    textBox2.AppendText((i + 1).ToString() + ". " + mutualfriend.relation[i][1] + " ");
                    if (mutualfriend.relation[i][1] == dest)
                    {
                        if (radioButton1.Checked)
                        {
                            textBox2.AppendText(dfs.showDFS(init, dest, this.contents));
                        }
                        if (radioButton2.Checked)
                        {
                            BFS bfs = new BFS(this.contents);
                            textBox2.AppendText(bfs.ShowBFS(bfs.ExploreFriendBFS(init, dest)));
                        }
                    }
                    textBox2.AppendText("\r\n    ");
                    textBox2.AppendText(mutualfriend.relation[i][0] + " Mutual Friends : ");
                    for (int j = 0; j < int.Parse(mutualfriend.relation[i][0]); j++)
                    {
                        textBox2.AppendText(mutualfriend.relation[i][j + 2]);
                    }
                    textBox2.AppendText("\r\n");
                }
            }
            textBox2.AppendText("\r\n");
            textBox2.AppendText("Nama akun : " + init + " dan " + dest + "\r\n");
            if (radioButton1.Checked)
            {
                // mencari dengan DFS
                DFS    dfs2 = new DFS(this.contents);
                string text = dfs2.showDFS(init, dest, this.contents);

                // memprint hasil ke textBox2
                textBox2.AppendText(text);

                // mendeklarasikan delimiter untuk parsing text menjadi nodes
                char[]   dilimiter = { ' ', '-', '>', ',', '(', ')' };
                string[] hasil;

                // jika ditemukan koneksi
                if (!text.Equals("Tidak ada jalur koneksi yang tersedia"))
                {
                    hasil = text.Split(dilimiter);
                    // membuat list of node yg dikunjungi
                    List <string> edges = new List <string> {
                    };
                    foreach (string t in hasil)
                    {
                        if (g.Nodes.Contains(t))
                        {
                            edges.Add(t);
                        }
                    }

                    // merubah warna edge dan node
                    for (int i = 0; i < edges.Count() - 1; i++)
                    {
                        foreach (Microsoft.Msagl.Drawing.Edge E in gViewer1.Graph.Edges)
                        {
                            if ((E.Source.Equals(edges[i]) && E.Target.Equals(edges[i + 1])) || (E.Source.Equals(edges[i + 1]) && E.Target.Equals(edges[i])))
                            {
                                E.Attr.Color = Microsoft.Msagl.Drawing.Color.Blue;
                            }
                        }

                        /*
                         * if (i != 0 || i != edges.Count() - 1)
                         * {
                         *  gViewer1.Graph.FindNode(edges[i]).Attr.Color = Microsoft.Msagl.Drawing.Color.Green;
                         * }
                         */
                    }
                    gViewer1.Refresh();
                }
            }
            if (radioButton2.Checked)
            {
                // mencari dengan bfs
                BFS bfs2 = new BFS(this.contents);

                string text = bfs2.ShowBFS(bfs2.ExploreFriendBFS(init, dest));
                textBox2.AppendText(text);

                // mendeklarasikan delimiter untuk parsing text menjadi nodes
                char[]   dilimiter = { ' ', '-', '>', ',', '(', ')' };
                string[] hasil;

                // jika ditemukan koneksi
                if (!text.Equals("Tidak ada jalur koneksi yang tersedia"))
                {
                    hasil = text.Split(dilimiter);
                    // membuat list of node yg dikunjungi
                    List <string> edges = new List <string> {
                    };
                    foreach (string t in hasil)
                    {
                        if (g.Nodes.Contains(t))
                        {
                            edges.Add(t);
                        }
                    }

                    // merubah warna edge dan node
                    for (int i = 0; i < edges.Count() - 1; i++)
                    {
                        foreach (Microsoft.Msagl.Drawing.Edge E in gViewer1.Graph.Edges)
                        {
                            if ((E.Source.Equals(edges[i]) && E.Target.Equals(edges[i + 1])) || (E.Source.Equals(edges[i + 1]) && E.Target.Equals(edges[i])))
                            {
                                E.Attr.Color = Microsoft.Msagl.Drawing.Color.Blue;
                            }
                        }

                        /*
                         * if (i != 0 || i != edges.Count() - 1)
                         * {
                         *  gViewer1.Graph.FindNode(edges[i]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGreen;
                         * }
                         */
                    }
                    gViewer1.Refresh();
                }
            }
        }