protected override int ChooseNext(Route route) { if (route.Count == 0) { return(0); } // New method which happens to be worse for the biggest graph: // best = route.SelectNextBest(); int last = route[route.Count - 1]; int best = -1; int bestVal = -1; int score = Int32.MaxValue; for (int i = route.Count; i < route.Graph.Count; ++i) { int val = route.GetFromSelectionBuffer(i); int dist = route.Graph[last, val]; if (dist < score || (dist == score && val < bestVal)) { best = i; bestVal = val; score = dist; } } return(best); }
protected override int ChooseNext(Route route) { if (route.Count == 0) { return(0); } if (_testRoute == null || _testRoute.Graph != route.Graph) { _testRoute = new Route(route.Graph); } int best = -1; int bestVal = -1; int score = Int32.MaxValue; for (int i = route.Count; i < route.Graph.Count; ++i) { int val = route.GetFromSelectionBuffer(i); _testRoute.Clear(); _testRoute.Copy(route); _testRoute.AddEnd(i); Improver.Improve(_testRoute, false); int dist = _testRoute.Length; if (dist < score || (dist == score && val < bestVal)) { best = i; bestVal = val; score = dist; } } return(best); }
protected override int ChooseNext( Route route ) { if ( route.Count == 0 ) return 0; if ( _testRoute == null || _testRoute.Graph != route.Graph ) _testRoute = new Route( route.Graph ); int best = -1; int bestVal = -1; int score = Int32.MaxValue; for ( int i = route.Count; i < route.Graph.Count; ++i ) { int val = route.GetFromSelectionBuffer( i ); _testRoute.Clear(); _testRoute.Copy( route ); _testRoute.AddEnd( i ); Improver.Improve( _testRoute, false ); int dist = _testRoute.Length; if ( dist < score || ( dist == score && val < bestVal ) ) { best = i; bestVal = val; score = dist; } } return best; }
protected override int ChooseNext( Route route ) { if ( route.Count == 0 ) return 0; // New method which happens to be worse for the biggest graph: // best = route.SelectNextBest(); int last = route[route.Count - 1]; int best = -1; int bestVal = -1; int score = Int32.MaxValue; for ( int i = route.Count; i < route.Graph.Count; ++i ) { int val = route.GetFromSelectionBuffer( i ); int dist = route.Graph[last, val]; if ( dist < score || ( dist == score && val < bestVal ) ) { best = i; bestVal = val; score = dist; } } return best; }
protected override int ChooseNext(Route route) { if (route.Count == 0) { return(0); } int best = -1; int score = 0; _lastIndex = 0; for (int i = route.Count; i < route.Graph.Count; ++i) { int val = route.GetFromSelectionBuffer(i); int minDist = Int32.MaxValue; int minIndex = 0; for (int j = 0; j < route.Count; ++j) { int dist = route.Graph[val, route[j]] + route.Graph[val, route[j + 1]]; if (dist < minDist) { minDist = dist; minIndex = j; } } if (minDist > score) { best = i; score = minDist; _lastIndex = minIndex; } } return(best); }
protected override int ChooseNext( Route route ) { if ( route.Count == 0 ) return 0; int best = -1; int score = 0; _lastIndex = 0; for ( int i = route.Count; i < route.Graph.Count; ++i ) { int val = route.GetFromSelectionBuffer( i ); int minDist = Int32.MaxValue; int minIndex = 0; for ( int j = 0; j < route.Count; ++j ) { int dist = route.Graph[val, route[j]] + route.Graph[val, route[j + 1]]; if ( dist < minDist ) { minDist = dist; minIndex = j; } } if ( minDist > score ) { best = i; score = minDist; _lastIndex = minIndex; } } return best; }