private void Optimize(int begin, int end, IntervalCollection meta, CostDelegate cost_del) { Interval set; set.contiguous = false; int best_set_begin = -1; int best_set_end = -1; double best_set_cost = 0; for (int i = begin; i <= end; ++i) { set.low = this[i].low; double cost = 0.0; for (int j = i; j <= end; ++j) { set.high = this[j].high; cost += cost_del(this[j]); double set_cost = cost_del(set); if (set_cost < cost && cost > best_set_cost) { best_set_begin = i; best_set_end = j; best_set_cost = cost; } } } if (best_set_begin < 0) { // didn't find an optimal set: add original members for (int i = begin; i <= end; ++i) { meta.Add(this[i]); } } else { // found set: add it ... set.low = this[best_set_begin].low; set.high = this[best_set_end].high; meta.Add(set); // ... and optimize to the left and right if (best_set_begin > begin) { Optimize(begin, best_set_begin - 1, meta, cost_del); } if (best_set_end < end) { Optimize(best_set_end + 1, end, meta, cost_del); } } }
private void Optimize(int begin, int end, IntervalCollection meta, CostDelegate cost_del) { Interval i = default(Interval); i.contiguous = false; int num = -1; int num2 = -1; double num3 = 0.0; for (int j = begin; j <= end; j++) { Interval interval = this[j]; i.low = interval.low; double num4 = 0.0; for (int k = j; k <= end; k++) { Interval interval2 = this[k]; i.high = interval2.high; num4 += cost_del(this[k]); double num5 = cost_del(i); if (num5 < num4 && num4 > num3) { num = j; num2 = k; num3 = num4; } } } if (num < 0) { for (int l = begin; l <= end; l++) { meta.Add(this[l]); } return; } Interval interval3 = this[num]; i.low = interval3.low; Interval interval4 = this[num2]; i.high = interval4.high; meta.Add(i); if (num > begin) { Optimize(begin, num - 1, meta, cost_del); } if (num2 < end) { Optimize(num2 + 1, end, meta, cost_del); } }
private void Optimize(int begin, int end, IntervalCollection meta, IntervalCollection.CostDelegate cost_del) { Interval i; i.contiguous = false; int num = -1; int num2 = -1; double num3 = 0.0; for (int j = begin; j <= end; j++) { i.low = this[j].low; double num4 = 0.0; for (int k = j; k <= end; k++) { i.high = this[k].high; num4 += cost_del(this[k]); double num5 = cost_del(i); if (num5 < num4 && num4 > num3) { num = j; num2 = k; num3 = num4; } } } if (num < 0) { for (int l = begin; l <= end; l++) { meta.Add(this[l]); } } else { i.low = this[num].low; i.high = this[num2].high; meta.Add(i); if (num > begin) { this.Optimize(begin, num - 1, meta, cost_del); } if (num2 < end) { this.Optimize(num2 + 1, end, meta, cost_del); } } }
private void Optimize (int begin, int end, IntervalCollection meta, CostDelegate cost_del) { Interval set; set.contiguous = false; int best_set_begin = -1; int best_set_end = -1; double best_set_cost = 0; for (int i = begin; i <= end; ++ i) { set.low = this[i].low; double cost = 0.0; for (int j = i; j <= end; ++ j) { set.high = this[j].high; cost += cost_del (this[j]); double set_cost = cost_del (set); if (set_cost < cost && cost > best_set_cost) { best_set_begin = i; best_set_end = j; best_set_cost = cost; } } } if (best_set_begin < 0) { // didn't find an optimal set: add original members for (int i = begin; i <= end; ++ i) meta.Add (this[i]); } else { // found set: add it ... set.low = this[best_set_begin].low; set.high = this[best_set_end].high; meta.Add (set); // ... and optimize to the left and right if (best_set_begin > begin) Optimize (begin, best_set_begin - 1, meta, cost_del); if (best_set_end < end) Optimize (best_set_end + 1, end, meta, cost_del); } }