private Hashtable worst = new Hashtable(); // trakcs the worst #endregion Fields #region Constructors public NRA(NearestNeighbor.NearestNeighbor in1, NearestNeighbor.NearestNeighbor in2) { numAccess = 0; obj1 = in1; obj2 = in2; op = new COMP(avg); }
public Algorithm( IPoints points, IRectangle rect, StrategyType type = StrategyType.Grid, ILog2 log = null) { _log = log ?? new NoLog(); Rectangle = rect; Points = points.Data; Singles = new List <IP>(); Knn = new NearestNeighbor(); GridContainer = new GridContainer(Rectangle, Points); switch (type) { case StrategyType.Naive: Strategy = new NaiveStrategy(_log); break; case StrategyType.Grid: Strategy = new GridStrategy(_log); break; case StrategyType.KdTree: Strategy = new KdTreeStrategy(Points); break; default: throw new NotImplementedException("Unknown strategy"); } //_log.Info(MethodBase.GetCurrentMethod(), "object init"); }
/// <summary> /// Create the concrete instance of the Algorithm with a specified Neighborhood as parameter. /// </summary> /// <param name="currentAlgorithm"> Algorithm type to create. </param> /// <param name="neighborhood"> Neighborhood type to pass to the Algorithm. </param> /// <returns> The Algorithm's instance to run. </returns> internal static Algorithm CreateAlgorithm(AlgorithmType algorithmType, Neighborhood <ToSolution> neighborhood) { Algorithm algorithm = default; switch (algorithmType) { case AlgorithmType.None: break; case AlgorithmType.NearestNeighbor: algorithm = new NearestNeighbor(); break; case AlgorithmType.NearestNeighborKnapsack: algorithm = new NearestNeighborKnapsack(); break; case AlgorithmType.CheapestInsertion: algorithm = new CheapestInsertion(); break; case AlgorithmType.TwoOpt: if (neighborhood == null) { neighborhood = NeighborhoodFactory.CreateNeighborhood(algorithmType); } algorithm = new LocalSearchTemplate(neighborhood); break; case AlgorithmType.LinKernighan: algorithm = new LinKernighan(); break; case AlgorithmType.HybridCustomInsertion: algorithm = new HybridCustomInsertion(); break; case AlgorithmType.HybridCustomUpdate: algorithm = new HybridCustomUpdate(); break; case AlgorithmType.TabuSearch: if (neighborhood == null) { neighborhood = NeighborhoodFactory.CreateNeighborhood(algorithmType); } algorithm = new TabuSearch(neighborhood); break; // Add new Algorithm types here ... default: throw new ArgumentOutOfRangeException(nameof(algorithmType), algorithmType, null); } return(algorithm); }
public void TestDoubleTreeFailOnIncompleteGraph() { Graph <int, double> graph = new GraphBuilder <int, double>() .AddVerteces(5, v => v) .AddEdge(0, 2) .AddEdge(2, 1) .AddEdge(2, 3) .AddEdge(2, 4) .Build(); NearestNeighbor.FindTour(graph); }
static void Main(string[] args) { List <Vector> positives = new List <Vector>(); List <Vector> negatives = new List <Vector>(); // Vectorの各要素 0:無料 1:出会い 2:登録 3:参加 4:講義 positives.Add(new Vector(new double[] { 1.0, 0, 0, 1.0, 1.0 })); negatives.Add(new Vector(new double[] { 2.0, 1.0, 1.0, 1.0, 0 })); NearestNeighbor nearestNeighbor = new NearestNeighbor(positives, negatives); int result = nearestNeighbor.Classify(new Vector(new double[] { 1.0, 1.0, 1.0, 0, 0 }), 1); Console.WriteLine(result); Console.ReadKey(); }
static void Main1(string[] args) { // Usage: // NearestNeighbour [indexFolder queryfile pagesize=6000 outputfile=results.txt] NearestNeighbor nnObj1 = new NearestNeighbor(); nnObj1.setFolderDir(@"C:\cse515\idx\sift_k50_l16\"); nnObj1.setQueryFile(@"C:\cse515\sift-query.txt"); NearestNeighbor nnObj2 = new NearestNeighbor(); nnObj2.setFolderDir(@"C:\cse515\idx\shape_k8_l5\"); nnObj2.setQueryFile(@"C:\cse515\query.txt"); NRA merge = new NRA(nnObj1, nnObj2); List<string> images = merge.mergeAndReturn(2); foreach (string i in images) { Console.WriteLine("image: " + i); } //resultSet = nnObj1.getNext(7); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //resultSet = nnObj.getNext(10); //feature index starts from 0, so if you wanna change the 5th feature, pass 4 here... //nnObj.setFeatureWeight(2, 4.0); //MyResultSet newResults = nnObj.getFirst(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //newResults = nnObj.getNext(10); //nnObj.setQueryFile(@"E:\CG\NearestNeighborCS\NearestNeighborCS\bin\Debug\query1.txt"); //newResults = nnObj.getFirst(10); }
private void TestTspAlgorithm(IWeightedGraph <int, double> graph, TspAlgorithm algorithm, int expectedVerteces, int expectedEdges, double optimalTourCosts = 0.0, double precision = 0.01) { IWeightedGraph <int, double> tour = null; // Compute tour with the chosen algorithm switch (algorithm) { case TspAlgorithm.NearestNeighbor: tour = NearestNeighbor.FindTour(graph); break; case TspAlgorithm.DoubleTree: tour = DoubleTree.FindTour(graph); break; case TspAlgorithm.BruteForce: tour = BruteForce.FindOptimalTour(graph, 0.0, double.MaxValue, (w1, w2) => w1 + w2); break; default: throw new NotSupportedException($"Testing TSP with the {algorithm} algorithm is currently not supported."); } // Check route for component count Assert.AreEqual(expectedVerteces, tour.VertexCount); Assert.AreEqual(expectedEdges, tour.GetAllEdges().Count()); // For algorithms that find the optimal tour, check the optmial tour costs if (algorithm == TspAlgorithm.BruteForce) { AssertDoublesNearlyEqual(optimalTourCosts, tour.GetAllEdges().Sum(e => e.Weight), precision); } }
void Awake() { _pawn = GetComponent <IControllable>(); _nearestNeighbor = GetComponent <NearestNeighbor>(); }