private void buttonOK_Click(object sender, EventArgs e) { NodeWrapper chosen_node_wrapper = (NodeWrapper)comboTargetNodes.SelectedItem; ChosenNode = chosen_node_wrapper.GraphNode; //StartingNode.ConnectTo(chosen_node_wrapper.GraphNode); this.Close(); }
// creates a connection (edge) to the specified target node. If there // is already a connection, does nothing and returns null. public GlGraphEdge ConnectTo(GlGraphNode target_node) { if (FindConnectionTo(target_node) != null) return null; else return new GlGraphEdge(_ParentGraph, this, target_node, true); }
public void InitForNode(GlGraphNode _working_node) { this.Text = "Node properties"; working_node = _working_node; lblName.Text = "Node name: " + working_node.GetCustomString(NodeWrapper.NODE_NAME_PROPERTY); RebuildList(); }
public GlGraphNode CreateNewNode() { GlGraphNode new_node = new GlGraphNode(this); AllNodesByGuid.Add(new_node.NodeUID, new_node); return(new_node); }
public void Delete() { _ParentGraph.GlNodeRef.Kill(GlobalsGraphAdmin.GL_EDGES_SUBSCRIPT, SourceNode.NodeUID.ToString(), TargetNode.NodeUID.ToString()); Detach(); source_node = null; target_node = null; }
public int Distance(GlGraphNode start_node, GlGraphNode end_node) { try { return(ShortestPath(start_node, end_node).Count); } catch { return(-1); } }
// returns an edge pointing from the current node to the specified // node, IF ONE EXISTS. public GlGraphEdge FindConnectionTo(GlGraphNode target_node) { if (OutgoingEdges.ContainsKey(target_node)) { return(OutgoingEdges[target_node]); } else { return(null); } }
// creates a connection (edge) to the specified target node. If there // is already a connection, does nothing and returns null. public GlGraphEdge ConnectTo(GlGraphNode target_node) { if (FindConnectionTo(target_node) != null) { return(null); } else { return(new GlGraphEdge(_ParentGraph, this, target_node, true)); } }
// constructor is INTERNAL because client code should generate edges by using the graph node class's "ConnectTo" method internal GlGraphEdge(GlGraph parent_graph, GlGraphNode _source, GlGraphNode _target, bool create_in_db) { _ParentGraph = parent_graph; if (create_in_db) { parent_graph.GlNodeRef.Set(GlobalsGraphAdmin.GL_EDGE_FLAG, GlobalsGraphAdmin.GL_EDGES_SUBSCRIPT, _source.NodeUID.ToString(), _target.NodeUID.ToString()); } source_node = _source; target_node = _target; Attach(); }
// simple breadth-first search to find shortest path between two given nodes. // The parameter "allow_trivial_path" instructs the routine as to whether every node should be considered // to have a trivial 0-length path from itself to itself. If not, then the code will attempt to find a non-empty // one in such cases (either a 1-length path represented by an a->a loop edge, or else a larger one). public List <GlGraphEdge> ShortestPath(GlGraphNode start_node, GlGraphNode end_node, bool allow_trivial_path = true) { if (start_node == end_node && allow_trivial_path) { return(new List <GlGraphEdge>()); } Dictionary <GlGraphNode, List <GlGraphEdge> > paths_by_node = new Dictionary <GlGraphNode, List <GlGraphEdge> >(); List <GlGraphNode> current_generation = new List <GlGraphNode>(); current_generation.Add(start_node); do { List <GlGraphNode> next_generation = new List <GlGraphNode>(); foreach (GlGraphNode current_node in current_generation) { foreach (GlGraphEdge next_edge in current_node.OutgoingEdges.Values) { GlGraphNode next_node = next_edge.TargetNode; if (!paths_by_node.ContainsKey(next_node)) { if (current_node == start_node) { // no path object yet paths_by_node[next_node] = new List <GlGraphEdge>(); } else { // base new node's path on previous steps paths_by_node[next_node] = new List <GlGraphEdge>(paths_by_node[current_node]); } paths_by_node[next_node].Add(next_edge); if (next_node == end_node) { return(paths_by_node[next_node]); } next_generation.Add(next_node); } } } current_generation = next_generation; }while (current_generation.Count > 0); return(null); // none found }
public void InitForNewEdge(GlGraph working_graph, GlGraphNode start_node) { List<NodeWrapper> valid_targets = new List<NodeWrapper>(); foreach (GlGraphNode loop_node in working_graph.AllNodes) { if (start_node.FindConnectionTo(loop_node) == null) { valid_targets.Add(new NodeWrapper(loop_node)); } } comboTargetNodes.DisplayMember = "NodeName"; comboTargetNodes.DataSource = new BindingList<NodeWrapper>(valid_targets); comboTargetNodes.Refresh(); }
// simple breadth-first search to find shortest path between two given nodes. // The parameter "allow_trivial_path" instructs the routine as to whether every node should be considered // to have a trivial 0-length path from itself to itself. If not, then the code will attempt to find a non-empty // one in such cases (either a 1-length path represented by an a->a loop edge, or else a larger one). public List<GlGraphEdge> ShortestPath(GlGraphNode start_node, GlGraphNode end_node, bool allow_trivial_path = true) { if (start_node == end_node && allow_trivial_path) return new List<GlGraphEdge>(); Dictionary<GlGraphNode, List<GlGraphEdge>> paths_by_node = new Dictionary<GlGraphNode, List<GlGraphEdge>>(); List<GlGraphNode> current_generation = new List<GlGraphNode>(); current_generation.Add(start_node); do { List<GlGraphNode> next_generation = new List<GlGraphNode>(); foreach (GlGraphNode current_node in current_generation) { foreach (GlGraphEdge next_edge in current_node.OutgoingEdges.Values) { GlGraphNode next_node = next_edge.TargetNode; if (!paths_by_node.ContainsKey(next_node)) { if (current_node == start_node) { // no path object yet paths_by_node[next_node] = new List<GlGraphEdge>(); } else { // base new node's path on previous steps paths_by_node[next_node] = new List<GlGraphEdge>(paths_by_node[current_node]); } paths_by_node[next_node].Add(next_edge); if (next_node == end_node) return paths_by_node[next_node]; next_generation.Add(next_node); } } } current_generation = next_generation; } while (current_generation.Count > 0); return null; // none found }
public void ReOrient(GlGraphNode new_target) { Detach(); target_node = new_target; Attach(); }
public static string GetNodeName(GlGraphNode any_node) { return any_node.GetCustomString(NODE_NAME_PROPERTY); }
// constructors public NodeWrapper(GlGraphNode existing_node_from_db) { _api_graph_node = existing_node_from_db; }
public GlGraphNode CreateNewNode() { GlGraphNode new_node = new GlGraphNode(this); AllNodesByGuid.Add(new_node.NodeUID, new_node); return new_node; }
// returns an edge pointing from the current node to the specified // node, IF ONE EXISTS. public GlGraphEdge FindConnectionTo(GlGraphNode target_node) { if (OutgoingEdges.ContainsKey(target_node)) return OutgoingEdges[target_node]; else return null; }
public int Distance(GlGraphNode start_node, GlGraphNode end_node) { try { return ShortestPath(start_node, end_node).Count; } catch { return -1; } }