Пример #1
0
 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();
 }
Пример #2
0
 // 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);
 }
Пример #3
0
 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();
 }
Пример #4
0
        public GlGraphNode CreateNewNode()
        {
            GlGraphNode new_node = new GlGraphNode(this);

            AllNodesByGuid.Add(new_node.NodeUID, new_node);
            return(new_node);
        }
Пример #5
0
 public void Delete()
 {
     _ParentGraph.GlNodeRef.Kill(GlobalsGraphAdmin.GL_EDGES_SUBSCRIPT, SourceNode.NodeUID.ToString(), TargetNode.NodeUID.ToString());
     Detach();
     source_node = null;
     target_node = null;
 }
Пример #6
0
 public int Distance(GlGraphNode start_node, GlGraphNode end_node)
 {
     try
     {
         return(ShortestPath(start_node, end_node).Count);
     }
     catch
     {
         return(-1);
     }
 }
Пример #7
0
 // 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);
     }
 }
Пример #8
0
 // 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));
     }
 }
Пример #9
0
        // 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();
        }
Пример #10
0
        // 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
        }
Пример #11
0
        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();
        }
Пример #12
0
        // 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
        }
Пример #13
0
 public void ReOrient(GlGraphNode new_target)
 {
     Detach();
     target_node = new_target;
     Attach();
 }
Пример #14
0
 public static string GetNodeName(GlGraphNode any_node)
 {
     return any_node.GetCustomString(NODE_NAME_PROPERTY);
 }
Пример #15
0
 // constructors
 public NodeWrapper(GlGraphNode existing_node_from_db)
 {
     _api_graph_node = existing_node_from_db;
 }
Пример #16
0
 public GlGraphNode CreateNewNode()
 {
     GlGraphNode new_node = new GlGraphNode(this);
     AllNodesByGuid.Add(new_node.NodeUID, new_node);
     return new_node;
 }
Пример #17
0
 // 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;
 }
Пример #18
0
 public int Distance(GlGraphNode start_node, GlGraphNode end_node)
 {
     try
     {
         return ShortestPath(start_node, end_node).Count;
     }
     catch
     {
         return -1;
     }
 }