Beispiel #1
0
 public ClusterManager(Context context, GoogleMap map, MarkerManager markerManager)
 {
     mMap            = map;
     mMarkerManager  = markerManager;
     mClusterMarkers = markerManager.newCollection();
     mMarkers        = markerManager.newCollection();
     mRenderer       = new DefaultClusterRenderer <T>(context, map, this);
     mAlgorithm      = new PreCachingAlgorithmDecorator <T>(new NonHierarchicalDistanceBasedAlgorithm <T>());
     mClusterTask    = new ClusterTask(this);
     mRenderer.onAdd();
 }
    static void Main(string[] args)
    {
        Console.WriteLine("Generating random matrix...");
        // generate Matrix with the size as input
        int[,] arrTest = creatRandomArray(5, 5);
        Console.WriteLine("Generated matrix : ");
        printArray(arrTest);

        Console.WriteLine("\nDoing MapReduce...");
        int rows = arrTest.GetLength(1);

        ClusterTask[] tasks = new ClusterTask[rows];
        Thread[]      t     = new Thread[rows];

        //map
        for (int i = 0; i < rows; i++)
        {
            tasks[i] = new ClusterTask(getRow(arrTest, i));
            t[i]     = new Thread(new ThreadStart(tasks[i].execute));
            t[i].Start();
        }

        // Here I need to wait all the threads to have ended
        foreach (Thread th in t)
        {
            th.Join();
        }

        // Here I am collecting all the results of each thread/node
        List <Dictionary <int, int> > results = new List <Dictionary <int, int> >();

        for (int i = 0; i < rows; i++)
        {
            results.Add(tasks[i].GetResults());
        }

        // Reduce
        Dictionary <int, int> final = Reduce(results);

        // Print dictionary ordered by key
        var list = final.Keys.ToList();

        list.Sort();

        // Loop through keys.
        foreach (var key in list)
        {
            Console.WriteLine("Number = {0}, Occurence = {1}", key, final[key]);
        }

        Console.ReadKey();
    }
Beispiel #3
0
 /// <summary>
 /// Force a re-cluster. You may want to call this after adding new item(s).
 /// </summary>
 public virtual void cluster()
 {
     mClusterTaskLock.AcquireWriterLock(5);
     try
     {
         // Attempt to cancel the in-flight request.
         mClusterTask.Cancel(true);
         mClusterTask = new ClusterTask(this);
         mClusterTask.Execute(mMap.CameraPosition.Zoom);
     }
     finally
     {
         mClusterTaskLock.ReleaseWriterLock();
     }
 }