public AcceptVertexEventArgs(Vertex vertex) { Vertex = vertex; }
public AcceptVertexEventArgs(Vertex vertex, bool cancel) : base(cancel) { Vertex = vertex; }
public VertexEventArgs(Vertex vertex) { Vertex = vertex; }
public IVertex AddVertex(string ID, IDictionary<string, object> theAttributes, KHGraphDB.Structure.Type type = null) { IVertex v = new Vertex(ID, theAttributes); return AddVertex(v, type); }
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); }
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 }
public IEnumerable<IVertex> ReadAllVertices(StreamReader sr) { //Need Vertices while (!sr.EndOfStream) { string str = sr.ReadLine(); string[] commands = str.Split(new char[] { ' ' }); if (commands.Length < 2) continue; IVertex v = new KHGraphDB.Structure.Vertex(commands[0]); int iAttr = Convert.ToInt32(commands[1]); for (int i = 0; i < iAttr; i += 2) { object o; if (commands[i + 3][0] == '\'' && commands[i + 3][commands[i+3].Length - 1] == '\'') o = commands[i + 3].Trim(new char[] { '\'' }); else if (commands[i + 3] == "*") { o = null; } else if (commands[i + 3].Contains('.')) { o = Convert.ToDouble(commands[i + 3]); } else { o = Convert.ToInt32(commands[i + 3]); } v.Attributes[(string)(commands[i + 2])] = o; } gHelper.AddVertex(v); } return null; }