Пример #1
0
    public static void testSpatialCollection(ISpatialCollection<AgentType> testingAgents)
    {
      Console.WriteLine("Running test for " + testingAgents.GetType().Name);
      ISpatialCollection<AgentType> baseAgents = new SpatialCollectionAsList<AgentType>();
      List<AgentType> agents = new List<AgentType>();
      Console.WriteLine("Creating Agents.");
      for (int i = 0; i < NUM_AGENTS; i++) agents.Add(new AgentType(Random.RandomPoint(min, max)));
      // DK: For testing/debugging, was using just these 2 points:
      // agents.Add(new AgentType(new Point3d(1, 1, 1)));
      // agents.Add(new AgentType(new Point3d(1, 1, 1.01)));

      Stopwatch stopwatchBase = new Stopwatch();
      Stopwatch stopwatchTesting = new Stopwatch();
      Console.WriteLine("Getting add time data.");

      stopwatchBase.Start();
      foreach (AgentType agent in agents)
      {
          baseAgents.Add(agent);
      }
      //baseAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
      stopwatchBase.Stop();

      stopwatchTesting.Start();
      foreach (AgentType agent in agents)
      {
        testingAgents.Add(agent);
      }
      //testingAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
      stopwatchTesting.Stop();

      TimeSpan baseAddTime = stopwatchBase.Elapsed;
      TimeSpan testAddTime = stopwatchTesting.Elapsed;
      Console.WriteLine("Base time elapsed: {0}", baseAddTime);
      Console.WriteLine("Testing time elapsed: {0}", testAddTime);

      Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedTicks / stopwatchBase.ElapsedTicks);

      if (CHECKMATCH) // DK: added so we can easily turn on and off this expensive check
      {
          Console.WriteLine("Checking neighbors match.");
          foreach (AgentType agent in agents)
          {
              ISpatialCollection<AgentType> testingNeighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
              ISpatialCollection<AgentType> baseNeighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
              foreach (AgentType neighbor in testingNeighbors)
              {
                  if (!listContainsByReferenceEquals(neighbor, baseNeighbors))
                  {
                    Console.WriteLine("Mismatch1! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                      Console.ReadLine();
                      //throw new Exception();
                  }
              }
              foreach (AgentType neighbor in baseNeighbors)
              {
                  if (!listContainsByReferenceEquals(neighbor, testingNeighbors))
                  {
                    Console.WriteLine("Mismatch2! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                      Console.ReadLine();
                      //throw new Exception();
                  }
              }
          }
      }
      Console.WriteLine("Getting getNeighbors timing data.");
      stopwatchBase.Restart();
      foreach (AgentType agent in agents)
      {
        ISpatialCollection<AgentType> neighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
      }
      stopwatchBase.Stop();
      TimeSpan baseNeighborsTime = stopwatchBase.Elapsed;
      Console.WriteLine("Base time elapsed: {0}", baseNeighborsTime);

      
      stopwatchTesting.Restart();
      foreach (AgentType agent in agents)
      {
        ISpatialCollection<AgentType> neighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
      }
      stopwatchTesting.Stop();
      TimeSpan testNeighborsTime = stopwatchTesting.Elapsed;
      Console.WriteLine("Testing time elapsed: {0}", testNeighborsTime);

      Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedMilliseconds / stopwatchBase.ElapsedMilliseconds);

      TimeSpan totalBaseTime = baseAddTime.Add(baseNeighborsTime);
      Console.WriteLine("Total base time: {0}", totalBaseTime);
      TimeSpan totalTestTime = testAddTime.Add(testNeighborsTime);
      Console.WriteLine("Total test time: {0}", totalTestTime);
      Console.WriteLine("Total elapsed time ratio: {0}", 1.0 * totalTestTime.TotalMilliseconds / totalBaseTime.TotalMilliseconds);
    }
Пример #2
0
        public static void testSpatialCollection(ISpatialCollection <AgentType> testingAgents)
        {
            Console.WriteLine("Running test for " + testingAgents.GetType().Name);
            ISpatialCollection <AgentType> baseAgents = new SpatialCollectionAsList <AgentType>();
            List <AgentType> agents = new List <AgentType>();

            Console.WriteLine("Creating Agents.");
            for (int i = 0; i < NUM_AGENTS; i++)
            {
                agents.Add(new AgentType(Random.RandomPoint(min, max)));
            }
            // DK: For testing/debugging, was using just these 2 points:
            // agents.Add(new AgentType(new Point3d(1, 1, 1)));
            // agents.Add(new AgentType(new Point3d(1, 1, 1.01)));

            Stopwatch stopwatchBase    = new Stopwatch();
            Stopwatch stopwatchTesting = new Stopwatch();

            Console.WriteLine("Getting add time data.");

            stopwatchBase.Start();
            foreach (AgentType agent in agents)
            {
                baseAgents.Add(agent);
            }
            //baseAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
            stopwatchBase.Stop();

            stopwatchTesting.Start();
            foreach (AgentType agent in agents)
            {
                testingAgents.Add(agent);
            }
            //testingAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
            stopwatchTesting.Stop();

            TimeSpan baseAddTime = stopwatchBase.Elapsed;
            TimeSpan testAddTime = stopwatchTesting.Elapsed;

            Console.WriteLine("Base time elapsed: {0}", baseAddTime);
            Console.WriteLine("Testing time elapsed: {0}", testAddTime);

            Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedTicks / stopwatchBase.ElapsedTicks);

            if (CHECKMATCH) // DK: added so we can easily turn on and off this expensive check
            {
                Console.WriteLine("Checking neighbors match.");
                foreach (AgentType agent in agents)
                {
                    ISpatialCollection <AgentType> testingNeighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
                    ISpatialCollection <AgentType> baseNeighbors    = baseAgents.getNeighborsInSphere(agent, visionRadius);
                    foreach (AgentType neighbor in testingNeighbors)
                    {
                        if (!listContainsByReferenceEquals(neighbor, baseNeighbors))
                        {
                            Console.WriteLine("Mismatch1! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                            Console.ReadLine();
                            //throw new Exception();
                        }
                    }
                    foreach (AgentType neighbor in baseNeighbors)
                    {
                        if (!listContainsByReferenceEquals(neighbor, testingNeighbors))
                        {
                            Console.WriteLine("Mismatch2! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                            Console.ReadLine();
                            //throw new Exception();
                        }
                    }
                }
            }
            Console.WriteLine("Getting getNeighbors timing data.");
            stopwatchBase.Restart();
            foreach (AgentType agent in agents)
            {
                ISpatialCollection <AgentType> neighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
            }
            stopwatchBase.Stop();
            TimeSpan baseNeighborsTime = stopwatchBase.Elapsed;

            Console.WriteLine("Base time elapsed: {0}", baseNeighborsTime);


            stopwatchTesting.Restart();
            foreach (AgentType agent in agents)
            {
                ISpatialCollection <AgentType> neighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
            }
            stopwatchTesting.Stop();
            TimeSpan testNeighborsTime = stopwatchTesting.Elapsed;

            Console.WriteLine("Testing time elapsed: {0}", testNeighborsTime);

            Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedMilliseconds / stopwatchBase.ElapsedMilliseconds);

            TimeSpan totalBaseTime = baseAddTime.Add(baseNeighborsTime);

            Console.WriteLine("Total base time: {0}", totalBaseTime);
            TimeSpan totalTestTime = testAddTime.Add(testNeighborsTime);

            Console.WriteLine("Total test time: {0}", totalTestTime);
            Console.WriteLine("Total elapsed time ratio: {0}", 1.0 * totalTestTime.TotalMilliseconds / totalBaseTime.TotalMilliseconds);
        }