Exemplo n.º 1
0
 public DeviceModel(DeviceModel d)
 {
     Id = d.Id;
     Mac = d.Mac;
     Name = d.Name;
     XLocation = d.XLocation;
     YLocation = d.YLocation;
     RSSValue = d.RSSValue;
     Property = new PropertyModel(d.Property);
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {

            Manager _manager = new WifiLocalization.Manager();
            DeviceModel User = new DeviceModel();
            List<LocationModel> OfflineMapList = new List<LocationModel>();
            string xlPath = "C:/Users/Tarek/Desktop/ResearchLab_Database_6x7.xls";

            for (int i = 1; i <= 2; i++)
            {
                LocationModel Offline = new LocationModel();

                Offline.XValue = Helper.ObjectToDouble(_manager.ReadOfflineDB(xlPath, i, "K4:K45"));
                Offline.YValue = Helper.ObjectToDouble(_manager.ReadOfflineDB(xlPath, i, "L4:L45"));

                char ch = 'B';
                for (int j = 1; j <= 5; j++)
                {
                    Offline.RSSValueList.Add(Helper.ObjectToDouble(_manager.ReadOfflineDB(xlPath, i, ch + "4:" + ch++ + "45")));
                }

                OfflineMapList.Add(Offline);
            }


            User.Mac = "AA:BB:CC:DD";
            User.Name = "TestUser";
            User.Property.KNN = 3;
            User.Property.Threshold = 1;
            User.Property.Exponent = 2;

            User.RSSValue = new double[OfflineMapList[0].RSSValueList.Count()];
            for (int i = 0; i < OfflineMapList[0].RSSValueList.Count(); i++)
            {
                User.RSSValue[i] = OfflineMapList[0].RSSValueList[i][0];                
            }

            User.GetLocation(OfflineMapList[0]);

            double[] u1 = new double[] { };
            double[] u2 = new double[] { };
            
            User.GetStatistics(Helper.Magnitude(u1, u2),
                Helper.Magnitude(OfflineMapList[0].XValue, OfflineMapList[0].YValue));

            User.DisplayInfo();
            User.Property.DisplayInfo();
            //user.GetLocation();
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public DeviceModel KNearestNeighbor(DeviceModel user, LocationModel Offline)
        {
            Dictionary<int, Double> dist = new Dictionary<int, double>();
            List<Double[]> ap = Offline.RSSValueList;
            Double[] us = user.RSSValue;
            int knn = user.Property.KNN;
            int exp = user.Property.Exponent;
            int uNum = us.Length;
            int apNum = ap.Count();
            int locNum = ap[0].Length;
            double sum;
            double invExp = 1 / (double)exp;
             


            for (int j = 0; j < locNum; j++)
            {
                sum = 0;

                for (int i = 0; i < apNum; i++)
                {
                    sum += Math.Pow(us[i] - ap[i][j], exp);

                }

                dist.Add(j, Math.Pow(sum, invExp));
            }

            var results = dist.OrderBy(i => i.Value).Take(knn);

            double x = 0, y = 0;
            foreach (KeyValuePair<int, double> result in results)
            {
                x += Offline.XValue[result.Key];
                y += Offline.YValue[result.Key];

            }
            
            DeviceModel KNNResult = new DeviceModel(user);

            KNNResult.XLocation = x / knn;
            KNNResult.YLocation = y / knn;

            return KNNResult;
        }
Exemplo n.º 4
0
        public DeviceModel KNearestNeighbor(DeviceModel user, LocationModel Offline)
        {
            Dictionary <int, Double> dist = new Dictionary <int, double>();
            List <Double[]>          ap   = Offline.RSSValueList;

            Double[] us     = user.RSSValue;
            int      knn    = user.Property.KNN;
            int      exp    = user.Property.Exponent;
            int      uNum   = us.Length;
            int      apNum  = ap.Count();
            int      locNum = ap[0].Length;
            double   sum;
            double   invExp = 1 / (double)exp;



            for (int j = 0; j < locNum; j++)
            {
                sum = 0;

                for (int i = 0; i < apNum; i++)
                {
                    sum += Math.Pow(us[i] - ap[i][j], exp);
                }

                dist.Add(j, Math.Pow(sum, invExp));
            }

            var results = dist.OrderBy(i => i.Value).Take(knn);

            double x = 0, y = 0;

            foreach (KeyValuePair <int, double> result in results)
            {
                x += Offline.XValue[result.Key];
                y += Offline.YValue[result.Key];
            }

            DeviceModel KNNResult = new DeviceModel(user);

            KNNResult.XLocation = x / knn;
            KNNResult.YLocation = y / knn;

            return(KNNResult);
        }
Exemplo n.º 5
0
 private DeviceModel WKNearestNeighbor(DeviceModel user, LocationModel offline)
 {
     return WifiLocalization.Implement.Instance.WKNearestNeighbor();
 }
Exemplo n.º 6
0
 public DeviceModel GetLocation(DeviceModel user, LocationModel offline)
 {
     return KNearestNeighbor(user, offline);
     // return WKNearestNeighbor(user, offline);
 }