예제 #1
0
 /// <summary>
 /// 更换图
 /// </summary>
 public void ReplaceGraph(Graph __graph)
 {
     this.graph = __graph;
     this.panelGraph.Graph = this.graph;
     grammar = new Grammar.Grammar(this.graph);
     this.graph.OnAnyChange += GraphChange;
     SavePath = "";
 }
예제 #2
0
 public void AddGraph(Graph g)
 {
     this.panel1.Graph = g;
     vHelper = new GraphHelper(g);
 }
예제 #3
0
        private void InitialNewGraph(Graph graph)
        {
            if (graph == null) return;
            if (_graph != null)
            {
                //TODO:删除旧有的图属性
            }

            _graph = graph;

            //TODO:Initial
            graph.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0);
            Parallel.ForEach<IVertex>(Graph.Vertices, v =>
            {
                PointF location = new PointF(Random.Next(2, Width - 20), Random.Next(0, Height - 20));
                int radio = Random.Next(7, 12);
                RectangleF bound = new RectangleF(location.X - radio, location.Y - radio, radio * 2, radio*2);
                v.SetAlgorithmObj(_KH_PANE_LOCATION, location);
                v.SetAlgorithmObj(_KH_PANE_BOUNDS, bound);
                v.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0);
                v.SetAlgorithmObj(Flags.State.None.ToString(), false);
                v.SetAlgorithmObj(Flags.State.Focus.ToString(), false);
                v.SetAlgorithmObj(Flags.State.Hover.ToString(), false);
                v.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false);
                v.SetAlgorithmObj(Flags.State.Dragging.ToString(), false);
                v.SetAlgorithmObj(Flags.State.HighLight.ToString(), false);
                v.OnAttributeChange += OnAttributeChange;
            });

            Parallel.ForEach<IEdge>(Graph.Edges, e =>
            {
                e.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0);
                e.SetAlgorithmObj(Flags.State.None.ToString(), false);
                e.SetAlgorithmObj(Flags.State.Focus.ToString(), false);
                e.SetAlgorithmObj(Flags.State.Hover.ToString(), false);
                e.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false);
                e.SetAlgorithmObj(Flags.State.Dragging.ToString(), false);
                e.SetAlgorithmObj(Flags.State.HighLight.ToString(), false);
                e.OnAttributeChange += OnAttributeChange;
            });

            graph.OnAddVertex += OnAddVertex;
            graph.OnAddEdge += OnAddEdge;
            graph.OnAddType += OnAddType;
            graph.OnRemoveVertex += OnRemoveVertex;
            graph.OnRemoveEdge += OnRemoveEdge;
            graph.OnRemoveType += OnRemoveType;

            ghelper = new GraphHelper(_graph);

            System.Timers.Timer t = new System.Timers.Timer(1000);//实例化Timer
            t.Elapsed += new System.Timers.ElapsedEventHandler(theoutRefresh);//到达时间的时候执行事件;
            t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
            t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;

            this.Refresh();
        }
예제 #4
0
 public GraphWriter(Graph g)
 {
     _graph = g;
     Path = "KHGDB";
 }
예제 #5
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);
        }
예제 #6
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
        }
예제 #7
0
 public GraphReader(Graph g)
 {
     _graph = g;
     Path = "KHGDB";
     gHelper = new GraphHelper(_graph);
 }
예제 #8
0
        private void InitialNewGraph(Graph graph)
        {
            if (graph == null) return;
            if (_graph != null)
            {
                //TODO:删除旧有的图属性
            }

            _graph = graph;

            //TODO:Initial
            graph.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0);
            Parallel.ForEach<IVertex>(Graph.Vertices, v =>
            {
                PointF location = new PointF(Random.Next(2, Width - 20), Random.Next(0, Height - 20));
                int radio = Random.Next(7, 12);
                RectangleF bound = new RectangleF(location.X - radio, location.Y - radio, radio * 2, radio*2);
                v.SetAlgorithmObj(_KH_PANE_LOCATION, location);
                v.SetAlgorithmObj(_KH_PANE_BOUNDS, bound);
                v.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0);
                v.SetAlgorithmObj(Flags.State.None.ToString(), false);
                v.SetAlgorithmObj(Flags.State.Focus.ToString(), false);
                v.SetAlgorithmObj(Flags.State.Hover.ToString(), false);
                v.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false);
                v.SetAlgorithmObj(Flags.State.Dragging.ToString(), false);
                v.SetAlgorithmObj(Flags.State.HighLight.ToString(), false);
                v.OnAttributeGhange += OnAttributeChange;
            });

            Parallel.ForEach<IEdge>(Graph.Edges, e =>
            {
                e.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0);
                e.SetAlgorithmObj(Flags.State.None.ToString(), false);
                e.SetAlgorithmObj(Flags.State.Focus.ToString(), false);
                e.SetAlgorithmObj(Flags.State.Hover.ToString(), false);
                e.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false);
                e.SetAlgorithmObj(Flags.State.Dragging.ToString(), false);
                e.SetAlgorithmObj(Flags.State.HighLight.ToString(), false);
                e.OnAttributeGhange += OnAttributeChange;
            });

            graph.OnAddVertex += OnAddVertex;
            graph.OnAddEdge += OnAddEdge;
            graph.OnAddType += OnAddType;
            graph.OnRemoveVertex += OnRemoveVertex;
            graph.OnRemoveEdge += OnRemoveEdge;
            graph.OnRemoveType += OnRemoveType;

            ghelper = new GraphHelper(_graph);

            this.Refresh();
        }