Esempio n. 1
0
    }   // End of AddEdge()

    // Removes the edge if presents.
    public override void RemoveEdge(int from, int to)
    {
        if ((from >= this.nodes.Count) || (to >= this.nodes.Count))
        {
            ErrorPrinter.PrintError("SparseGraph", "RemoveEdge", "THE INVALID EDGE BETWEEN from: " + from + " to: " + to, "Cihan");
        }
        else
        {
            EdgeCommons.RemoveFromLinkedList <EdgeType>(this.edges, from, to);
        }
    }
Esempio n. 2
0
    }   // End of AddEdge()

    // Removes the edge if presents.
    public override void RemoveEdge(int from, int to)
    {
        if ((from >= this.nodes.Count) || (to >= this.nodes.Count))
        {
            ErrorPrinter.PrintError("SparseGraph", "RemoveEdge", "THE INVALID EDGE BETWEEN from: " + from + " to: " + to, "Cihan");
            return;
        }

        if (from > to)
        {
            HelperMethods.Swap <int>(ref from, ref to);
        }

        EdgeCommons.RemoveFromLinkedList <EdgeType>(this.edges, from, to);

        // Remove from adjacency list too
        adjacencyList[from].Remove(to);
        adjacencyList[to].Remove(from);
    }
Esempio n. 3
0
    }     // End of SparseGraph.AddEdge()

    // Adds an edge to the graph. The method ensures that the edge is valid
    // before adding it to the graph.
    // WARNING THIS VERSION MAY CREATE GARBAGE
    public override void AddEdge(EdgeType edge)
    {
        // Make sure the from and to nodes exist within the graph
        if ((edge.FromNode >= nextNodeIndex) || (edge.ToNode >= nextNodeIndex))
        {
            ErrorPrinter.PrintError("SparseGraph", "AddEdge", "THE EDGE HAS INVALID INDICES: from: " + edge.FromNode + " to: " + edge.ToNode, "Cihan");
            return;
        }

        // Make sure both nodes are active before adding the edge
        if (
            (this.nodes[edge.ToNode].Id != NodeCommons.InvalidNodeId) &&
            (this.nodes[edge.FromNode].Id != NodeCommons.InvalidNodeId)
            )
        {
            if (edge.FromNode > edge.ToNode)
            {
                EdgeCommons.SwapEdgeNodes <EdgeType>(edge);
            }

            // Add the edge, first making sure it is unique
            if (IsUniqueEdge(edge.FromNode, edge.ToNode))
            {
                this.edges[edge.FromNode].AddLast(edge);

                // Insert to adjacency list too
                adjacencyList[edge.FromNode].AddLast(edge.ToNode);
                adjacencyList[edge.ToNode].AddLast(edge.FromNode);
            }
            else
            {
                ErrorPrinter.PrintError("SparseGraph", "AddEdge", "THE EDGE IS NOT UNIQUE: from: " + edge.FromNode + " to: " + edge.ToNode, "Cihan");
            }
        }
        else
        {
            ErrorPrinter.PrintError(
                "SparseGraph", "AddEdge", "THE EDGE HAS INACTIVE NODES: fromNode: " +
                this.nodes[edge.FromNode].Id + " toNode: " + this.nodes[edge.ToNode].Id,
                "Cihan"
                );
        }
    }   // End of AddEdge()