///// <summary> ///// 初始以Time、GPS等设计 ///// </summary> //public void InitDetect() //{ // if (files.Length <= 0) { throw new Exception("选择独立基线前,请配置好观测数据!"); } // DataOfAllSites = new Dictionary<string, SiteEpochSatData>(); // int m = 0; // foreach (var file in files) // { // Gnsser.Data.Rinex.FileStreamObsDataSource reader = new FileStreamObsDataSource(file, false); // SiteEpochSatData siteEpochSatData = new SiteEpochSatData(); // siteEpochSatData.SiteName = reader.SiteInfo.MarkerName.ToUpper(); // siteEpochSatData.SiteNumber = m; // m++; // foreach (var key in reader) // { // siteEpochSatData.Data.Add(key.Time, key.Prns); // string[] prns = new string[key.Prns.Count]; // int kk = 0; // foreach (var prn in key.Prns) // { // prns[kk] = prn.ToString(); // kk++; // } // siteEpochSatData.EpochSatData.Add(key.Time, prns); // } // DataOfAllSites.Add(reader.SiteInfo.MarkerName.ToUpper(), siteEpochSatData); // } //} /// <summary> /// 更改简洁版 /// </summary> public void Init() { if (files.Length <= 0) { throw new Exception("选择独立基线前,请配置好观测数据!"); } DataOfAllSites = new Dictionary <string, SiteEpochSatData>(); int m = 0; foreach (var file in files) { var reader = new RinexFileObsDataSource(file, false); SiteEpochSatData siteEpochSatData = new SiteEpochSatData(); siteEpochSatData.SiteName = reader.SiteInfo.SiteName.ToUpper(); siteEpochSatData.SiteNumber = m; m++; foreach (var item in reader) { double seconds = item.ReceiverTime.Hour * 60 * 60 + item.ReceiverTime.Minute * 60 + item.ReceiverTime.Seconds; double seconds1 = item.ReceiverTime.SecondsOfDay; if (seconds != seconds1) { throw new Exception("单基线选取中时间统计出错!"); } int[] prn = new int[item.EnabledPrns.Count]; for (int j = 0; j < item.EnabledPrns.Count; j++) { prn[j] = item.EnabledPrns[j].PRN; } siteEpochSatData.Data.Add(seconds, prn); //string[] prns = new string[key.Prns.Count]; //int kk = 0; //foreach (var prn in key.Prns) //{ // prns[kk] = prn.ToString(); // kk++; //} siteEpochSatData.EpochSatData.Add(seconds, prn); } DataOfAllSites.Add(reader.SiteInfo.SiteName.ToUpper(), siteEpochSatData); } }
/// <summary> /// 初始化,读取赋值 /// </summary> public void Init() { if (ObsFilesPaths.Length <= 0) { throw new Exception("选择独立基线前,请配置好观测数据!"); } //初始化 DataOfAllSites = new SiteEpochSatData[ObsFilesPaths.Length]; RinexFileObsDataSource RinexFileObsDataSource = new Data.Rinex.RinexFileObsDataSource(ObsFilesPaths[0], false); //加载读取全部文件 List <ISingleSiteObsStream> obsDataSources = RinexFileObsDataSource.LoadObsData(ObsFilesPaths); int siteNumberCount = 0; foreach (var obsData in obsDataSources) { SiteEpochSatData siteEpochSatData = new SiteEpochSatData(); siteEpochSatData.Path = obsData.Path; siteEpochSatData.SiteName = GnssBaseLineName.GetSiteName(obsData.Path);// obsData.SiteInfo.MarkerName.ToUpper(); siteEpochSatData.SiteNumber = siteNumberCount; siteEpochSatData.PrnInfo = new string[2880]; siteEpochSatData.TimeInfo = new double[2880]; int jj = 0; foreach (var item in obsData) { double seconds = item.ReceiverTime.Hour * 60 * 60 + item.ReceiverTime.Minute * 60 + item.ReceiverTime.Seconds; double seconds1 = item.ReceiverTime.SecondsOfDay; if (seconds != seconds1) { throw new Exception("单基线选取中时间统计出错!"); } string prnStr = null; foreach (var prn in item.TotalPrns) { prnStr += prn.ToString(); } if (prnStr != null) { siteEpochSatData.TimeInfo[jj] = seconds; siteEpochSatData.PrnInfo[jj] = prnStr; jj++; } } DataOfAllSites[siteNumberCount] = siteEpochSatData; siteNumberCount++; } }
// public Dictionary<string, SiteEpochSatData> DataOfAllSites = new Dictionary<string, SiteEpochSatData>(); #endregion public void IndepentBaselineProcess() { //存储基线 Dictionary <string, Edge> graphRound = new Dictionary <string, Edge>(); int n = DataOfAllSites.Length; mgraph = new MGraph(); mgraph.n = n; mgraph.e = n * (n - 1) / 2; mgraph.vex = new VertexType[n]; mgraph.edges = new int[n][]; road = new Road[n * (n - 1) / 2]; v = new int[n * (n - 1) / 2]; int ii = 0; for (int i = 0; i < n; i++) { // SiteEpochSatData dataA = DataOfAllSites.ElementAt(i).Value; SiteEpochSatData dataA = DataOfAllSites[i]; mgraph.vex[i] = new VertexType(); mgraph.vex[i].no = i; mgraph.vex[i].name = dataA.SiteName; v[i] = i; //顶点ver[i]初始时表示各在不同的连通分支v[i]中,父结点依次为v[i] for (int j = i + 1; j < n; j++) { mgraph.edges[i] = new int[n]; SiteEpochSatData dataB = DataOfAllSites[j]; //.ElementAt (j).Value; double toleranceSeccond = 3.5; //限差 单位:秒 int count = 0; //for (int k = 0, s = 0; k < dataA.TimeInfo.Length.Data.Count && s < dataB.Data.Count; k++, s++) for (int k = 0, s = 0; k < dataA.TimeInfo.Length && s < dataB.TimeInfo.Length; k++, s++) { //double diff = Math.Abs(dataA.Data.ElementAt(k).Key - dataB.Data.ElementAt(s).Key); double diff = Math.Abs(dataA.TimeInfo[k] - dataB.TimeInfo[s]); if (diff <= toleranceSeccond) { //IEnumerable<int> strB = dataB.EpochSatData.ElementAt(s).Value; string strA = dataA.PrnInfo[k]; string strB = dataB.PrnInfo[s]; if (strA == null || strB == null) { break; } for (int ss = 0; ss < strA.Length / 3; ss++) { string prn = strA.Substring(ss * 3, 3); if (strB.Contains(prn)) // if (strB.IndexOf(prn)!=-1) //即含有 { count += 1; } } } else { // if (dataB.Data.ElementAt(s).Key < dataA.Data.ElementAt(k).Key) if (dataB.TimeInfo[s] < dataA.TimeInfo[k]) { while (diff > toleranceSeccond) { s++; if (s >= dataB.TimeInfo.Length) { break; } //diff = Math.Abs(dataA.Data.ElementAt(k).Key - dataB.Data.ElementAt(s).Key); diff = Math.Abs(dataA.TimeInfo[k] - dataB.TimeInfo[s]); if (diff <= toleranceSeccond) { string strA = dataA.PrnInfo[k]; string strB = dataB.PrnInfo[s]; if (strA == null || strB == null) { break; } for (int ss = 0; ss < strA.Length / 3; ss++) { string prn = strA.Substring(ss * 3, 3); if (strB.Contains(prn)) { count += 1; } } break; } } } else if (dataB.TimeInfo[s] > dataA.TimeInfo[k]) { while (diff > toleranceSeccond) { k++; if (k >= dataA.TimeInfo.Length) { break; } diff = Math.Abs(dataA.TimeInfo[k] - dataB.TimeInfo[s]); if (diff <= toleranceSeccond) { string strA = dataA.PrnInfo[k]; string strB = dataB.PrnInfo[s]; if (strA == null || strB == null) { break; } for (int ss = 0; ss < strA.Length / 3; ss++) { string prn = strA.Substring(ss * 3, 3); if (strB.Contains(prn)) { count += 1; } } break; } } } } } //End 完成一条基线的统计 mgraph.edges[i][j] = count; road[ii] = new Road(); road[ii].a = i; road[ii].b = j; road[ii].w = count; ii++; ////写入 //string sb = dataA.SiteName + "-" + dataB.SiteName + " " + count.ToString(); //writer.WriteLine(sb); Node NodeA = new Node(); NodeA.Name = dataA.SiteNumber; NodeA.strName = dataA.SiteName; NodeA.Visited = false; NodeA.Tag = dataA.Path; Node NodeB = new Node(); NodeB.Name = dataB.SiteNumber; NodeB.strName = dataB.SiteName; NodeB.Visited = false; NodeB.Tag = dataB.Path; Edge edge = new Edge(); edge.NodeA = NodeA; edge.NodeB = NodeB; edge.Weight = count; string baselineName = dataA.SiteName + dataB.SiteName; graphRound.Add(baselineName, edge); } } //sort 排序 由大到小 List <KeyValuePair <string, Edge> > graphPair = new List <KeyValuePair <string, Edge> >(graphRound); graphPair.Sort(delegate(KeyValuePair <string, Edge> s1, KeyValuePair <string, Edge> s2) { return(s1.Value.Weight.CompareTo(s2.Value.Weight)); }); //存储排序基线 Dictionary <string, Edge> graph = new Dictionary <string, Edge>(); for (int index = graphPair.Count - 1; index >= 0; index--) { var item = graphPair.ElementAt(index); Edge edge = new Edge(); edge.NodeA = item.Value.NodeA; edge.NodeB = item.Value.NodeB; edge.Weight = item.Value.Weight; graph.Add(item.Key, edge); //重新排序 road[mgraph.e - 1 - index].a = DataOfAllSites[item.Value.NodeA.Name].SiteNumber; road[mgraph.e - 1 - index].b = DataOfAllSites[item.Value.NodeB.Name].SiteNumber; road[mgraph.e - 1 - index].w = item.Value.Weight; } //根据Kruskal算法生成最小生成树 GetMinCostSpanTree List <Edge> findedMinCostSpanTree = new List <Edge>(); List <List <Node> > findedNodes = new List <List <Node> >(); findedNodes.Add(new List <Node>() { graph.ElementAt(0).Value.NodeA, graph.ElementAt(0).Value.NodeB }); findedMinCostSpanTree.Add(graph.ElementAt(0).Value); for (int index = 1; index < graph.Count; index++) { var item = graph.ElementAt(index); int i = 0, indexA = -1, indexB = -1; Node nodeA = item.Value.NodeA; Node nodeB = item.Value.NodeB; foreach (var nodes in findedNodes) { foreach (var node in nodes) { if (!item.Value.NodeB.Visited && node.Name == nodeB.Name && node.Visited == nodeB.Visited) { item.Value.NodeB.Visited = true; indexB = i; } if (!item.Value.NodeA.Visited && node.Name == nodeA.Name && node.Visited == nodeA.Visited) { item.Value.NodeA.Visited = true; indexA = i; } } i++; } // if (item.Value.NodeA.Visited && item.Value.NodeB.Visited && (indexA != indexB)) { //连接不同的联通分量,则这两个连通分量可以合并成一个了。 int minId = Math.Min(indexA, indexB); int maxId = Math.Max(indexA, indexB); findedNodes[minId].AddRange(findedNodes[maxId]); findedNodes.RemoveAt(maxId); findedMinCostSpanTree.Add(item.Value); } else if (!item.Value.NodeA.Visited && !item.Value.NodeB.Visited) { //都不包含,直接添加新列表 findedNodes.Add(new List <Node>() { nodeA, nodeB }); findedMinCostSpanTree.Add(item.Value); } else if (item.Value.NodeA.Visited && !item.Value.NodeB.Visited) { //包含A,则将B添加到A的集合中去 findedNodes[indexA].Add(nodeB); findedMinCostSpanTree.Add(item.Value); } else if (!item.Value.NodeA.Visited && item.Value.NodeB.Visited) { //包含B,则将A添加到B的集合中去 findedNodes[indexB].Add(nodeA); findedMinCostSpanTree.Add(item.Value); } item.Value.NodeA.Visited = false; item.Value.NodeB.Visited = false; } //writer.WriteLine("\n"); //writer.WriteLine("根据最大观测量选择的独立基线: "); int jj = 0; IndepentBaselinesInfo = new List <GnssBaseLineName>(); foreach (var item in findedMinCostSpanTree) { var tmp = new GnssBaseLineName(item.NodeA.strName, item.NodeB.strName) { RefFilePath = item.NodeA.Tag + "", RovFilePath = item.NodeB.Tag + "", } ; // + BaseLineSplitter + item.NodeB.strName;// + " " + key.Weight; IndepentBaselinesInfo.Add(tmp); //写入 //writer.WriteLine(tmp); jj++; } //writer.Close(); //关闭 }
public void IndepentBaselineProcess() { //比较计算 // var name = DateTime.Now.ToString("yyyy-MM-dd_HH"); string outPath = Path.GetDirectoryName(files[0]) + "\\" + "baseline.param"; StreamWriter writer = new StreamWriter(outPath); //存储基线 Dictionary <string, Edge> graphRound = new Dictionary <string, Edge>(); int n = DataOfAllSites.Count; mgraph = new MGraph(); mgraph.n = n; mgraph.e = n * (n - 1) / 2; mgraph.vex = new VertexType[n]; mgraph.edges = new int[n][]; road = new Road[n * (n - 1) / 2]; v = new int[n * (n - 1) / 2]; int ii = 0; for (int i = 0; i < n; i++) { SiteEpochSatData dataA = DataOfAllSites.ElementAt(i).Value; mgraph.vex[i] = new VertexType(); mgraph.vex[i].no = i; mgraph.vex[i].name = dataA.SiteName; v[i] = i; //顶点ver[i]初始时表示各在不同的连通分支v[i]中,父结点依次为v[i] for (int j = i + 1; j < n; j++) { mgraph.edges[i] = new int[n]; SiteEpochSatData dataB = DataOfAllSites.ElementAt(j).Value; double toleranceSeccond = 0.5; //限差 单位:秒 int count = 0; for (int k = 0, s = 0; k < dataA.Data.Count && s < dataB.Data.Count; k++, s++) { double diff = Math.Abs(dataA.Data.ElementAt(k).Key - dataB.Data.ElementAt(s).Key); if (diff <= toleranceSeccond) { IEnumerable <int> strA = dataA.EpochSatData.ElementAt(k).Value; IEnumerable <int> strB = dataB.EpochSatData.ElementAt(s).Value; IEnumerable <int> comPrn = strA.Intersect(strB); //bool isIntersected = strA.Intersect(strB).Count() > 0; count += comPrn.Count(); int[] iA = dataA.EpochSatData.ElementAt(k).Value; int[] iB = dataB.EpochSatData.ElementAt(s).Value; int lengthA = iA.Length; int lengthB = iB.Length; int maxLength = Math.Max(lengthA, lengthB); int kk = 0, nn = 0, mm = 0; for (int ss = 0; ss < maxLength; ss++, kk++, nn++) { if (kk >= lengthA) { break; } if (nn >= lengthB) { break; } while (iA[kk] != iB[nn]) { if (iA[kk] > iB[nn]) { nn++; if (nn >= lengthB) { break; } } if (iA[kk] < iB[nn]) { kk++; if (kk >= lengthA) { break; } } } if (kk >= lengthA) { break; } if (nn >= lengthB) { break; } if (iA[kk] == iB[nn]) { mm++; } } if (mm != comPrn.Count()) { // } //foreach (var key in dataA.Data.ElementAt(k).Value) //{ // if (dataB.Data.ElementAt(s).Value.Contains(key)) // { count += 1; } //} } else { if (dataB.Data.ElementAt(s).Key < dataA.Data.ElementAt(k).Key) { while (diff > toleranceSeccond) { s++; if (s >= dataB.Data.Count) { break; } diff = Math.Abs(dataA.Data.ElementAt(k).Key - dataB.Data.ElementAt(s).Key); if (diff <= toleranceSeccond) { IEnumerable <int> strA = dataA.EpochSatData.ElementAt(k).Value; IEnumerable <int> strB = dataB.EpochSatData.ElementAt(s).Value; IEnumerable <int> comPrn = strA.Intersect(strB); count += comPrn.Count(); //foreach (var key in dataA.Data.ElementAt(k).Value) //{ // if (dataB.Data.ElementAt(s).Value.Contains(key)) // { count += 1; } //} break; } } } else if (dataB.Data.ElementAt(s).Key > dataA.Data.ElementAt(k).Key) { while (diff > toleranceSeccond) { k++; if (k >= dataA.Data.Count) { break; } diff = Math.Abs(dataA.Data.ElementAt(k).Key - dataB.Data.ElementAt(s).Key); if (diff <= toleranceSeccond) { IEnumerable <int> strA = dataA.EpochSatData.ElementAt(k).Value; IEnumerable <int> strB = dataB.EpochSatData.ElementAt(s).Value; IEnumerable <int> comPrn = strA.Intersect(strB); count += comPrn.Count(); //foreach (var key in dataA.Data.ElementAt(k).Value) //{ // if (dataB.Data.ElementAt(s).Value.Contains(key)) // { count += 1; } //} break; } } } } } //完成一条基线的统计 mgraph.edges[i][j] = count; road[ii] = new Road(); road[ii].a = i; road[ii].b = j; road[ii].w = count; ii++; //写入 string sb = dataA.SiteName + "-" + dataB.SiteName + " " + count.ToString(); writer.WriteLine(sb); Node NodeA = new Node(); NodeA.Name = dataA.SiteName; NodeA.Visited = false; Node NodeB = new Node(); NodeB.Name = dataB.SiteName; NodeB.Visited = false; Edge edge = new Edge(); edge.NodeA = NodeA; edge.NodeB = NodeB; edge.Weight = count; string baselineName = NodeA.Name + NodeB.Name; graphRound.Add(baselineName, edge); } } //sort List <KeyValuePair <string, Edge> > graphPair = new List <KeyValuePair <string, Edge> >(graphRound); graphPair.Sort(delegate(KeyValuePair <string, Edge> s1, KeyValuePair <string, Edge> s2) { return(s1.Value.Weight.CompareTo(s2.Value.Weight)); }); //存储排序基线 Dictionary <string, Edge> graph = new Dictionary <string, Edge>(); for (int index = graphPair.Count - 1; index >= 0; index--) { var item = graphPair.ElementAt(index); Edge edge = new Edge(); edge.NodeA = item.Value.NodeA; edge.NodeB = item.Value.NodeB; edge.Weight = item.Value.Weight; graph.Add(item.Key, edge); //重新排序 road[mgraph.e - 1 - index].a = DataOfAllSites[item.Value.NodeA.Name].SiteNumber; road[mgraph.e - 1 - index].b = DataOfAllSites[item.Value.NodeB.Name].SiteNumber; road[mgraph.e - 1 - index].w = item.Value.Weight; } //Kruskal GetMinCostSpanTree List <Edge> finded = new List <Edge>(); List <List <Node> > findedNodes = new List <List <Node> >(); findedNodes.Add(new List <Node>() { graph.ElementAt(0).Value.NodeA, graph.ElementAt(0).Value.NodeB }); finded.Add(graph.ElementAt(0).Value); for (int index = 1; index < graph.Count; index++) { var item = graph.ElementAt(index); int i = 0, indexA = -1, indexB = -1; Node nodeA = item.Value.NodeA; Node nodeB = item.Value.NodeB; foreach (var nodes in findedNodes) { foreach (var node in nodes) { if (!item.Value.NodeB.Visited && node.Name == nodeB.Name && node.Visited == nodeB.Visited) { item.Value.NodeB.Visited = true; indexB = i; } if (!item.Value.NodeA.Visited && node.Name == nodeA.Name && node.Visited == nodeA.Visited) { item.Value.NodeA.Visited = true; indexA = i; } } i++; } // if (item.Value.NodeA.Visited && item.Value.NodeB.Visited && (indexA != indexB)) { //连接不同的联通分量,则这两个连通分量可以合并成一个了。 int minId = Math.Min(indexA, indexB); int maxId = Math.Max(indexA, indexB); findedNodes[minId].AddRange(findedNodes[maxId]); findedNodes.RemoveAt(maxId); finded.Add(item.Value); } else if (!item.Value.NodeA.Visited && !item.Value.NodeB.Visited) { //都不包含,直接添加新列表 findedNodes.Add(new List <Node>() { nodeA, nodeB }); finded.Add(item.Value); } else if (item.Value.NodeA.Visited && !item.Value.NodeB.Visited) { //包含A,则将B添加到A的集合中去 findedNodes[indexA].Add(nodeB); finded.Add(item.Value); } else if (!item.Value.NodeA.Visited && item.Value.NodeB.Visited) { //包含B,则将A添加到B的集合中去 findedNodes[indexB].Add(nodeA); finded.Add(item.Value); } item.Value.NodeA.Visited = false; item.Value.NodeB.Visited = false; } writer.WriteLine("\n"); writer.WriteLine("根据最大观测量选择的独立基线: "); foreach (var item in finded) { string tmp = item.NodeA.Name + "-" + item.NodeB.Name + " " + item.Weight; //写入 writer.WriteLine(tmp); } writer.Close(); //关闭 }