Esempio n. 1
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();
        }
Esempio 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();
        }
Esempio 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;
        }
Esempio 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);
        }
Esempio n. 5
0
        public LocationModel LocalizationAlgorithm(List <LocationModel> online, List <LocationModel> offlineList)
        {
            List <LocationModel> data          = MinimumDistance(online, offlineList);
            List <LocationModel> sorted        = new List <LocationModel>();
            List <LocationModel> methodsOutput = new List <LocationModel>();

            var sortedData = data.OrderBy(x => x.RSSI);

            foreach (var sd in sortedData)
            {
                sorted.Add(sd);
            }

            methodsOutput.Add(sorted.First());
            LocationModel KNN = new LocationModel();
            LocationModel WKNN = new LocationModel();
            int           k = 0;
            double        W_d = 0;
            double        knn_x = 0, knn_y = 0;
            double        wknn_x = 0, wknn_y = 0;

            var list = sorted.Take(K);

            foreach (var item in list)
            {
                knn_x  += item.X;
                knn_y  += item.Y;
                wknn_x += (item.X / item.RSSI);
                wknn_y += (item.Y / item.RSSI);
                W_d    += (1 / item.RSSI);
                k++;
            }
            KNN.X = knn_x / K;
            KNN.Y = knn_y / K;
            methodsOutput.Add(KNN);
            WKNN.X = wknn_x / W_d;
            WKNN.Y = wknn_y / W_d;
            methodsOutput.Add(WKNN);


            return(FuzzyMethod(methodsOutput, offlineList));
        }
Esempio n. 6
0
 private DeviceModel WKNearestNeighbor(DeviceModel user, LocationModel offline)
 {
     return WifiLocalization.Implement.Instance.WKNearestNeighbor();
 }
Esempio n. 7
0
 public DeviceModel GetLocation(DeviceModel user, LocationModel offline)
 {
     return KNearestNeighbor(user, offline);
     // return WKNearestNeighbor(user, offline);
 }
Esempio n. 8
0
 public LocationModel(LocationModel l)
 {
     XValue       = l.XValue;
     YValue       = l.YValue;
     RSSValueList = Copy(l.RSSValueList);
 }
Esempio n. 9
0
 public LocationModel(LocationModel l)
 {
     XValue = l.XValue;
     YValue = l.YValue;
     RSSValueList = Copy(l.RSSValueList);
 }
Esempio n. 10
0
 public void GetLocation(LocationModel model)
 {
     var temp = WifiLocalization.Manager.Instance.GetLocation(this, model);
     XLocation = temp.XLocation;
     YLocation = temp.YLocation;
 }