public static StudyCase DeserializeFromXml(string pathName)
        {
            try
            {
                // Create an empy NetworkMeasurements object reference.
                StudyCase collection = null;

                // Create an XmlSerializer with the type of NetworkMeasurements.
                XmlSerializer deserializer = new XmlSerializer(typeof(StudyCase));

                // Read the data in from the file.
                StreamReader reader = new StreamReader(pathName);

                // Cast the deserialized data as a NetworkMeasurements object.
                collection = (StudyCase)deserializer.Deserialize(reader);

                // Close the connection.
                reader.Close();

                return(collection);
            }
            catch (Exception exception)
            {
                throw new Exception("Failed to Deserialize the Network from the Configuration File: " + exception.ToString());
            }
        }
Exemple #2
0
        public NetworkTopology(string FilePath)  // System Configuration
        {
            #region [ Original Configuration ]
            //m_busOriginalLibrary = new int[] { 8, 9, 10, 26, 30, 38, 63, 64, 65, 68, 81 };
            //m_lineLibrary = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
            //m_lineSetCalibrateOriginal = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            //m_lineBusInfoOriginal = new int[24, 3] {{   1   ,   8   ,   9   }   ,
            //                                        {   2   ,   8   ,   30  }   ,
            //                                        {   3   ,   9   ,   10  }   ,
            //                                        {   4   ,   26  ,   30  }   ,
            //                                        {   5   ,   30  ,   38  }   ,
            //                                        {   6   ,   38  ,   65  }   ,
            //                                        {   7   ,   63  ,   64  }   ,
            //                                        {   8   ,   64  ,   65  }   ,
            //                                        {   9   ,   65  ,   68  }   ,
            //                                        {   10  ,   68  ,   81  }   ,
            //                                        {   11  ,   68  ,   116 }   ,
            //                                        {   12  ,   5   ,   8   }   ,
            //                                        {   13  ,   17  ,   30  }   ,
            //                                        {   14  ,   25  ,   26  }   ,
            //                                        {   15  ,   37  ,   38  }   ,
            //                                        {   16  ,   59  ,   63  }   ,
            //                                        {   17  ,   61  ,   64  }   ,
            //                                        {   18  ,   65  ,   66  }   ,
            //                                        {   19  ,   68  ,   69  }   ,
            //                                        {   20  ,   80  ,   81  }   ,
            //                                        {   21  ,   8   ,   -1  }   ,
            //                                        {   22  ,   10  ,   -1  }   ,
            //                                        {   23  ,   26  ,   -1  }   ,
            //                                        {   24  ,   65  ,   -1  }   };


            //m_lineParameters = new double[24, 4] {{   1   ,   0.00244 ,   0.030499999 ,   0.580999961 }   ,
            //                                     {   2   ,   0.00431 ,   0.050399998 ,   0.256999996 }   ,
            //                                     {   3   ,   0.00258 ,   0.032200001 ,   0.615000005 }   ,
            //                                     {   4   ,   0.00799 ,   0.086000005 ,   0.454000003 }   ,
            //                                     {   5   ,   0.00464 ,   0.054       ,   0.210999996 }   ,
            //                                     {   6   ,   0.00901 ,   0.098600002 ,   0.522999992 }   ,
            //                                     {   7   ,   0.00172 ,   0.02        ,   0.108000002 }   ,
            //                                     {   8   ,   0.00269 ,   0.0302      ,   0.189999998 }   ,
            //                                     {   9   ,   0.00138 ,   0.015999995 ,   0.319000001 }   ,
            //                                     {   10  ,   0.00175 ,   0.020200001 ,   0.404000015 }   ,
            //                                     {   11  ,   0       ,   0           ,   0           }   ,
            //                                     {   12  ,   0       ,   0           ,   0           }   ,
            //                                     {   13  ,   0       ,   0           ,   0           }   ,
            //                                     {   14  ,   0       ,   0           ,   0           }   ,
            //                                     {   15  ,   0       ,   0           ,   0           }   ,
            //                                     {   16  ,   0       ,   0           ,   0           }   ,
            //                                     {   17  ,   0       ,   0           ,   0           }   ,
            //                                     {   18  ,   0       ,   0           ,   0           }   ,
            //                                     {   19  ,   0       ,   0           ,   0           }   ,
            //                                     {   20  ,   0       ,   0           ,   0           }   ,
            //                                     {   21  ,   0       ,   0           ,   0           }   ,
            //                                     {   22  ,   0       ,   0           ,   0           }   ,
            //                                     {   23  ,   0       ,   0           ,   0           }   ,
            //                                     {   24  ,   0       ,   0           ,   0           }   };

            //m_busNum = m_busOriginalLibrary.Count();
            //m_lineNum = m_lineLibrary.Count();

            //Console.WriteLine("Please choose starting bus: ");
            //string starting_bus = Console.ReadLine();
            //Console.WriteLine("Please choose starting line: ");
            //string starting_line = Console.ReadLine();
            //string starting_bus_original = "81";
            //string starting_line_original = "10";
            #endregion

            int starting_bus_original_int  = 0;
            int starting_line_original_int = 0;

            m_busOriginalLibrary          = new List <int>();
            m_busNameOriginalLibrary      = new List <string>();
            m_busCalibrateOriginalLibrary = new List <int>();
            m_lineLibrary = new List <int>();
            m_lineSetCalibrateOriginal = new List <int>();
            m_lineBusInfoOriginal      = new List <int[]>();
            m_lineParameters           = new List <double[]>();

            // Configuration Data Acquisition
            StudyCase CurrentCase = StudyCase.DeserializeFromXml(FilePath);

            m_lineNum = 0;
            foreach (Branch CurrentLine in CurrentCase.Branches)
            {
                m_lineNum += 1;
                m_lineLibrary.Add(CurrentLine.LineNumber);
                if (CurrentLine.HighVoltageLineFlag == true)
                {
                    m_lineSetCalibrateOriginal.Add(CurrentLine.LineNumber);
                }
                if (CurrentLine.ReferenceFlag == true)
                {
                    starting_line_original_int = CurrentLine.LineNumber;
                }

                int[] TempLineBusInfo = new int[3] {
                    CurrentLine.LineNumber, CurrentLine.FromBusNumber, CurrentLine.ToBusNumber
                };
                m_lineBusInfoOriginal.Add(TempLineBusInfo);

                double[] TempLineParameters = new double[4] {
                    CurrentLine.LineNumber, CurrentLine.Resistance, CurrentLine.Reactance, CurrentLine.Susceptance
                };
                m_lineParameters.Add(TempLineParameters);
            }

            m_busNum          = 0;
            m_busCalibrateNum = 0;
            foreach (Bus CurrentBus in CurrentCase.Buses)
            {
                m_busNum += 1;
                m_busOriginalLibrary.Add(CurrentBus.BusNumber);
                m_busNameOriginalLibrary.Add(CurrentBus.BusName);
                if (CurrentBus.ReferenceFlag == true)
                {
                    starting_bus_original_int = CurrentBus.BusNumber;
                }

                if (CurrentBus.BusName != "AuxiliaryBus")
                {
                    m_busCalibrateNum += 1;
                    m_busCalibrateOriginalLibrary.Add(CurrentBus.BusNumber);
                }
            }

            m_baseKV  = CurrentCase.BaseKV;
            m_baseMVA = CurrentCase.BaseMVA;


            // Data Processing
            m_lineSetCalibrate = m_lineSetCalibrateOriginal;

            m_busLibrary = new int[m_busNum];
            for (int idx1 = 0; idx1 < m_busNum; idx1++)
            {
                m_busLibrary[idx1] = idx1 + 1;
            }

            m_busCalibrateLibrary = new int[m_busCalibrateNum];
            for (int idx8 = 0; idx8 < m_busCalibrateNum; idx8++)
            {
                for (int idx9 = 0; idx9 < m_busNum; idx9++)
                {
                    if (m_busCalibrateOriginalLibrary[idx8] == m_busOriginalLibrary[idx9])
                    {
                        m_busCalibrateLibrary[idx8] = m_busLibrary[idx9];
                        break;
                    }
                }
            }

            m_lineBusInfo = new int[m_lineNum, 3];
            for (int idx2 = 0; idx2 < m_lineNum; idx2++)
            {
                int TempFromBusNumber = m_lineBusInfoOriginal[idx2][1];
                int TempToBusNumber   = m_lineBusInfoOriginal[idx2][2];

                int TempFromBusIndex = -1;
                int TempToBusIndex   = -1;

                for (int idx3 = 0; idx3 < m_busNum; idx3++)
                {
                    if (m_busOriginalLibrary[idx3] == TempFromBusNumber)
                    {
                        TempFromBusIndex = idx3 + 1;
                    }
                    if (m_busOriginalLibrary[idx3] == TempToBusNumber)
                    {
                        TempToBusIndex = idx3 + 1;
                    }
                }

                m_lineBusInfo[idx2, 0] = idx2 + 1; // m_lineBusInfoOriginal[idx2, 0];
                m_lineBusInfo[idx2, 1] = TempFromBusIndex;
                m_lineBusInfo[idx2, 2] = TempToBusIndex;

                m_lineParameters[idx2][0] = idx2 + 1; // m_lineParameters [Original line number, R, X, y] -> [Line number, R, X, y]
            }

            m_zyDictionary = new Dictionary <string, double>();
            Zy_to_dictionary();

            for (int idx6 = 0; idx6 < m_lineSetCalibrateOriginal.Count(); idx6++)
            {
                int TempLineNumber = m_lineSetCalibrateOriginal[idx6];
                for (int idx7 = 0; idx7 < m_lineNum; idx7++)
                {
                    if (m_lineBusInfoOriginal[idx7][0] == TempLineNumber)
                    {
                        m_lineSetCalibrate[idx6] = idx7 + 1;
                        break;
                    }
                }
            }

            m_connectivityMatrix = new int[m_busCalibrateNum, m_busCalibrateNum];
            m_componentsNum      = 0;
            m_components         = new int[25, m_lineSetCalibrate.Count() + 2, 3];



            // project the opriginal bus number and line number to the indices
            string starting_bus  = null;
            string starting_line = null;
            for (int idx4 = 0; idx4 < m_busNum; idx4++)
            {
                if (m_busOriginalLibrary[idx4] == starting_bus_original_int)
                {
                    m_refBusNumber = m_busLibrary[idx4];
                    starting_bus   = m_busLibrary[idx4].ToString();
                    break;
                }
            }
            for (int idx5 = 0; idx5 < m_lineNum; idx5++)
            {
                if (m_lineBusInfoOriginal[idx5][0] == starting_line_original_int)
                {
                    m_refLineNumber = m_lineBusInfo[idx5, 0];
                    starting_line   = m_lineBusInfo[idx5, 0].ToString();
                    break;
                }
            }

            ConnectivityAnalysis(starting_bus, starting_line);

            // Insert double lines
            for (int idx10 = 0; idx10 < m_lineNum; idx10++)
            {
                if ((CurrentCase.Branches[idx10].LineID == 2) || (CurrentCase.Branches[idx10].LineID == 3))
                {
                    InsertLineToComponent(LineBusInfo[idx10, 0], LineBusInfo[idx10, 1], LineBusInfo[idx10, 2]);
                }
            }
        }