Beispiel #1
0
 public IType AddType(string ID, string Name, IDictionary<string, object> theAttributes = null)
 {
     if (SelectSingleType("name", Name) != null) return null;
     if (theAttributes == null)
     {
         IType t = new KHGraphDB.Structure.Type(ID, new Dictionary<string, object>(){
             {"name",Name}
         });
         return AddType(t);
     }
     else
     {
         theAttributes["name"] = Name;
         IType t = new KHGraphDB.Structure.Type(ID, theAttributes);
         return AddType(t);
     }
 }
Beispiel #2
0
 public IType AddType(string ID, string Name, IDictionary<string, object> theAttributes = null)
 {
     if (SelectSingleTypeName(Name) != null) return null;
     if (theAttributes == null)
     {
         IType t = new KHGraphDB.Structure.Type(ID);
         t.Name = Name;
         return AddType(t);
     }
     else
     {
         IType t = new KHGraphDB.Structure.Type(ID, theAttributes);
         t.Name = Name;
         return AddType(t);
     }
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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
        }
Beispiel #5
0
        public IEnumerable<IType> ReadAllTypes(StreamReader sr)
        {
            //Need Vertices
            while (!sr.EndOfStream)
            {
                string str = sr.ReadLine();
                string[] commands = str.Split(new char[] { ' ' });

                if (commands.Length < 4) continue;

                IType t = new KHGraphDB.Structure.Type(commands[0]);
                t.Name = commands[1];
                int iAttr = Convert.ToInt32(commands[2]);
                for (int i = 0; i < iAttr; i += 2)
                {
                    object o;
                    if (commands[i + 4][0] == '\'' && commands[i + 4][commands[i + 4].Length - 1] == '\'')
                        o = commands[i + 4].Trim(new char[] { '\'' });
                    else if (commands[i + 4] == "*")
                    {
                        o = null;
                    }
                    else if (commands[i + 4].Contains('.'))
                    {
                        o = Convert.ToDouble(commands[i + 4]);
                    }
                    else
                    {
                        o = Convert.ToInt32(commands[i + 4]);
                    }

                    t.Attributes[(string)(commands[i + 3])] = o;
                }
                int iVertex = Convert.ToInt32(commands[3 + iAttr * 2]);
                for (int i = 0; i < iVertex; i++)
                {
                    t.AddVertex(gHelper.SelectSingleVertex(commands[4 + iAttr * 2]));
                }

                gHelper.AddType(t);
            }
            return null;
        }