Ejemplo n.º 1
0
        //
        // Adding an edge to the graph
        //
        public bool AddEdge(List <T> antecedent, T consequent, A annotation)
        {
            //
            // Add a local representaiton of this edge to each node in which it is applicable
            //
            if (HasEdge(antecedent, consequent))
            {
                return(false);
            }

            KeyValuePair <List <int>, int> local = ConvertToLocal(antecedent, consequent);

            HyperEdge <A> edge = new HyperEdge <A>(local.Key, local.Value, annotation);

//System.Diagnostics.Debug.WriteLine("Adding edge: " + edge.ToString());

            foreach (int src in local.Key)
            {
                vertices[src].AddEdge(edge);
            }

            // Add this as a target edge to the target node.
            vertices[local.Value].AddTargetEdge(edge);
            edgeCount++;

            return(true);
        }
Ejemplo n.º 2
0
        public void AddTargetEdge(HyperEdge <A> edge)
        {
            if (edge.targetNode != id)
            {
                throw new ArgumentException("Given node is not the target as advertised " + edge);
            }

            targetEdges.Add(edge);
        }
Ejemplo n.º 3
0
        // The source nodes and target must be the same for equality.
        public override bool Equals(object obj)
        {
            HyperEdge <A> thatEdge = obj as HyperEdge <A>;

            if (thatEdge == null)
            {
                return(false);
            }
            foreach (int src in sourceNodes)
            {
                if (!thatEdge.sourceNodes.Contains(src))
                {
                    return(false);
                }
            }
            return(targetNode == thatEdge.targetNode);
        }
Ejemplo n.º 4
0
        //
        // Adding an edge to the graph based on known indices.
        //
        public bool AddIndexEdge(List <int> antecedent, int consequent, A annotation)
        {
            if (HasLocalEdge(antecedent, consequent))
            {
                return(false);
            }

            HyperEdge <A> edge = new HyperEdge <A>(antecedent, consequent, annotation);

            foreach (int src in antecedent)
            {
                vertices[src].AddEdge(edge);
            }

            // Add this as a target edge to the target node.
            vertices[consequent].AddTargetEdge(edge);
            edgeCount++;

            return(true);
        }
Ejemplo n.º 5
0
 public void AddEdge(HyperEdge <A> edge)
 {
     edges.Add(edge);
 }