/*从 数据库 获取 SSS相关系数矩阵*/ ///已验证正确性 private bool initSSSCorr(DB db, XML xml, out double[,] Corr) { bool result = true; Corr = new double[168, 168]; int s1, s2; double corr; string sqlInitializeSSS; xml.getSqlCommand(xmlNodeSSSCorr, out sqlInitializeSSS); #region 从数据库中读出SSS相关系数矩阵的值,并填充Corr矩阵 SqlDataReader reader; reader = db.selectR(sqlInitializeSSS); while (reader.Read()) { s1 = reader.GetInt16(0); s2 = reader.GetInt16(1); corr = reader.GetDouble(2); if (s1 <= 167 && s2 <= 167 && s1 >= 0 && s2 >= 0) { if (s1 != s2) { Corr[s1, s2] = corr; Corr[s2, s1] = corr; } else Corr[s1, s1] = corr; } else { result = false; break; } } reader.Close(); #endregion return result; }
/*从 数据库 获取 当前小区 邻区信息*/ private void initializeAdjectSector(DB db, XML xml) { string sqlInitFirstAdjection;//一阶邻区 xml.getSqlCommand(xmlNodeFirstAdjectedSectors, out sqlInitFirstAdjection); //string sqlInitSecondAdjection;//二阶邻区 //xml.getSqlCommand(xmlNodeSecondAdjectedSectors, out sqlInitSecondAdjection); SqlDataReader reader1, reader2; string temSql1, temSql2; for(int i=0; i < sectorList.Count(); i++) { #region 读取当前小区的一阶邻区 temSql1 = sqlInitFirstAdjection.Replace("@sectorId", sectorList[i].sectorID); reader1 = db.selectR(temSql1); while (reader1.Read()) { FirAdjSector FirAdjSector = new FirAdjSector(reader1.GetString(0), isInSectorList(reader1.GetString(0)), 1); if (FirAdjSector.FirAdjIndex != -1) { //FirAdjSector.overlap = OverlapMatrix[i, FirAdjSector.FirAdjIndex];//注释!150305 FirAdjSector.distance = CJWDHelper.GetDistance2(sectorList[i].Longitude, sectorList[i].Latitude, sectorList[FirAdjSector.FirAdjIndex].Longitude, sectorList[FirAdjSector.FirAdjIndex].Latitude); sectorList[i].faList.Add(FirAdjSector); sectorList[i].faIndexList.Add(FirAdjSector.FirAdjIndex); } } reader1.Close(); #endregion #region ;对s的一阶邻区按照对打度大小进行排序 //sectorList[i].faList.Sort(SortRewrite.CompareOverlap);//目标:降序排序! #endregion #region ;对s的一阶邻区按照下标大小进行排序(需调整的小区基因位在前) sectorList[i].faList.Sort(SortRewrite.CompareFAIndex); #endregion #region 读取当前小区的二阶邻区 //temSql2 = sqlInitSecondAdjection.Replace("@sectorId", sectorList[i].sectorID); //reader2 = db.selectR(temSql2); //while (reader2.Read()) //{ // SecAdjSector SecAdjSector = new SecAdjSector(reader2.GetString(0), isInSectorList(reader2.GetString(0))); // //SecAdjCell sector = new SecAdjCell(reader2.GetString(0), isInCellList(reader2.GetString(0)), reader2.GetDouble(1)); // if (SecAdjSector.SecAdjIndex != -1) // { // sectorList[i].saList.Add(SecAdjSector); // sectorList[i].saIndexList.Add(SecAdjSector.SecAdjIndex); // } //} //reader2.Close(); #endregion } }
/*从 数据库 获取 当前小区 对打小区信息;并 构造 对打度矩阵*/ private void initializeOverlapInfo(DB db, XML xml) { string sqlInitOverlapInfo; string temSql; xml.getSqlCommand(xmlNodeDuiDaSectors, out sqlInitOverlapInfo); if (sectorList.Count() == 0) return; else OverlapMatrix = new double[sectorList.Count(), sectorList.Count()]; SqlDataReader reader; //foreach (Sector s in sectorList) for (int i = 0; i < sectorList.Count(); i++) { temSql = sqlInitOverlapInfo.Replace("@sectorId", sectorList[i].sectorID); reader = db.selectR(temSql); while (reader.Read()) { OverlapSector OverlapSector = new OverlapSector(reader.GetString(0), isInSectorList(reader.GetString(0)), reader.GetDouble(1)); if (OverlapSector.OverlapIndex != -1) { OverlapMatrix[i, OverlapSector.OverlapIndex] = OverlapSector.overlaping; } //s.overlapList.Add(sector); } reader.Close();//如果没有这句话,会出现“已有打开的与此 Command 相关联的 DataReader,必须首先将它关闭” } }
/*从 数据库 获取 小区基础信息, 并创建 小区对象数组*/ private void initializeSectorInfo(DB db, XML xml) { List<Sector> tempSec = new List<Sector>(); string sqlInitSectorInfo; xml.getSqlCommand(xmlNodeSectorInfo, out sqlInitSectorInfo); //sqlInitSectorInfo = "select distinct SECTOR_ID,ENODEBID,PHYCELLID,LONGITUDE,LATITUDE,STYLE,EARFCN,SECTOR_NAME from tbCell where LONGITUDE!=0 and LATITUDE!=0 and sector_name is not null"; SqlDataReader reader; reader = db.selectR(sqlInitSectorInfo); while (reader.Read()) { if (reader.GetDouble(3) - 0 < 1e-7 || reader.GetDouble(4) - 0 < 1e-7 || reader.GetString(5).Length == 0) continue; Sector cell = new Sector(reader.GetString(0), reader.GetInt32(1), reader.GetInt32(2), (double)reader.GetDouble(3), (double)reader.GetDouble(4), reader.GetString(5)); cell.FCN = reader.GetInt32(6); cell.sectorNAME = reader.GetString(7); //if (cell.sectorType == "室外") cell.sectorType = "OUTDOOR"; //else if (cell.sectorType == "室内") cell.sectorType = "INDOOR"; //else cell.sectorType = "SPECIAL"; //if (cell.sectorType == "宏站") cell.sectorType = "OUTDOOR"; //else if (cell.sectorType == "室分") cell.sectorType = "INDOOR"; //else cell.sectorType = "SPECIAL"; //tempSec.Add(cell); sectorList.Add(cell); } reader.Close(); //string sqlInitKdist; //xml.getSqlCommand(xmlNodeKdistInfo, out sqlInitKdist); //string temSql; //for (int i = 0; i < tempSec.Count; i++) //{ // temSql = sqlInitKdist.Replace("@sectorId", tempSec[i].sectorID); // //temSql = sqlInitKdist.Replace("@sectorId", sectorList[i].sectorID); // reader = db.selectR(temSql); // while (reader.Read()) // tempSec[i].kDist = reader.GetDouble(0); // //sectorList[i].kDist = reader.GetDouble(0); // reader.Close(); //} ////按照地理关系划分象限 //KdistSectorset(tempSec, out sectorList); }
/*从 数据库 获取 当前小区 3层之内 的 对打小区信息*/ private void initializeLyaer_OverlaySector(DB db, XML xml) { string sqlInitLyDuidaInfo; string temSql; xml.getSqlCommand(xmlNodeLayerSectors, out sqlInitLyDuidaInfo); SqlDataReader reader; foreach (Sector s in sectorList) { temSql = sqlInitLyDuidaInfo.Replace("@sectorId", s.sectorID); reader = db.selectR(temSql); while (reader.Read()) { NearSector sector = new NearSector(reader.GetString(0), isInSectorList(reader.GetString(0)), reader.GetInt32(1)); if (sector.NearIndex != -1) s.ly_over_List.Add(sector); } reader.Close(); } }
/*从 数据库 获取 优化目标集 周边小区信息*/ private void initializeOthersSectorInfo(DB db, XML xml) { //保证同频 int beOptimizedNum = sectorList.Count; string sqlInitOthers1, sqlInitOthers2, sqlInitMerge, sqlInitYiceng, sqlInitCoStation; xml.getSqlCommand(xmlNodeOtherSectors_1, out sqlInitOthers1); xml.getSqlCommand(xmlNodeOtherSectors_2, out sqlInitOthers2); xml.getSqlCommand(xmlNodeMergeSectors, out sqlInitMerge); xml.getSqlCommand(xmlNodeOtherSectors_3, out sqlInitYiceng); //xml.getSqlCommand(xmlNodeAddCostation, out sqlInitCoStation); SqlDataReader reader1, reader2, reader3, reader4, reader5; //string tempSql; //for (int i = 0; i < beOptimizedNum; i++) //{ // tempSql = sqlInitCoStation.Replace("@enodebid", sectorList[i].eNodeBID.ToString()); // reader5 = db.selectR(tempSql); // while (reader5.Read()) // { // Sector cell = new Sector(reader5.GetString(0), reader5.GetInt32(1), reader5.GetInt32(2), (double)reader5.GetDouble(3), (double)reader5.GetDouble(4), reader5.GetString(5)); // cell.FCN = reader5.GetInt32(6); // cell.sectorNAME = reader5.GetString(7); // if (cell.sectorType == "室外") cell.sectorType = "OUTDOOR"; // else if (cell.sectorType == "室内") cell.sectorType = "INDOOR"; // else cell.sectorType = "SPECIAL"; // if (isInSectorList(cell.sectorID) == -1) // sectorList.Add(cell); // } // reader5.Close(); //} reader1 = db.selectR(sqlInitOthers1); while (reader1.Read()) { Sector cell = new Sector(reader1.GetString(0), reader1.GetInt32(1), reader1.GetInt32(2), (double)reader1.GetDouble(3), (double)reader1.GetDouble(4), reader1.GetString(5)); cell.FCN = reader1.GetInt32(6); cell.sectorNAME = reader1.GetString(7); if (cell.sectorType == "室外") cell.sectorType = "OUTDOOR"; else if (cell.sectorType == "室内") cell.sectorType = "INDOOR"; else cell.sectorType = "SPECIAL"; if (isInSectorList(cell.sectorID) == -1 && cell.FCN == sectorList[0].FCN) sectorList.Add(cell); } reader1.Close(); reader2 = db.selectR(sqlInitOthers2); while (reader2.Read()) { Sector cell = new Sector(reader2.GetString(0), reader2.GetInt32(1), reader2.GetInt32(2), (double)reader2.GetDouble(3), (double)reader2.GetDouble(4), reader2.GetString(5)); cell.FCN = reader2.GetInt32(6); cell.sectorNAME = reader2.GetString(7); if (cell.sectorType == "室外") cell.sectorType = "OUTDOOR"; else if (cell.sectorType == "室内") cell.sectorType = "INDOOR"; else cell.sectorType = "SPECIAL"; if (isInSectorList(cell.sectorID) == -1 && cell.FCN == sectorList[0].FCN) sectorList.Add(cell); } reader2.Close(); reader3 = db.selectR(sqlInitMerge); while (reader3.Read()) { Sector cell = new Sector(reader3.GetString(0), reader3.GetInt32(1), reader3.GetInt32(2), (double)reader3.GetDouble(3), (double)reader3.GetDouble(4), reader3.GetString(5)); cell.FCN = reader3.GetInt32(6); cell.sectorNAME = reader3.GetString(7); if (cell.sectorType == "室外") cell.sectorType = "OUTDOOR"; else if (cell.sectorType == "室内") cell.sectorType = "INDOOR"; else cell.sectorType = "SPECIAL"; if (isInSectorList(cell.sectorID) == -1 && cell.FCN == sectorList[0].FCN) sectorList.Add(cell); } reader3.Close(); reader4 = db.selectR(sqlInitYiceng); while (reader4.Read()) { Sector cell = new Sector(reader4.GetString(0), reader4.GetInt32(1), reader4.GetInt32(2), (double)reader4.GetDouble(3), (double)reader4.GetDouble(4), reader4.GetString(5)); cell.FCN = reader4.GetInt32(6); cell.sectorNAME = reader4.GetString(7); if (cell.sectorType == "室外") cell.sectorType = "OUTDOOR"; else if (cell.sectorType == "室内") cell.sectorType = "INDOOR"; else cell.sectorType = "SPECIAL"; if (isInSectorList(cell.sectorID) == -1) sectorList.Add(cell); } reader4.Close(); //for (int i = 0; i < beOptimizedNum; i++) //{ // #region ;周边一阶邻区 // tempSql1 = sqlInitOthers1.Replace("@sectorId", sectorList[i].sectorID); // reader1 = db.selectR(tempSql1); // while (reader1.Read()) // { // if (reader1.GetDouble(3) - 0 < 1e-7 || reader1.GetDouble(4) - 0 < 1e-7 || reader1.GetString(5).Length == 0) // continue; // Sector cell = new Sector(reader1.GetString(0), reader1.GetInt32(1), reader1.GetInt32(2), reader1.GetDouble(3), reader1.GetDouble(4), reader1.GetString(5)); // cell.FCN = reader1.GetInt32(6); // if (isInSectorList(cell.sectorID) == -1 && cell.FCN == sectorList[0].FCN) // sectorList.Add(cell); // } // reader1.Close(); // #endregion // #region ;周边二阶邻区 // tempSql2 = sqlInitOthers2.Replace("@sectorId", sectorList[i].sectorID); // reader2 = db.selectR(tempSql2); // while (reader2.Read()) // { // if (reader2.GetDouble(3) - 0 < 1e-7 || reader2.GetDouble(4) - 0 < 1e-7 || reader2.GetString(5).Length == 0) // continue; // Sector cell = new Sector(reader2.GetString(0), reader2.GetInt32(1), reader2.GetInt32(2), reader2.GetDouble(3), reader2.GetDouble(4), reader2.GetString(5)); // cell.FCN = reader2.GetInt32(6); // if (isInSectorList(cell.sectorID) == -1) // sectorList.Add(cell); // } // reader2.Close(); // #endregion // #region ;Merge小区 // tempSql3 = sqlInitMerge.Replace("@sectorId", sectorList[i].sectorID); // reader3 = db.selectR(tempSql3); // while (reader3.Read()) // { // Sector cell = new Sector(reader3.GetString(0), reader3.GetInt32(1), reader3.GetInt32(2), reader3.GetDouble(3), reader3.GetDouble(4), reader3.GetString(5)); // cell.FCN = reader3.GetInt32(6); // if (isInSectorList(cell.sectorID) == -1 && cell.FCN == sectorList[0].FCN) // sectorList.Add(cell); // } // reader3.Close(); // #endregion //} }
/*从 SectorList中 获取每个小区的 Kdist值*/ private void initializeKDist(DB db, XML xml) { string sqlInitKdist; xml.getSqlCommand(xmlNodeKdistInfo, out sqlInitKdist); SqlDataReader reader; string temSql; //reader = db.selectR(sqlInitKdist); for (int i = 0; i < sectorList.Count; i++) { temSql = sqlInitKdist.Replace("@sectorId", sectorList[i].sectorID); reader = db.selectR(temSql); while (reader.Read()) sectorList[i].kDist = reader.GetDouble(0); reader.Close(); } #region ;计算Kdist //double Radius = 5;//单位km //int k = 3; //for (int i = 0; i < sectorList.Count; i++) // sectorList[i].kDist = getKdist(sectorList[i].Longitude, sectorList[i].Latitude, Radius, k, sectorList, sectorList[i].FCN); //string currentDirectory = System.Environment.CurrentDirectory; //Excel.Application excelApp = new Excel.Application(); //if (sectorList.Count > 0) //{ // Excel.Worksheet Xsheet; // excelApp.Visible = true; // excelApp.Workbooks.Add(""); // Xsheet = (Excel.Worksheet)excelApp.Worksheets.get_Item(1); // Xsheet.Activate(); // Xsheet.Cells[1, 1] = "SECTOR_ID"; // Xsheet.Cells[1, 2] = "SECTOR_NAME"; // Xsheet.Cells[1, 3] = "K_DIST"; // for (int i = 0; i < sectorList.Count; i++) // { // Xsheet.Cells[i + 2, 1] = sectorList[i].sectorID; // Xsheet.Cells[i + 2, 2] = sectorList[i].sectorNAME; // Xsheet.Cells[i + 2, 3] = sectorList[i].kDist; // } // excelApp.ActiveWorkbook.SaveAs(currentDirectory + "/" + "KDIST_GQ0624.xlsx"); // excelApp.Workbooks.Close(); // excelApp.Visible = false; // excelApp.Quit(); //} #endregion }
/*从 数据库 获取 当前小区 干扰小区信息;并 构造 干扰矩阵*/ private void initializeInterfInfo(DB db, XML xml) { string sqlInitInterfInfo; xml.getSqlCommand(xmlNodeInterfInfo, out sqlInitInterfInfo); if (sectorList.Count() == 0) return; else InterfMatrix = new double[sectorList.Count(), sectorList.Count()]; SqlDataReader reader; string tempSql; //获取第i个小区的干扰信息 for (int i = 0; i < sectorList.Count();i++ ) { tempSql = sqlInitInterfInfo.Replace("@sectorId", sectorList[i].sectorID); reader = db.selectR(tempSql); while (reader.Read()) { InterfSector InterfSector = new InterfSector(reader.GetString(0), isInSectorList(reader.GetString(0)), reader.GetDouble(1)); if (InterfSector.InterfIndex != -1) { //第i个小区的进向以及第InterfSector.InterfIndex个小区的出向 if (!sectorList[i].CoIn.Contains(InterfSector.InterfIndex)) sectorList[i].CoIn.Add(InterfSector.InterfIndex); if (!sectorList[InterfSector.InterfIndex].CoOut.Contains(i)) sectorList[InterfSector.InterfIndex].CoOut.Add(i); //记录干扰值 InterfMatrix[i, InterfSector.InterfIndex] = InterfSector.interf; } } reader.Close(); } }
/*从 数据库 读取 每个小区 的 第一层地理邻区*/ private void initializeFirNearSector(DB db, XML xml) { string sqlInitFirstNear; string tempSql; xml.getSqlCommand(xmlNodeFirstNearSectors, out sqlInitFirstNear); SqlDataReader reader; for (int i = 0; i < sectorList.Count; i++) { tempSql = sqlInitFirstNear.Replace("@sectorId", sectorList[i].sectorID); reader = db.selectR(tempSql); while (reader.Read()) { NearSector sector = new NearSector(reader.GetString(0), isInSectorList(reader.GetString(0)), 1); if (sector.NearIndex != -1) { sectorList[i].fnList.Add(sector); sectorList[i].fnIndexList.Add(sector.NearIndex); //if (!sectorList[i].faIndexList.Contains(sector.NearIndex)) //{//不是一阶邻区则添加到一阶邻区里 // sectorList[i].faIndexList.Add(sector.NearIndex); // double d = CJWDHelper.GetDistance2(sectorList[i].Longitude, sectorList[i].Latitude, sectorList[sector.NearIndex].Longitude, sectorList[sector.NearIndex].Latitude); // sectorList[i].faList.Add(new FirAdjSector(sector.NearSectorID, sector.NearIndex, d)); // sectorList[i].fnNotfaIndexList.Add(sector.NearIndex);//记录非一阶邻区的一层邻区 //} } } reader.Close(); } }
/*从 数据库 获取 每个小区的 同频一阶邻区平均距离*/ private void initializeAvgDist(DB db, XML xml) { string sqlInitAvgd; xml.getSqlCommand(xmlNodeAverageDistance, out sqlInitAvgd); SqlDataReader reader; string tempSql; for (int i = 0; i < sectorList.Count; i++) { tempSql = sqlInitAvgd.Replace("@sectorId", sectorList[i].sectorID); reader = db.selectR(tempSql); while (reader.Read()) sectorList[i].avgDist = reader.GetDouble(0); reader.Close(); #region ;计算AVGDistance //double sumD = 0; //int count = 0; //for (int j = 0; j < sectorList[i].faList.Count; j++) //{ // int ind = sectorList[i].faList[j].FirAdjIndex; // if (sectorList[i].FCN == sectorList[ind].FCN) // { // double d = CJWDHelper.GetDistance2(sectorList[i].Longitude, sectorList[i].Latitude, sectorList[ind].Longitude, sectorList[ind].Latitude); // sumD += d; // count++; // } //} ////sumD /= 1000; //if (count == 0) // sectorList[i].avgDist = 0; //else // sectorList[i].avgDist = sumD / count; #endregion } #region 存储 //if (sectorList.Count > 0) //{ // Excel.Worksheet Xsheet; // Excel.Application excelApp = new Excel.Application(); // excelApp.Visible = true; // excelApp.Workbooks.Add(""); // Xsheet = (Excel.Worksheet)excelApp.Worksheets.get_Item(1); // Xsheet.Activate(); // string currentDirectory = System.Environment.CurrentDirectory; // Xsheet.Cells[1, 1] = "SECTOR_ID"; // Xsheet.Cells[1, 2] = "SECTOR_NAME"; // Xsheet.Cells[1, 3] = "averageDist"; // for (int i = 0; i < sectorList.Count; i++) // { // Xsheet.Cells[i + 2, 1] = sectorList[i].sectorID; // Xsheet.Cells[i + 2, 2] = sectorList[i].sectorNAME; // Xsheet.Cells[i + 2, 3] = sectorList[i].avgDist; // } // excelApp.ActiveWorkbook.SaveAs(currentDirectory + "/" + sectorList.Count + " Ad_GQ0624.xlsx"); // excelApp.Workbooks.Close(); // excelApp.Visible = false; // excelApp.Quit(); //} #endregion }
//初始化小区各种信息,填充各种列表 public bool initialize(DB db, XML xml) { bool result = true; int index = 0; string sqlInitSectorInfo; //读取37900小区信息 xml.getSqlCommand(xmlNode37900, out sqlInitSectorInfo); SqlDataReader reader; reader = db.selectR(sqlInitSectorInfo); while (reader.Read()) { if (reader.GetDouble(1) - 0 < 1e-7 || reader.GetDouble(2) - 0 < 1e-7 || reader.GetString(3).Length == 0) continue; Sector cell = new Sector(reader.GetString(0), index, reader.GetDouble(1), reader.GetDouble(2), reader.GetString(3),reader.GetInt32(4)); sectorList.Add(cell); index++; } reader.Close(); //读取38098小区信息 xml.getSqlCommand(xmlNode38098, out sqlInitSectorInfo); reader = db.selectR(sqlInitSectorInfo); while (reader.Read()) { if (reader.GetDouble(1) - 0 < 1e-7 || reader.GetDouble(2) - 0 < 1e-7 || reader.GetString(3).Length == 0) continue; Sector cell = new Sector(reader.GetString(0), index, reader.GetDouble(1), reader.GetDouble(2), reader.GetString(3), reader.GetInt32(4)); sectorList.Add(cell); index++; } reader.Close(); //读取C2I数据,构造C2I干扰矩阵 string sqlInitInterfInfo; xml.getSqlCommand(xmlNodeC2Iinfo, out sqlInitInterfInfo); if (sectorList.Count == 0) { Console.WriteLine("小区集合为空!"); return false; } else InterfMatrix = new double[sectorList.Count, sectorList.Count]; string tempSql; //获取第i个小区的干扰信息 for (int i = 0; i < sectorList.Count; i++) { tempSql = sqlInitInterfInfo.Replace("@sectorId", sectorList[i].sectorID); reader = db.selectR(tempSql); while (reader.Read()) { InterfSector InterfSector = new InterfSector(reader.GetString(0), isInSectorList(reader.GetString(0)), reader.GetDouble(1)); if (InterfSector.InterfIndex != -1) { InterfMatrix[i, InterfSector.InterfIndex] = InterfSector.interf; } } reader.Close(); } return result; }