public AddEdge() { InitializeComponent(); GPH = new GraphFile(); graph = GPH.GetGraph(); from = to = string.Empty; }
public static void MakeGraphStructureFalse(GraphStructure graph) { graph.Flag = false; if (graph.Output == null) { return; } foreach (var nextElement in graph.Output) { MakeGraphStructureFalse(nextElement); } }
public static void UpdateInputs(GraphStructure node, GraphStructure inputNode) { foreach (var inputs in inputNode.Input) { if (!node.Input.Contains(inputs)) { node.Input.Add(inputs); } } if (node.Output == null) { return; } foreach (var output in node.Output) { UpdateInputs(output, node); } }
public static void CreateGraphByStructure(GraphStructure structure, RectangularGraph graph) { structure.Flag = true; if (structure.Output != null) { foreach (var node in structure.Output) { if (!node.Flag) { RectangularGraph temp = new RectangularGraph(30, 30); temp.NextElements = new List <RectangularGraph>(); temp.Content.Identificator = node.Identificator; graph.NextElements.Add(temp); CreateGraphByStructure(node, temp); } } } else { graph.NextElements = null; } }
private void GenerateGraph(GraphStructure stGraph) { Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph(stGraph.Header.GraphName); if (stGraph.Records.Count > 1) { for (int i = 0; i < stGraph.Records.Count; i++) { for (int j = 0; j < stGraph.Records.Count; j++) { string source = stGraph.Records.ElementAt(i).VertexName; string target = stGraph.Header.Vertices.ElementAt(j); string label = stGraph.Records.ElementAt(i).Edges.ElementAt(j); if (i != j && !(label.ToLower().Equals("inf"))) //if it's not pointing to itself or Inf(doesn't has an edge to target vertex) { graph.AddEdge(source: source, edgeLabel: label, target: target); //add vertices and make an edge between them RequireAttributes(graph.FindNode(source) as Node); } } } } this.gViewer.Graph = graph; }
public static RectangularGraph GenerateGraphStructure(int number, int maxLines) { var nodes = new GraphStructure[number]; for (int i = 0; i < number; i++) { nodes[i].Identificator = i; nodes[i].Input = new List <GraphStructure>(); nodes[i].Output = new List <GraphStructure>(); } var random = new Random(); for (int i = 1; i < number; i++) { var count = random.Next(maxLines); for (int j = 0; j < count; j++) { bool error; int maxiterations = 0; do { var value = random.Next(1, number); error = (value == i) || (nodes[i].Input.Contains(nodes[value])) || (nodes[i].Output.Contains(nodes[value])); if (!error) { nodes[i].Output.Add(nodes[value]); nodes[value].Input.Add(nodes[i]); UpdateInputs(nodes[value], nodes[i]); } maxiterations++; } while (error && maxiterations < 20); } } for (int i = 1; i < number; i++) { if (nodes[i].Input.Count == 0) { nodes[0].Output.Add(nodes[i]); } } MakeGraphStructureFalse(nodes[0]); var result = new RectangularGraph[number]; for (int i = 0; i < number; i++) { result[i] = new RectangularGraph(30, 30); } for (int i = 0; i < number; i++) { result[i].NextElements = new List <RectangularGraph>(); result[i].Content.Identificator = i; if (nodes[i].Output != null) { foreach (var node in nodes[i].Output) { result[i].NextElements.Add(result[node.Identificator]); } } } return(result[0]); }