Ejemplo n.º 1
0
        public UI()
        {
            InitializeComponent();
              if (!Constant.TESTING)
              {
            xb = new Xbee();
            xb.open();
            xb.enter_api_mode();
              }

              //Initiates C# built-in double buffering
              this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

              this.Invalidate();
              PersistedDataBySignalStrength d = new PersistedDataBySignalStrength(new FileStream("resources/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read));
              loc = new ArrayBasedLocations(d.load());

              panel1.Visible = false;

              this.room = new BasicRoom();
              this.room.location = new Point(panel1.Location.X, panel1.Location.Y);
              room.size = new Size(panel1.Size.Width, panel1.Size.Height);

              // Initialized displayed orientations
              display_north = true;
              display_east = true;
              display_south = true;
              display_west = true;

              generate_new_location_list_from_signal_strength();
              sld_cluster_radius.set_range(0, 6);
              sld_cluster_radius.value = 1;
              this.clusters = Clusterer.cluster(this.locations, (float)sld_cluster_radius.value);
              sld_num_clusters.set_range(1, clusters.Count);
              sld_num_clusters.value = sld_num_clusters.Maximum;
              lbl_cluster_radius.Text = sld_cluster_radius.value.ToString();
              lbl_num_clusters.Text = sld_num_clusters.value.ToString();

              // Initialize renderer type
              this.room.set_renderer_type(Constant.HEAT_MAP_RENDERER);
        }
        public void will_test_construtor()
        {
            uint primary_key_count = 1;
              uint node_count = 1;
              uint orientation_count = 1;
              uint value_cnt = 6;

              List<Location>[, ,] locations = new List<Location>[primary_key_count,node_count,orientation_count];

              locations[0, 0, 0] = new List<Location>();
              for(int i = 0; i < value_cnt; i++)
              {
            locations[0, 0, 0].Add(new Location(1, i));
              }

              ILocations loc = new ArrayBasedLocations(locations);

              for (int i = 0; i < value_cnt; i++)
              {
            Specify.That(loc.get_locations(0, 0, 0)[i].Equals(locations[0,0,0][i])).ShouldBeTrue();
              }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Boolean display_north = false;
              Boolean display_east = false;
              Boolean display_south = false;
              Boolean display_west = false;

              PersistedDataBySignalStrength d = new PersistedDataBySignalStrength
            (new FileStream("resources/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read));
              ILocations loc = new ArrayBasedLocations(d.load());
              List<Location> locations = new List<Location>();
              List<Location> l = new List<Location>();

              string orientation = "";
              int diameter = -1;
              if(args.Length == 2)
              {
            orientation = args[0];
            try
            {
              diameter = Convert.ToInt32(args[1]);
            }
            catch
            {
              Console.WriteLine(program_usage("A valid cluster radius was not entered."));
              return;
            }
              }
              else
              {
            Console.WriteLine(program_usage("Incorrect number of arguments specified."));
            return;
              }

              // Determine Orientation
            if      (orientation == "North"   || orientation == "north")
              display_north = true;
            else if (orientation == "South"   || orientation == "south")
              display_south = true;
            else if (orientation == "East"    || orientation == "east")
              display_east  = true;
            else if (orientation == "West"    || orientation == "west")
              display_west  = true;
            else if (orientation == "Unknown" || orientation == "unknown")
            {
              display_north = true;
              display_east  = true;
              display_south = true;
              display_west  = true;
            }
            else
            {
              Console.WriteLine(program_usage("A valid orientation was not entered."));
              return;
            }

              if (!Constant.TESTING)  //Can turn on/off real code and test code
              {
            Xbee xb = new Xbee();
            xb.open();
            xb.enter_api_mode();

            SignalStrengthReceiver receiver;
            if (xb.get_valid_signal_strengths()[Constant.NUM_NODES] > 0)
            {
              receiver = new RelaySignalStrengthReceiver(xb);
            }
            else
            {
              receiver = new DirectSignalStrengthReceiver(xb);
            }

            uint[] avg_signals = new uint[8];

            avg_signals = receiver.get_avg_signal_strength(2, 200);

            if (display_north)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.North, avg_signals[i]));
            }
            if (display_south)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.South, avg_signals[i]));
            }
            if (display_east)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.East, avg_signals[i]));
            }
            if (display_west)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.West, avg_signals[i]));
            }
              }
              else
              {
            //Test Code
            if (display_north)
            {
              l.AddRange(loc.get_locations(0, Orientation.North, 55));
              l.AddRange(loc.get_locations(1, Orientation.North, 55));
              l.AddRange(loc.get_locations(2, Orientation.North, 55));
              l.AddRange(loc.get_locations(3, Orientation.North, 55));
            }
            if (display_south)
            {
              l.AddRange(loc.get_locations(0, Orientation.South, 60));
              l.AddRange(loc.get_locations(1, Orientation.South, 60));
              l.AddRange(loc.get_locations(2, Orientation.South, 60));
              l.AddRange(loc.get_locations(3, Orientation.South, 60));
            }
            if (display_east)
            {
              l.AddRange(loc.get_locations(0, Orientation.East, 71));
              l.AddRange(loc.get_locations(1, Orientation.East, 71));
              l.AddRange(loc.get_locations(2, Orientation.East, 71));
              l.AddRange(loc.get_locations(3, Orientation.East, 71));
            }
            if (display_west)
            {
              l.AddRange(loc.get_locations(0, Orientation.West, 59));
              l.AddRange(loc.get_locations(1, Orientation.West, 59));
              l.AddRange(loc.get_locations(2, Orientation.West, 59));
              l.AddRange(loc.get_locations(3, Orientation.West, 59));
            }
              }

              l.Sort();
              locations = l;

              List<Cluster> clusters = Clusterer.cluster(locations, diameter);
              List<PositionWithProb> loc_probs = new List<PositionWithProb>();
              for (int i = 0; i < clusters.Count; i++)
              {
            loc_probs.Add(new PositionWithProb(clusters[i].location, clusters[i].probability));
              }
              PositionWithProbComparer compaerer = new PositionWithProbComparer();
              loc_probs.Sort(compaerer);

              Console.WriteLine();
              Console.WriteLine("{0} {1, 16}", "Position", "Probability");
              Console.WriteLine("{0} {1, 13}", "-----------", "-----------");
              Console.WriteLine("{0, 4} {1, 5}", "X", "Y");
              for (int i = 0; i < clusters.Count; i++)
              {
            Console.WriteLine("{0, 4:0.00}, {1, 5:0.00}: {2, 9:0.000}%", loc_probs[i].location.x,
              loc_probs[i].location.y, loc_probs[i].probability * 100);
              }
        }
Ejemplo n.º 4
0
        private void run_test_on(uint[] sig_strs, List<Location> expected_clusters, List<Location>[, ,] locations, int dist_from_cent)
        {
            ArrayBasedLocations loc = new ArrayBasedLocations(locations);
              List<Location> pos_locs = new List<Location>();
              bool expected_matches_actual = true;

              for (int i = 0; i < sig_strs.Length; ++i)
              {
              pos_locs.AddRange(loc.get_locations(i, Orientation.North, sig_strs[i]));
              }
              pos_locs.Sort();

              List<Cluster> actual_clusters = Clusterer.cluster(pos_locs, dist_from_cent);

              int total_locations = 0;
              for (int i = 0; i < actual_clusters.Count; ++i)
              {
            total_locations += actual_clusters[i].locations.Count;
              }

              if (expected_clusters.Count != total_locations)
              {
            expected_matches_actual = false;
              }
              else
              {
            int count = 0;
            //System.Console.WriteLine("\nTest: num_signal_strengths = " + sig_strs.Length + ", dist_from_center = " + dist_from_cent);
            for (int i = 0; i < actual_clusters.Count; ++i)
            {
              //System.Console.WriteLine("");
              for (int j = 0; j < actual_clusters[i].locations.Count; ++j)
              {
            // Uncomment the 5 commented out lines of code to debug test case.  Prints "Actual Value(Expected Value)".
            //System.Console.Write(actual_clusters[i].locations[j].x + "," + actual_clusters[i].locations[j].y);
            //System.Console.Write("(" + expected_clusters[count].x + "," + expected_clusters[count].y + ") ");
            expected_matches_actual &= (actual_clusters[i].locations[j].Equals(expected_clusters[count]));
            count++;
              }
              //System.Console.WriteLine("");
            }
              }

            Specify.That(expected_matches_actual).ShouldBeTrue();
        }