示例#1
0
        public void dfsrecommend(string s)
        {
            int  aktif      = this.searchIdxNode(s);
            node node_aktif = this.nodes[aktif];
            //copy adj
            graph adj_aktif = new graph();

            foreach (node i in node_aktif.adjacent)
            {
                adj_aktif.addNode(i);
            }
            graph friend_recommend = new graph();

            foreach (node i in this.nodes)
            {
                node temp = new node(i.vertex);
                if (temp.vertex != node_aktif.vertex && (!adj_aktif.contain(temp.vertex)))
                {
                    friend_recommend.addNode(temp);
                }
                foreach (node j in i.adjacent)
                {
                    int num = adj_aktif.searchIdxNode(j.vertex);
                    if (num != -1)
                    {
                        temp.addAdj(adj_aktif.nodes[num]);
                    }
                }
            }
            friend_recommend.AllInfo();
        }
示例#2
0
        public graph bfs(string vertexawal, string vertextujuan, graph strippedGraph)
        {
            node  awal           = this.nodes[searchIdxNode(vertexawal)];
            node  tujuan         = this.nodes[searchIdxNode(vertextujuan)];
            graph travelledNodes = new graph();
            graph parentsGraph   = new graph();
            int   idxTrav;

            if (awal.adjCount() != 0)
            // Kalau tidak trigger, return list node isi node awal saja
            {
                travelledNodes.addNode(awal);
                parentsGraph.nodes.Add(this.nodes[searchIdxNode(vertexawal)]);
                idxTrav = 0;
                bfsRekurs(idxTrav, tujuan, travelledNodes, parentsGraph);


                int i = travelledNodes.nodes.Count - 1;
                while (i > 0)
                {
                    strippedGraph.nodes.Insert(0, travelledNodes.nodes[i]);
                    i = travelledNodes.searchIdxNode(parentsGraph.nodes[i].vertex);
                }
            }
            strippedGraph.nodes.Insert(0, travelledNodes.nodes[0]);
            return(travelledNodes);
        }
示例#3
0
        public void dfsrecommend(string s, RichTextBox rtb)
        {
            graph g = new graph();

            foreach (node i in this.nodes)
            {
                g.addNode(i);
            }
            int  aktif      = g.searchIdxNode(s);
            node node_aktif = g.nodes[aktif];
            //copy adj
            graph adj_aktif = new graph();

            foreach (node i in node_aktif.adjacent)
            {
                adj_aktif.addNode(i);
            }
            graph friend_recommend = new graph();

            foreach (node i in g.nodes)
            {
                node temp = new node(i.vertex);
                if (temp.vertex != node_aktif.vertex && (!adj_aktif.contain(temp.vertex)))
                {
                    friend_recommend.addNode(temp);
                }
                foreach (node j in i.adjacent)
                {
                    int num = adj_aktif.searchIdxNode(j.vertex);
                    if (num != -1)
                    {
                        temp.addAdj(adj_aktif.nodes[num]);
                    }
                }
            }
            rtb.AppendText("Daftar rekomendasi teman untuk akun " + s + ":\n");
            Boolean HasRecom = false;

            foreach (node i in friend_recommend.nodes)
            {
                if (i.adjCount() > 0)
                {
                    HasRecom = true;
                }
            }
            if (HasRecom)
            {
                friend_recommend.sortGraphDescAdjCount();
                friend_recommend.AllInfo(rtb);
            }
            else
            {
                rtb.AppendText("Tidak ada yang cocok.\n");
            }
        }
示例#4
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            NamaFile.Text = openFileDialog1.FileName;
            string[] lines = System.IO.File.ReadAllLines(NamaFile.Text);
            a.nodes.Clear();
            foreach (string line in lines)
            {
                string[] y = line.Split(" ");
                if (!a.contain(y[0]))
                {
                    node temp = new node(y[0]);
                    a.addNode(temp);
                    if (!a.contain(y[1]))
                    {
                        node temp1 = new node(y[1]);
                        a.addNode(temp1);
                        temp.addAdj(temp1);
                    }
                    else
                    {
                        foreach (node i in a.nodes)
                        {
                            if (i.vertex == y[1])
                            {
                                temp.addAdj(i);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < a.nodes.Count; i++)
                    {
                        if (a.nodes[i].vertex == y[0])
                        {
                            if (!a.contain(y[1]))
                            {
                                node temp1 = new node(y[1]);
                                a.addNode(temp1);
                                a.nodes[i].addAdj(temp1);
                            }
                            else
                            {
                                foreach (node j in a.nodes)
                                {
                                    if (j.vertex == y[1])
                                    {
                                        a.nodes[i].addAdj(j);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            richTextBox1.Text = File.ReadAllText(NamaFile.Text);
            Awal.Items.Clear();
            Akhir.Items.Clear();
            Awal.Items.Add("NONE");
            Akhir.Items.Add("NONE");
            Awal.Text  = "NONE";
            Akhir.Text = "NONE";
            foreach (node i in a.nodes)
            {
                Awal.Items.Add(i.vertex);
                Akhir.Items.Add(i.vertex);
            }

            GraphPanel.Controls.Clear();
            //create a viewer object
            Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
            //create a graph object
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
            //create the graph content
            foreach (node i in a.nodes)
            {
                foreach (node j in a.nodes[a.searchIdxNode(i.vertex)].adjacent)
                {
                    graph.AddEdge(i.vertex, j.vertex);
                }
            }
            //bind the graph to the viewer
            viewer.Graph = graph;

            //associate the viewer with the form
            GraphPanel.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            GraphPanel.Controls.Add(viewer);
            GraphPanel.ResumeLayout();
            //show the form
            GraphPanel.Show();
        }