/// <summary>Compare the diffs for all existing patches</summary> /// <returns>The IDs of pairs that can be merged</returns> private PatchIDs ComparePatches() { // Note: // The code added so far is only tentative, better rulles to decide which patches are similar need to be developed PatchIDs Patches = new PatchIDs(); List <int> recipient = new List <int>(); List <int> disappearing = new List <int>(); for (int k1 = 0; k1 < Patch.Count; k1++) { for (int k2 = k1 + 1; k2 < Patch.Count; k2++) { // go through a series of criteria t evaluate whether the two patches can be merged if (Math.Abs(Patch[k1].carbon_tot[0] - Patch[k2].carbon_tot[0]) < EPSILON) { if (Math.Abs(Patch[k1].no3[0] - Patch[k2].no3[0]) < EPSILON) { recipient.Add(k1); disappearing.Add(k2); } } } } Patches.recipient = recipient; Patches.disappearing = disappearing; return(Patches); }
private void OnDoUpdate(object sender, EventArgs e) { // + Purpose: Check patch status and clean up, if possible if (Patch.Count > 1000) // must set this to one later { // we have more than one patch, check whether they are similar enough to be merged PatchIDs Patches = new PatchIDs(); Patches = ComparePatches(); if (Patches.disappearing.Count > 0) { // there are patches that will be merged for (int k = 0; k < Patches.disappearing.Count; k++) { MergePatches(Patches.recipient[k], Patches.disappearing[k]); Summary.WriteMessage(this, " merging Patch(" + Patches.disappearing[k].ToString() + ") into Patch(" + Patches.recipient[k].ToString() + "). New patch area = " + Patch[Patches.recipient[k]].RelativeArea.ToString("#0.00#")); } } } }
/// <summary>Compare the diffs for all existing patches</summary> /// <returns>The IDs of pairs that can be merged</returns> private PatchIDs ComparePatches() { // Note: // The code added so far is only tentative, better rulles to decide which patches are similar need to be developed PatchIDs Patches = new PatchIDs(); List<int> recipient = new List<int>(); List<int> disappearing = new List<int>(); for (int k1 = 0; k1 < Patch.Count; k1++) { for (int k2 = k1 + 1; k2 < Patch.Count; k2++) { // go through a series of criteria t evaluate whether the two patches can be merged if (Math.Abs(Patch[k1].carbon_tot[0] - Patch[k2].carbon_tot[0]) < EPSILON) { if (Math.Abs(Patch[k1].no3[0] - Patch[k2].no3[0]) < EPSILON) { recipient.Add(k1); disappearing.Add(k2); } } } } Patches.recipient = recipient; Patches.disappearing = disappearing; return Patches; }
private void OnDoUpdate(object sender, EventArgs e) { // + Purpose: Check patch status and clean up, if possible if (Patch.Count > 1000) // must set this to one later { // we have more than one patch, check whether they are similar enough to be merged PatchIDs Patches = new PatchIDs(); Patches = ComparePatches(); if (Patches.disappearing.Count > 0) { // there are patches that will be merged for (int k = 0; k < Patches.disappearing.Count; k++) { MergePatches(Patches.recipient[k], Patches.disappearing[k]); Summary.WriteMessage(this, " merging Patch(" + Patches.disappearing[k].ToString() + ") into Patch(" + Patches.recipient[k].ToString() + "). New patch area = " + Patch[Patches.recipient[k]].RelativeArea.ToString("#0.00#")); } } } }