コード例 #1
0
ファイル: Program.cs プロジェクト: kinghand/KHGraphDB
        static void Main(string[] args)
        {
            Graph graph = new Graph();

            KHGraphDB.Structure.Type student = new KHGraphDB.Structure.Type(new Dictionary<string, object>(){
                {"Name",null}, {"Num",null}
            });
            student.Name = "Student";

            Vertex peiming = new Vertex(new Dictionary<string, object>(){
                {"Name","Peiming"},
                {"Age","22"},
                {"Game","Gal"}
            });

            Vertex weidong = new Vertex(new Dictionary<string, object>(){
                {"Name","Weidong"},
                {"Age","22"}
            });

            Vertex yidong = new Vertex(new Dictionary<string, object>(){
                {"Name","Yidong"},
                {"Age","21"}
            });

            GraphHelper gHelper = new GraphHelper(graph);

            gHelper.AddType(student);
            gHelper.AddVertex(peiming, student);
            graph.AddVertex(yidong, student);
            graph.AddVertex(weidong);

            Console.WriteLine(peiming.ToString());
            Console.WriteLine(yidong.ToString());
            Console.WriteLine(weidong.ToString());

            Console.WriteLine(peiming.IncomingEdges.Count());
            Console.WriteLine(yidong.IncomingEdges.Count());
            Console.WriteLine(weidong.IncomingEdges.Count());

            Edge friendPY = new Edge(peiming, yidong, new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase){
                {"friend",null},
            });

            Edge friendYP = new Edge(yidong, peiming, new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase){
                {"friend",null},
            });

            Edge friendYW = new Edge(yidong, weidong, new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase){
                {"friend",10},
            });

            graph.AddEdge(friendPY);
            graph.AddEdge(friendYP);
            graph.AddEdge(friendYW);

            gHelper.AddEdge(peiming, weidong, new Dictionary<string, object>() { { "friend", null } });

            Console.WriteLine(peiming.InDegree);
            Console.WriteLine(peiming.OutDegree);
            Console.WriteLine(yidong.InDegree);
            Console.WriteLine(yidong.OutDegree);
            Console.WriteLine(weidong.InDegree);
            Console.WriteLine(weidong.OutDegree);

            Console.WriteLine(peiming.ToString());
            Console.WriteLine(yidong.ToString());
            Console.WriteLine(weidong.ToString());

            Console.WriteLine(weidong["Name"]);
            Console.WriteLine("+++");

            BreadthFirstSearch bfs01 = new BreadthFirstSearch();
            var path = bfs01.Search(graph, peiming, weidong);

            foreach (var v in path)
            {
                Console.WriteLine(v["Name"]);
            }

            BreadthFirstSearch bfs02 = new BreadthFirstSearch();
            path = bfs02.Search(graph, peiming, weidong, false);

            foreach (var v in path)
            {
                Console.WriteLine(v["Name"]);
            }

            BreadthFirstSearch bfs03 = new BreadthFirstSearch();
            path = bfs03.Search(graph, weidong, peiming);

            if(null != path )
            foreach (var v in path)
            {
                Console.WriteLine(v["Name"]);
            }

            Console.ReadKey(true);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 form = new Form1();
            form.AddGraph(graph);
            Application.Run(form);
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: kinghand/KHGraphDB
        private void Form1_Load(object sender, EventArgs e)
        {
            panelMain.MouseDown += FormMain_MouseDown;
            panelMain.MouseUp += FormMain_MouseUp;
            panelMain.MouseMove += FormMain_MouseMove;
            lbTitle.MouseDown += FormMain_MouseDown;
            lbTitle.MouseUp += FormMain_MouseUp;
            lbTitle.MouseMove += FormMain_MouseMove;
            pbLogo.MouseDown += FormMain_MouseDown;
            pbLogo.MouseUp += FormMain_MouseUp;
            pbLogo.MouseMove += FormMain_MouseMove;

            textArea1.PressControlEnter += textArea1_PressControlEnter;

            #region Graph test

            graph = new Graph();
            grammar = new Grammar.Grammar(graph);

            KHGraphDB.Structure.Type student = new KHGraphDB.Structure.Type(new Dictionary<string, object>(){
                {"Name",null},{"Num",null}
            });
            student.Name = "Student";

            Vertex peiming = new Vertex(new Dictionary<string, object>(){
                {"Name","Peiming"},
                {"Age","22"},
                {"Game","Gal"}
            });

            Vertex weidong = new Vertex(new Dictionary<string, object>(){
                {"Name","Weidong"},
                {"Age","22"}
            });

            Vertex yidong = new Vertex(new Dictionary<string, object>(){
                {"Name","Yidong"},
                {"Age","21"}
            });

            graph.AddType(student);

            graph.AddVertex(peiming, student);
            graph.AddVertex(yidong, student);
            graph.AddVertex(weidong, student);

            Edge friendPY = new Edge(peiming, yidong, new Dictionary<string, object>(){
                {"relationship","friend"},
            });

            Edge friendYW = new Edge(yidong, weidong, new Dictionary<string, object>(){
                {"relationship","friend"},
            });

            graph.AddEdge(friendPY);
            graph.AddEdge(friendYW);

            panelGraph.Graph = graph;
            this.graph.OnAnyChange += GraphChange;
            #endregion
        }