Beispiel #1
0
        private void InitializeAdjacencyList()
        {
            m_adjacencyList = new VertexAdjacencyList();

            List <VertexCluster>      vertexClusters = new List <VertexCluster>();
            List <VertexAdjacencyRow> adjacencyRows  = new List <VertexAdjacencyRow>();

            foreach (Node node in m_vertexSet)
            {
                VertexCluster        vertexCluster     = new VertexCluster(node.InternalID);
                List <VertexCluster> vertexAdjacencies = new List <VertexCluster>();

                foreach (SwitchingDeviceBase switchingDevice in m_edgeSet)
                {
                    if (node.InternalID == switchingDevice.FromNode.InternalID)
                    {
                        vertexAdjacencies.Add(new VertexCluster(switchingDevice.ToNode.InternalID));
                    }
                    else if (node.InternalID == switchingDevice.ToNode.InternalID)
                    {
                        vertexAdjacencies.Add(new VertexCluster(switchingDevice.FromNode.InternalID));
                    }
                }

                m_adjacencyList.Rows.Add(new VertexAdjacencyRow(vertexCluster, vertexAdjacencies));
            }
        }
 /// <summary>
 /// Merges the target <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> with this instance of <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/>
 /// </summary>
 /// <param name="cluster">The target <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> to merge with.</param>
 public void MergeWith(VertexCluster cluster)
 {
     foreach (int vertex in cluster.Vertices)
     {
         m_vertices.Add(vertex);
     }
 }
Beispiel #3
0
        private void InitializeSeriesImpedanceAdjacencyList()
        {
            m_seriesImpedanceConnectedAdjacencyList = new VertexAdjacencyList();

            List <VertexCluster>      vertexClusters = new List <VertexCluster>();
            List <VertexAdjacencyRow> adjacencyRows  = new List <VertexAdjacencyRow>();

            foreach (Node node in m_vertexSet)
            {
                VertexCluster        vertexCluster     = new VertexCluster(node.InternalID);
                List <VertexCluster> vertexAdjacencies = new List <VertexCluster>();

                foreach (ITwoTerminal seriesBranch in m_edgeSet)
                {
                    if (node.InternalID == seriesBranch.FromNode.InternalID)
                    {
                        vertexAdjacencies.Add(new VertexCluster(seriesBranch.ToNode.InternalID));
                    }
                    else if (node.InternalID == seriesBranch.ToNode.InternalID)
                    {
                        vertexAdjacencies.Add(new VertexCluster(seriesBranch.FromNode.InternalID));
                    }
                }

                m_seriesImpedanceConnectedAdjacencyList.Rows.Add(new VertexAdjacencyRow(vertexCluster, vertexAdjacencies));
            }
        }
Beispiel #4
0
 /// <summary>
 /// Returns a boolen flag indicating whether the specified vertex cluster is an adjacency of the row.
 /// </summary>
 /// <param name="vertexCluster">The vertex cluster of interest.</param>
 /// <returns>A boolean flag indicating whether the specified vertex cluster is an adjacency of the row.</returns>
 public bool ContainsAdjacency(VertexCluster vertexCluster)
 {
     foreach (VertexCluster adjacency in m_adjacencies)
     {
         if (adjacency.Equals(vertexCluster))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
        /// <summary>
        /// Finds the row with the specified header vertex cluster.
        /// </summary>
        /// <param name="header">The specified header vertex cluster.</param>
        /// <returns>The row with the specified header.</returns>
        public VertexAdjacencyRow RowWithHeader(VertexCluster header)
        {
            foreach (VertexAdjacencyRow row in m_adjacencyRows)
            {
                if (row.Header.Equals(header))
                {
                    return(row);
                }
            }

            return(null);
        }
Beispiel #6
0
        /// <summary>
        /// Removes the specified vertex cluster from the list of adjacencies.
        /// </summary>
        /// <param name="vertexCluster">The resulting vertex cluster.</param>
        public void RemoveVertex(VertexCluster vertexCluster)
        {
            List <VertexCluster> updatedVertices = new List <VertexCluster>();

            foreach (VertexCluster adjacency in m_adjacencies)
            {
                if (!adjacency.Equals(vertexCluster))
                {
                    updatedVertices.Add(adjacency);
                }
            }

            m_adjacencies = updatedVertices;
        }
Beispiel #7
0
 public bool CoherencyExistsBetween(VertexCluster fromVertexCluster, VertexCluster toVertexCluster)
 {
     foreach (int fromVertex in fromVertexCluster.Vertices)
     {
         Node fromNode = m_vertexSet.Find(x => x.InternalID == fromVertex);
         foreach (int toVertex in toVertexCluster.Vertices)
         {
             Node toNode = m_vertexSet.Find(x => x.InternalID == toVertex);
             if (fromNode.Voltage.PositiveSequence.Measurement.IncludeInEstimator &&
                 toNode.Voltage.PositiveSequence.Measurement.IncludeInEstimator)
             {
                 PhasorPair vertexPair = new PhasorPair(fromNode.Voltage.PositiveSequence.Measurement, toNode.Voltage.PositiveSequence.Measurement);
                 if (vertexPair.AbsoluteAngleDeltaInDegrees < AngleDeltaThresholdInDegrees)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Beispiel #8
0
        /// <summary>
        /// Mergers two vertices together once a direct connection has been determined.
        /// </summary>
        /// <param name="fromVertexCluster">The vertex on the from side of the edge.</param>
        /// <param name="toVertexCluster">The vertex on the to side of the edge.</param>
        public void ConnectionEstablished(VertexCluster fromVertexCluster, VertexCluster toVertexCluster)
        {
            List <int> fromVertices = new List <int>();
            List <int> toVertices   = new List <int>();

            foreach (int vertex in fromVertexCluster.Vertices)
            {
                fromVertices.Add(vertex);
            }

            foreach (int vertex in toVertexCluster.Vertices)
            {
                toVertices.Add(vertex);
            }

            VertexCluster fromCluster = new VertexCluster(fromVertices);
            VertexCluster toCluster   = new VertexCluster(toVertices);

            VertexAdjacencyRow source = m_adjacencyList.RowWithHeader(fromVertexCluster);
            VertexAdjacencyRow target = m_adjacencyList.RowWithHeader(toVertexCluster);

            // Merge the two rows into one
            source.MergeWith(target);

            // Remove the old from the list
            m_adjacencyList.RemoveRow(target);

            // Update the vertices in the rest of the table
            foreach (VertexAdjacencyRow row in m_adjacencyList.Rows)
            {
                foreach (VertexCluster vertexCluster in row.Adjacencies)
                {
                    if (vertexCluster.Equals(fromCluster) || vertexCluster.Equals(toCluster))
                    {
                        vertexCluster.Vertices = source.Header.Vertices;
                    }
                }
                row.RemoveDuplicateVertexClusters();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Finds and returns the edge which connects to vertices.
        /// </summary>
        /// <param name="fromVertexCluster">The vertex for the from side of the potential edge.</param>
        /// <param name="toVertexCluster">The vertex for the to side of the potential edge.</param>
        /// <returns></returns>
        public SwitchingDeviceBase ConnectingEdgeBetween(VertexCluster fromVertexCluster, VertexCluster toVertexCluster)
        {
            foreach (SwitchingDeviceBase switchingDevice in m_edgeSet)
            {
                foreach (int fromVertex in fromVertexCluster.Vertices)
                {
                    foreach (int toVertex in toVertexCluster.Vertices)
                    {
                        if (switchingDevice.FromNode.InternalID == fromVertex && switchingDevice.ToNode.InternalID == toVertex)
                        {
                            return(switchingDevice);
                        }
                        else if (switchingDevice.FromNode.InternalID == toVertex && switchingDevice.ToNode.InternalID == fromVertex)
                        {
                            return(switchingDevice);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #10
0
 private bool HasChildOrDescendantNode(TreeNode <VertexCluster> currentNode, VertexCluster vertex)
 {
     if (currentNode.Value.Equals(vertex))
     {
         return(true);
     }
     else
     {
         foreach (TreeNode <VertexCluster> childNode in currentNode.Children)
         {
             if (childNode.Value.Equals(vertex))
             {
                 return(true);
             }
             else
             {
                 return(HasChildOrDescendantNode(childNode, vertex));
             }
         }
     }
     return(false);
 }
        /// <summary>
        /// Determines equality between two <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> objects by checking the contens of the <see cref="VertexCluster.Vertices"/> property to make sure that the source and target both contain the same values.
        /// </summary>
        /// <param name="target">The object to compare with.</param>
        /// <returns>A boolen flag indicating that the object is equal to the other object or not.</returns>
        public override bool Equals(object target)
        {
            // If parameter is null return false.
            if (target == null)
            {
                return(false);
            }

            // If parameter cannot be cast to VertexCluster return false.
            VertexCluster vertexCluster = target as VertexCluster;

            if ((object)vertexCluster == null)
            {
                return(false);
            }

            if (m_vertices.Count != vertexCluster.Vertices.Count)
            {
                return(false);
            }

            foreach (int vertex in m_vertices)
            {
                if (!vertexCluster.Vertices.Contains(vertex))
                {
                    return(false);
                }
            }

            foreach (int vertex in vertexCluster.Vertices)
            {
                if (!m_vertices.Contains(vertex))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #12
0
        /// <summary>
        /// Finds and returns the edge which connects to vertices.
        /// </summary>
        /// <param name="fromVertexCluster">The vertex for the from side of the potential edge.</param>
        /// <param name="toVertexCluster">The vertex for the to side of the potential edge.</param>
        /// <returns>The edge which connects to two vertices.</returns>
        public List <ITwoTerminal> ConnectingEdgeBetween(VertexCluster fromVertexCluster, VertexCluster toVertexCluster)
        {
            List <ITwoTerminal> seriesBranches = new List <ITwoTerminal>();

            foreach (ITwoTerminal seriesBranch in m_edgeSet)
            {
                foreach (int fromVertex in fromVertexCluster.Vertices)
                {
                    foreach (int toVertex in toVertexCluster.Vertices)
                    {
                        if (seriesBranch.FromNode.InternalID == fromVertex && seriesBranch.ToNode.InternalID == toVertex)
                        {
                            seriesBranches.Add(seriesBranch);
                        }
                        else if (seriesBranch.FromNode.InternalID == toVertex && seriesBranch.ToNode.InternalID == fromVertex)
                        {
                            seriesBranches.Add(seriesBranch);
                        }
                    }
                }
            }

            return(seriesBranches);
        }
Beispiel #13
0
 private TreeNode <VertexCluster> FindNodeInTreeWithValue(VertexCluster value)
 {
     return(m_rootNode.GetNodeAndAllSubtreeNodes().FirstOrDefault(node => node.Value.Equals(value)));
 }
Beispiel #14
0
 private bool AlreadyContainsNode(VertexCluster vertex)
 {
     return(HasChildOrDescendantNode(m_rootNode, vertex));
 }
Beispiel #15
0
 /// <summary>
 /// The designated constructor for the class.
 /// </summary>
 /// <param name="rowHeader">The vertex cluster header.</param>
 /// <param name="adjacencies">The vertex cluster adjacencies.</param>
 public VertexAdjacencyRow(VertexCluster rowHeader, List <VertexCluster> adjacencies)
 {
     m_rowHeader   = rowHeader;
     m_adjacencies = adjacencies;
 }
 /// <summary>
 /// Merges two <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> and returns the result.
 /// </summary>
 /// <param name="cluster">The <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> to merge with.</param>
 /// <returns>A <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> which is a union set of the source and target <see cref="SynchrophasorAnalytics.Graphs.VertexCluster"/> objects.</returns>
 public VertexCluster MergeToFormNewCluster(VertexCluster cluster)
 {
     this.MergeWith(cluster);
     return(this);
 }