/*石倩楠2014/12 重写 初始化函数*/ public bool initialize(DB db, XML xml) { System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch(); bool result = true; time.Start(); /*一下各个函数调用顺序不可调换*/ //初始化小区基本信息 initializeSectorInfo(db, xml);//按照地理划分象限 initializeAdjectSector(db, xml); //initializeFirNearSector(db, xml); calculateAverageDistance(db, xml); calculatKthDiatance(db, xml); return true; //endSectorIndex = sectorList.Count - 1; //initializeOthersSectorInfo(db, xml);//添加一阶二阶一层干扰共站邻区 //if (endSectorIndex < 10) //{ // for (int i = 0; i < endSectorIndex + 1; i++) // { // for (int j = endSectorIndex + 1; j < sectorList.Count; j++) // { // if (sectorList[i].eNodeBID == sectorList[j].eNodeBID) // { // Sector temp = sectorList[j]; // sectorList[j] = sectorList[endSectorIndex + 1]; // sectorList[endSectorIndex + 1] = temp; // endSectorIndex++; // } // } // } // //todo:关联出新增的共站小区的一阶二阶一层干扰??? //} //time.Stop(); //Console.WriteLine("SectorInfo Cost {0}",time.Elapsed.TotalSeconds); //time.Reset(); //time.Start(); ////初始化邻区数组 //time.Start(); //initializeAdjectSector(db, xml);//验证 //time.Stop(); //Console.WriteLine("AdjectSectorInfo Cost {0}", time.Elapsed.TotalSeconds); //time.Reset(); ////初始化维诺图第一层小区数组 //time.Start(); //initializeFirNearSector(db, xml); //time.Stop(); //Console.WriteLine("FNSectorInfo Cost {0}", time.Elapsed.TotalSeconds); //time.Reset(); ////todo:对一阶邻区的排序 //sortFirAdjSector(); ////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[0].sectorNAME + " 关联结果.xlsx"); //// excelApp.Workbooks.Close(); //// excelApp.Visible = false; //// excelApp.Quit(); ////初始化各个距离属性 //time.Start(); ////initializeKDist(db, xml); //initializeAvgDist(db, xml); //initializeIn3KM(); //time.Stop(); //Console.WriteLine("DistanceInfo Cost {0}", time.Elapsed.TotalSeconds); //time.Reset(); //time.Start(); ////初始化干扰矩阵以及对打度矩阵 //initializeInterfInfo(db, xml); //time.Stop(); //Console.WriteLine("InterfMatixInfo Cost {0}", time.Elapsed.TotalSeconds); //time.Reset(); //#region !对打度矩阵注释! ////time.Start(); ////initializeOverlapInfo(db, xml); ////time.Stop(); ////Console.WriteLine("OverlapMatrixInfo Cost {0}", time.Elapsed); ////time.Reset(); //#endregion ////初始化共站小区数组 //time.Start(); //initializeCoStationSector();//验证 //time.Stop(); //Console.WriteLine("CoStationSectorInfo Cost {0}", time.Elapsed.TotalSeconds); //time.Reset(); //#region ;存入excel ////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] = "AD"; //// for (int i = 0; i < sectorList.Count; i++) //// { //// Xsheet.Cells[i + 2, 1] = sectorList[i].sectorID; //// Xsheet.Cells[i + 2, 2] = sectorList[i].avgDist; //// } //// excelApp.ActiveWorkbook.SaveAs(currentDirectory + "/" + sectorList.Count + " Ad.xlsx"); //// excelApp.Workbooks.Close(); //// excelApp.Quit(); ////} //#endregion //#region !层次对打关系注释! ////time.Start(); ////initializeLyaer_OverlaySector(db, xml);//验证 ////time.Stop(); ////Console.WriteLine("Lyaer_OverlaySectorInfo Cost {0}", time.Elapsed); ////time.Reset(); //#endregion //result = selfCheck(); //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 } }
//计算一阶邻区平均距离以及kdist public void calculateAverageDistance(DB db, XML xml) { for (int i = 0; i < sectorList.Count; i++) { int p; if(sectorList[i].sectorID=="2392322") p =0; 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);//单位是米 if ((sectorList[i].Longitude - sectorList[ind].Longitude < 0.00001) && (sectorList[i].Latitude - sectorList[ind].Latitude < 0.00001)) d = 0; else 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; } 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 + " averageDistance.xlsx"); excelApp.Workbooks.Close(); excelApp.Visible = false; excelApp.Quit(); } }
public void calculatKthDiatance(DB db, XML xml) { 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 + "/" + "KthDiatance.xlsx"); excelApp.Workbooks.Close(); excelApp.Visible = false; excelApp.Quit(); } }
/*初始化 SSS相关系数信息*/ public bool initSSSInfo(DB db, XML xml) { bool result = true; bool ret1 = initSSSThr(xml, out sssThr); bool ret2 = initSSSCorr(db, xml, out sssCorr); result = ret1 && ret2; return result; }
/*从 数据库 获取 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 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 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 }
/*从 数据库 获取 当前小区 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(); } }
/* 初始化 小区、PCI 基本信息*/ private void prepareData(string configFile, string SSSThrLevel) { XML xml = new XML(configFile); DB db = new DB("Configuration/Database"); try { #region ;从 配置文件 获取 数据库配置信息 ;并连接数据库 if (db.initialize(xml) == false) { Console.WriteLine("初始化配置文件错误!"); return; } if (db.GetConnection() == null) { Console.WriteLine("连接数据库错误!"); return; } #endregion pciInfo = new PCIinfo("Configuration/pciInfo", "Configuration/SqlInitSSSCorrelation", "Configuration/sssThrInfo", SSSThrLevel); #region ;从 配置文件 获取 SSS相关系数 信息; if (pciInfo.initSSSInfo(db, xml) == false) return; #endregion #region ;从 配置文件 获取 不同类型小区 候选PCI bool r1 = pciInfo.initPCIInfo(xml, "INDOOR", out indoor); bool r2 = pciInfo.initPCIInfo(xml, "OUTDOOR", out outdoor); bool r3 = pciInfo.initPCIInfo(xml, "SPECIAL", out special); #endregion /////37900 //sList = new SectorList("Configuration/SqlInitSectorInfoTest37900", "Configuration/SqlInitClusterInfo", "Configuration/SqlInitOtherSectors_1_37900", "Configuration/SqlInitOtherSectors_2_37900", // "Configuration/SqlInitOtherSectors_3", "Configuration/SqlInitMergeInfo_37900", "Configuration/SqlInitViroInfo", // "Configuration/SqlInitKdist", "Configuration/SqlInitAvgDist", "Configuration/SqlInitInterfInfo", // "Configuration/SqlInitFirstAdjection", "Configuration/SqlInitSecondAdjection", "Configuration/SqlInitFirstNearSector", // "Configuration/SqlInitOverlapInfo", "Configuration/SqlInitLayer_OverlapInfo"); /////38350 //sList = new SectorList("Configuration/SqlInitSectorInfoTest38350", "Configuration/SqlInitClusterInfo", "Configuration/SqlInitOtherSectors_1_38350", "Configuration/SqlInitOtherSectors_2_38350", // "Configuration/SqlInitOtherSectors_3", "Configuration/SqlInitMergeInfo_38350", "Configuration/SqlInitViroInfo", // "Configuration/SqlInitKdist", "Configuration/SqlInitAvgDist", "Configuration/SqlInitInterfInfo", // "Configuration/SqlInitFirstAdjection", "Configuration/SqlInitSecondAdjection", "Configuration/SqlInitFirstNearSector", // "Configuration/SqlInitOverlapInfo", "Configuration/SqlInitLayer_OverlapInfo"); //sList = new SectorList("Configuration/SqlInitSectorInfoTest", "Configuration/SqlInitClusterInfo", "Configuration/SqlInitOtherSectors_1", "Configuration/SqlInitOtherSectors_2", // "Configuration/SqlInitOtherSectors_3", "Configuration/SqlInitMergeInfo", "Configuration/SqlInitViroInfo", // "Configuration/SqlInitKdist", "Configuration/SqlInitAvgDist", "Configuration/SqlInitInterfInfo", // "Configuration/SqlInitFirstAdjection", "Configuration/SqlInitSecondAdjection", "Configuration/SqlInitFirstNearSector", // "Configuration/SqlInitOverlapInfo", "Configuration/SqlInitLayer_OverlapInfo"); sList = new SectorList("Configuration/SqlInitSectorInfo", "Configuration/SqlInitOtherSectors_1_GQ", "Configuration/SqlInitOtherSectors_2_GQ", "Configuration/SqlInitOtherSectors_3_GQ", "Configuration/SqlInitMergeInfo_GQ", "Configuration/SqlInitViroInfo", "Configuration/SqlInitKdist", "Configuration/SqlInitAvgDist", "Configuration/SqlInitInterfInfo", "Configuration/SqlInitFirstAdjection", "Configuration/SqlInitSecondAdjection", "Configuration/SqlInitFirstNearSector", "Configuration/SqlInitOverlapInfo", "Configuration/SqlInitLayer_OverlapInfo"); #region ;从 配置文件 获取 小区列表 各项信息; if (sList.initialize(db, xml) == false) return; #endregion #region ;统计一/二阶邻区数目 //string currentDirectory = System.Environment.CurrentDirectory; //Excel.Application excelApp = new Excel.Application(); //Excel.Worksheet Xsheet; //excelApp.Visible = true; //excelApp.Workbooks.Add(""); //Xsheet = (Excel.Worksheet)excelApp.Worksheets.get_Item(1); //Xsheet.Activate(); //Xsheet.Cells[1, 1] = "SectorID"; //Xsheet.Cells[1, 2] = "FirAdjNum"; //Xsheet.Cells[1, 3] = "SecAdjNum"; //for (int i = 0; i < sList.sectorList.Count; i++) //{ // Xsheet.Cells[i + 2, 1] = sList.sectorList[i].sectorID; // Xsheet.Cells[i + 2, 2] = sList.sectorList[i].faList.Count; // Xsheet.Cells[i + 2, 3] = sList.sectorList[i].saList.Count; //} //excelApp.ActiveWorkbook.SaveAs(currentDirectory + "/" + sList.sectorList.Count + " Adj Number.xlsx"); //excelApp.Workbooks.Close(); ////excelApp.Visible = false; //excelApp.Quit(); #endregion begSecIndex = sList.begSectorIndex; endSecIndex = sList.endSectorIndex; //对sector按照kdist的值进行排序 if (endSecIndex - begSecIndex + 1 == sList.sectorList.Count) { List<KdistSortHelper> sortKD = new List<KdistSortHelper>(); for (int i = 0; i < sList.sectorList.Count; i++) sortKD.Add(new KdistSortHelper(sList.sectorList[i], sList.sectorList[i].kDist)); sortKD.Sort(SortRewrite.CompareKdist); } } catch (Exception e) { Console.WriteLine("PREPARE ERR: {0}!", e.Message); } finally { db.close(); xml.Dispose(); } }
/*从 数据库 获取 小区基础信息, 并创建 小区对象数组*/ 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); }
//数据的预处理 private void prepareData(string configFile) { XML xml = new XML(configFile); DB db = new DB("Configuration/Database"); try { #region ;从 配置文件 获取 数据库配置信息 ;并连接数据库 if (db.initialize(xml) == false) { Console.WriteLine("初始化配置文件错误!"); return; } if (db.GetConnection() == null) { Console.WriteLine("连接数据库错误!"); return; } #endregion slist = new SectorList("Configuration/SqlInitSectorInfoof37900", "Configuration/SqlInitSectorInfoof38098", "Configuration/SqlInitInterfInfo"); #region ;从 配置文件 获取 小区列表 各项信息; if (slist.initialize(db, xml) == false) { Console.WriteLine("初始化数据错误!"); return; } ancestor = new Individual(slist.sectorList.Count); ancestorori = new Individual(slist.sectorList.Count); for (int i = 0; i < slist.sectorList.Count; i++) { ancestor.gene[i] = slist.sectorList[i].FCN; ancestorori.gene[i] = slist.sectorList[i].FCN; } #endregion } catch (Exception e) { Console.WriteLine("PREPARE ERR: {0}!", e.Message); } finally { db.close(); xml.Dispose(); } }
//初始化小区各种信息,填充各种列表 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; }