C# code for BenchmarkRandomNW

C# code for BenchmarkRandomNW

public static string BenchmarkRandomNW(string mainDir, Tasker server, int iters, CostType costType)
{
    Random r = new Random();
    string msg = "";
    double totTime = 0;

    // Loop over list of network to run the benchmark on
    foreach (string network in new string[] { "england", "glasgow", "napoli", "stockholm" })
    {
        // Create network and router class, and add it to server ('using' statement will remove it with Dispose)
        Storage st = new Storage(mainDir, network);
        Watch totalTime = new Watch();
        Router router = new Router(server, 4, st, costType);

        // Do lots of random routes, and measure and display elapsed time
        for (int i = 0; i < iters; i++)
        {
            SpatialIndex si = st.SpatialIndex;
            double x1 = r.NextDouble() * si.Width + si.XMin, y1 = r.NextDouble() * si.Height + si.YMin;
            double x2 = r.NextDouble() * si.Width + si.XMin, y2 = r.NextDouble() * si.Height + si.YMin;
            NodePath result = router.Route(x1, y1, x2, y2, false);
            totTime += result == null ? 0 : result.Time;
        }
        msg += "Network: " + st.Info.Name + "   ms/route: " + totalTime.MilliSeconds / iters +
                "   Average travel time: " + TimeSpan.FromSeconds(totTime / iters) + Environment.NewLine;
        totTime = 0;
    }
    return msg;
}
Select all code
Close
Copyright © 2012 Xtreme Route - All Rights Reserved. Contact us: