public override DataFormat.IOutBlackBoxParam Calculate() { IPoint p1=new Point(parametr.x1_min,parametr.x2_min); IPoint p2=new Point(parametr.x1_max,parametr.x2_max); IPlace place = new Place(p1, p2, parametr); Double best; place.Separate(this); best = place.bestPoint.cost.Cost; int j = 0; for (int i = 0; i < 40; i++) { if ((place.allPlaces.Count-1) < j) { j = place.allPlaces.Count - 1; if (place.allPlaces.Count == 0) break; } IPlace pl= place.allPlaces[j]; if (!pl.IsSeparated) { pl.Separate(this); if(pl.bestPoint.cost.Cost==Double.MaxValue) { pl.parent.removePlace(pl); } if ((best > pl.bestPoint.cost.Cost) && (pl.bestPoint.cost.Cost > 0)) best = pl.bestPoint.cost.Cost; } else { i--; } j++; } return new OutBlackBoxParam(best); }
public void Separate(ICalculateFunction calculate) { if (!isSeparated) { ILine line = new Line(point1, point2); if (line.length > 0) { if (point1.cost == null) { Calculate(point1, calculate); } if (point2.cost == null) { Calculate(point2, calculate); } if ((point2.cost != null) && (point1.cost != null)) { if (point2.cost.Cost > point1.cost.Cost) setBest(point1); else setBest(point2); } IPoint p = line.GetPoint(this.rng.NextDouble() * (line.length)); if (p == null) p = line.GetPoint(this.rng.NextDouble() * (line.length)); /* if (p == null) { isSeparated = true; return; }*/ Calculate(p, calculate); if (p.cost==null) { Calculate(p, calculate); } if (best == null) { setBest(p); }else if (best.cost.Cost > p.cost.Cost) setBest(p); IPlace place = new Place(point1, p); this.places.Add(place); place.parent = this; place = new Place(p, point2); this.places.Add(place); place.parent = this; IPoint p3 = new Point(point1.x1, point2.x2); place = new Place(p3, p); this.places.Add(place); place.parent = this; IPoint p4 = new Point(point2.x1, point1.x2); place = new Place(p, p4); this.places.Add(place); place.parent = this; line = new Line(p3, p4); IPoint pn = line.GetPoint(this.rng.NextDouble() * (line.length)); Calculate(pn, calculate); setBest(pn); isSeparated = true; } else { Calculate(point1, calculate); setBest(point1); } } }