示例#1
0
        public CellGroup getMaxSensors()
        {
            List <int> sensorsCount = new List <int>();

            foreach (CellGroup tempClus in changePosClus)
            {
                sensorsCount.Add(tempClus.clusterNodes.Count());
            }
            int maxCount = 0;

            foreach (int i in sensorsCount)
            {
                if (maxCount < i)
                {
                    maxCount = i;
                }
            }
            CellGroup foundMax = new CellGroup();

            foreach (CellGroup tempClus in changePosClus)
            {
                if (tempClus.clusterNodes.Count == maxCount)
                {
                    foundMax = tempClus;
                }
            }
            changePosClus.Clear();
            return(foundMax);
        }
示例#2
0
        public static CellGroup getClusterWithID(int findID)
        {
            CellGroup getCluster = new CellGroup();


            foreach (CellGroup findCluster in PublicParameters.networkCells)
            {
                if (findCluster.getID() == findID)
                {
                    // Console.WriteLine("Searching in {0}", findCluster.getID());
                    getCluster = findCluster;
                    //  Console.WriteLine("Returning");
                    return(findCluster);
                }
            }
            //   Console.WriteLine("Returned");
            // if (!foundCluster)
            //{
            //     throw new System.ArgumentException("Cluster not found", "original");
            //  }
            //  else
            // {
            return(getCluster);
            // }
        }
示例#3
0
        private void changeClusterPosition()
        {
            List <CellGroup> clusterList = PublicParameters.networkCells;
            double           avg         = CellGroup.getAverageSensors();

            for (int x = 0; x < clusterList.Count(); x++)
            {
                CellGroup oldCluster         = PublicParameters.networkCells[x];
                Point     oldClusterLocation = oldCluster.clusterLocMargin;

                int oldNodesCount = oldCluster.clusterNodes.Count;
                if (oldNodesCount < avg)
                {
                    //Consider changing the cluster
                    //Construct 8 clusters and compare between each of them
                    //Construct the 8 clusters by adding them to a temporary list in ReCheck
                    for (int i = 1; i <= 8; i++)
                    {
                        CellGroup tempCluster = new CellGroup(oldClusterLocation, oldCluster.getID());
                        //Console.WriteLine("Old Position X: {0} Y: {1}", tempCluster.clusterPoint.X, tempCluster.clusterPoint.Y);
                        tempCluster.incDecPos(i, (0.334));
                        // Console.WriteLine("New Position X: {0} Y: {1}", tempCluster.clusterPoint.X, tempCluster.clusterPoint.Y);
                        tempCluster.findNearestSensorRecheck(false);
                    }
                    CellGroup maxCluster = new CellGroup();
                    maxCluster = maxCluster.getMaxSensors();
                    maxCluster.findNearestSensorRecheck(true);
                }
            }
        }
示例#4
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        private void reBuildTree(int rootID)
        {
            int clusterCount = PublicParameters.networkCells.Count();

            startFromCluster(CellGroup.getClusterWithID(rootID), true);
            for (int i = 0; (BFSvisited.Count == 0) || (i < clusterCount - 1); i++)
            {
                if (BFSvisited.Count() > 0)
                {
                    CellGroup         parent      = BFSvisited.Dequeue();
                    Queue <CellGroup> childrenQue = new Queue <CellGroup>();// parent.childrenClusters;
                    foreach (CellGroup child in parent.childrenClusters)
                    {
                        childrenQue.Enqueue(child);
                    }
                    int childrenCount = childrenQue.Count();
                    for (int q = 0; q < childrenCount; q++)
                    {
                        startFromCluster(childrenQue.Dequeue(), false);
                    }
                }
                else
                {
                    break;
                }
            }
        }
示例#5
0
        private void removeSmallCells()
        {
            List <CellGroup> clusterList = PublicParameters.networkCells;

            getAfterAverage();
            double avg = AfterSmallAverage; // Math.Abs(Cluster.getAverageSensors());

            avg--;
            List <CellGroup> removeThese = new List <CellGroup>();

            for (int x = 0; x < clusterList.Count(); x++)
            {
                CellGroup oldCluster    = PublicParameters.networkCells[x];
                int       oldNodesCount = oldCluster.clusterNodes.Count;
                if (oldNodesCount < avg)
                {
                    //PublicParameters.networkClusters.Remove(oldCluster);
                    removeThese.Add(oldCluster);
                }
            }
            foreach (CellGroup clus in removeThese)
            {
                PublicParameters.networkCells.Remove(clus);
            }
        }
示例#6
0
        //Assign cluster IDs here

        private void addIdsToSensorA(CellGroup cluster)
        {
            foreach (Sensor sensor in cluster.getClusterNodes())
            {
                sensor.inCell = cluster.getID();
                //Console.WriteLine("Sensor {0} is in {1}", sensor.ID, cluster.getID());
            }
        }
示例#7
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        public void displayTree()
        {
            CellGroup root = CellGroup.getClusterWithID(rootClusterID);

            root.clusterLevel = 1;
            setLevel(root);
            saveLevels();
            //printLevels();
        }
示例#8
0
文件: Tree.xaml.cs 项目: howbani/Tuft
 public void setLevel(CellGroup node)
 {
     if (node.childrenClusters.Count > 0)
     {
         foreach (CellGroup child in node.childrenClusters)
         {
             child.clusterLevel = node.clusterLevel + 1;
             setLevel(child);
         }
     }
 }
示例#9
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        /*
         *  1- Start from cluster center or randomly select a number with the median as the mean
         *  2- Get the children and add their parents var, then add them to the cluster root's children list
         *  3- add the cluster to the tempClusterGroup
         *  4- add the rootCluster to the visited list
         *  5- take variables from the visited list and search the children variable
         *  6- if the clusters have children add them to BFS visited
         *  7- else set them as leafNode untill BFSVisited is empty
         */


        private void startFromCluster(CellGroup parent, bool isRoot)
        {
            double radius = PublicParameters.cellRadius;

            parent.isVisited = true;
            double offset = Math.Ceiling((radius + (radius / 2)));

            offset = Math.Sqrt(Math.Pow(offset, 2) + Math.Pow(offset, 2));
            if (isRoot)
            {
                parent.parentCluster   = null;
                rootCluster            = parent;
                rootClusterID          = parent.getID();
                MobileModel.rootTreeID = rootClusterID;
            }

            PublicParameters.currentNetworkTree.Add(parent);

            foreach (CellGroup child in PublicParameters.networkCells)
            {
                if (!child.isVisited)
                {
                    double distance = Operations.DistanceBetweenTwoPoints(parent.clusterActualCenter, child.clusterActualCenter);
                    // Console.WriteLine("Distance between {0} and {1} is {2}",  parent.getID(), child.getID(),distance);
                    //Think about the lines where x difference might be 0 if no change and less than half the radius if it changed its place
                    //Also for Y
                    if (distance <= offset)
                    {
                        //That means this cluster is a child so we add it and edit it's parent variable
                        child.parentCluster = parent;
                        child.isVisited     = true;
                        parent.childrenClusters.Add(child);
                    }
                }
            }
            if (parent.childrenClusters.Count() > 0)
            {
                parent.isLeafNode = false;
            }
            else
            {
                parent.isLeafNode = true;
            }

            BFSvisited.Enqueue(parent);
        }
示例#10
0
        private void buildFromCenter(Canvas Canvase_SensingFeild)
        {
            double canvasHeight = Canvase_SensingFeild.ActualHeight;
            double canvasWidth  = Canvase_SensingFeild.ActualWidth;

            CellGroup.getCenterOfNetwork();

            double radius = PublicParameters.cellRadius;

            Point networkCenter = PublicParameters.networkCenter;

            networkCenter.X -= radius / 2;
            networkCenter.Y -= radius / 2;
            double xAxesCount = Math.Floor(canvasWidth / (radius + (radius / 2)));
            double yAxesCount = Math.Floor(canvasHeight / (radius + (radius / 2)));
            double pyth       = Math.Sqrt((Math.Pow(canvasHeight, 2) + (Math.Pow(canvasWidth, 2))));

            pyth     = Math.Floor(pyth / (radius + (radius / 2)));
            assignID = 1;

            buildFromDirection("center", networkCenter, 1);
            buildFromDirection("right", networkCenter, xAxesCount / 2);
            buildFromDirection("left", networkCenter, xAxesCount / 2);
            buildFromDirection("up", networkCenter, yAxesCount / 2);
            buildFromDirection("down", networkCenter, yAxesCount / 2);
            buildFromDirection("upright", networkCenter, pyth / 2);
            buildFromDirection("upleft", networkCenter, pyth / 2);
            buildFromDirection("downright", networkCenter, pyth / 2);
            buildFromDirection("downleft", networkCenter, pyth / 2);

            buildUnderTop();
            // changeClusterPosition();
            removeSmallCells();

            addIdsToSensorFinal();

            addClustersToWindow(Canvase_SensingFeild);

            Tree tree = new Tree(Canvase_SensingFeild);

            tree.displayTree();

            initAssignHead();
            populateClusterTables();
        }
示例#11
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        /* private static void drawLines()
         * {
         *
         *   int i = 0;
         *   Queue<Cluster> visited = new Queue<Cluster>();
         *   Point start;
         *   Point finish;
         *
         *   start = rootCluster.clusterCenterComputed;
         *   foreach (Cluster child in rootCluster.childrenClusters)
         *   {
         *       finish = child.clusterCenterComputed;
         *       Line connection = new Line();
         *       connection.Stroke = Brushes.Black;
         *       connection.Fill = Brushes.Black;
         *
         *       connection.X1 = start.X;
         *       connection.Y1 = start.Y;
         *       connection.X2 = finish.X;
         *       connection.Y2 = finish.Y;
         *       sensingField.Children.Add(connection);
         *       visited.Enqueue(child);
         *
         *   }
         *
         *   do
         *   {
         *       i++;
         *       Cluster parent = visited.Dequeue();
         *       start = parent.clusterCenterComputed;
         *       foreach (Cluster child in parent.childrenClusters)
         *       {
         *           finish = child.clusterCenterComputed;
         *           Line connection = new Line();
         *           connection.Stroke = Brushes.Black;
         *           connection.Fill = Brushes.Black;
         *
         *           connection.X1 = start.X;
         *           connection.Y1 = start.Y;
         *           connection.X2 = finish.X;
         *           connection.Y2 = finish.Y;
         *           sensingField.Children.Add(connection);
         *           visited.Enqueue(child);
         *       }
         *   } while (visited.Count > 0);
         *
         *
         *
         * }
         *
         * private static void updateTree()
         * {
         *
         *
         *
         * }
         *
         * public static void showTree()
         * {
         *   Queue<Cluster> visitedNodes = new Queue<Cluster>();
         *   visitedNodes.Enqueue(Cluster.getClusterWithID(rootClusterID));
         *   Queue<Cluster> childNodes = new Queue<Cluster>();
         *   int level = 1;
         *   Cluster node;
         *   int previousParent = 1;
         *   for (int i = 0; i < PublicParamerters.networkClusters.Count(); i++)
         *   {
         *       if (visitedNodes.Count == 0)
         *       {
         *           break;
         *       }
         *       else
         *       {
         *
         *           node = visitedNodes.Dequeue();
         *           Tree tree = new Tree(node.getID(), level, node.childrenClusters.Count());
         *           foreach (Cluster child in node.childrenClusters)
         *           {
         *                   childNodes.Enqueue(child);
         *           }
         *
         *           if (previousParent != node.parentCluster.getID())
         *           {
         *               level++;
         *           }
         *
         *           if (childNodes.Count > 0)
         *           {
         *               visitedNodes.Enqueue(childNodes.Dequeue());
         *           }
         *           else
         *           {
         *               break;
         *           }
         *           if (previousParent != node.parentCluster.getID())
         *           {
         *               previousParent = node.getID();
         *           }
         *
         *
         *
         *
         *
         *       }
         *   }
         *
         *
         * }
         *
         * }
         */

        private void drawLines()
        {
            foreach (Level level in clusterLevels)
            {
                if (level.nodesCount > 0)
                {
                    foreach (CellGroup node in level.nodes)
                    {
                        if (node.getID() != rootClusterID)
                        {
                            CellGroup parent    = node.parentCluster;
                            Point     parentPos = getNode(parent).treeNodePos;
                            node.treeParentNodePos = parentPos;
                        }
                    }
                }
            }
            foreach (Level level in clusterLevels)
            {
                if (level.nodesCount > 0)
                {
                    foreach (CellGroup node in level.nodes)
                    {
                        if (node.getID() != rootClusterID)
                        {
                            Point parentPos = node.treeParentNodePos;
                            Point nodePos   = node.treeNodePos;
                            parentPos.X += 25 / 2;
                            parentPos.Y += 25;
                            nodePos.X   += 25 / 2;

                            Line connection = new Line();
                            connection.Stroke = Brushes.Black;
                            connection.Fill   = Brushes.Black;
                            connection.X1     = parentPos.X;
                            connection.Y1     = parentPos.Y;
                            connection.X2     = nodePos.X;
                            connection.Y2     = nodePos.Y;
                            stack_panel.Children.Add(connection);
                        }
                    }
                }
            }
        }
示例#12
0
        private static void getAfterAverage()
        {
            double avg = Math.Abs(CellGroup.getAverageSensors());

            avg -= 2;
            double i = 0;
            double y = 0;

            foreach (CellGroup cell in PublicParameters.networkCells)
            {
                double count = cell.clusterNodes.Count;
                if (count > avg)
                {
                    i += count;
                    y++;
                }
            }
            AfterSmallAverage = Convert.ToInt32(i / y);
            //AfterSmallAverage = Math.Abs(i);
        }
示例#13
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        private void setInitialXVal(CellGroup parent)
        {
            int numberofChildren = parent.childrenClusters.Count;
            int startX           = 0;

            if (numberofChildren > 0)
            {
                foreach (CellGroup child in parent.childrenClusters)
                {
                    child.xValue = startX;
                    startX++;
                    TreeQueueReingfold.Enqueue(child);
                }
            }

            if (TreeQueueReingfold.Count > 0)
            {
                setInitialXVal(TreeQueueReingfold.Dequeue());
            }
        }
示例#14
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        private static void changeRootChildren()
        {
            CellGroup root = CellGroup.getClusterWithID(rootClusterID);

            foreach (CellGroup linked in root.clusterLinks.hasLinkwith)
            {
                if (linked.parentCluster.getID() != rootClusterID)
                {
                    double offset   = PublicParameters.cellRadius + PublicParameters.cellRadius / 2;
                    double distance = Operations.DistanceBetweenTwoPoints(linked.clusterActualCenter, root.clusterActualCenter);
                    // if (distance <= offset)
                    //{
                    CellGroup oldParent = CellGroup.getClusterWithID(linked.parentCluster.getID());
                    CellGroup child     = CellGroup.getClusterWithID(linked.getID());
                    oldParent.childrenClusters.Remove(linked);
                    child.parentCluster = root;
                    root.childrenClusters.Add(linked);
                    //}
                }
            }
        }
示例#15
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        private static CellGroup getNode(CellGroup node)
        {
            CellGroup found = null;

            foreach (Level level in clusterLevels)
            {
                if (level.nodesCount > 0)
                {
                    foreach (CellGroup compareNode in level.nodes)
                    {
                        if (compareNode.getID() == node.getID())
                        {
                            found = compareNode;
                        }
                    }
                }
                else if (level.nodes[0].getID() == node.getID())
                {
                    found = level.nodes[0];
                }
            }
            return(found);
        }
示例#16
0
文件: Tree.xaml.cs 项目: howbani/Tuft
        public static void changeTree(int nearClusterID)
        {
            if (nearClusterID != rootClusterID)
            {
                // PublicParamerters.currentNetworkTree.clusterTree.Clear();
                // The near cluster will be come the new root
                CellGroup oldRoot = CellGroup.getClusterWithID(rootClusterID);
                CellGroup newRoot = CellGroup.getClusterWithID(nearClusterID);
                // oldRoot.clusterHeader.headerSensor.ClusterHeader.SinkAgent = null;
                //Edit the old root cluster's children & parent
                oldRoot.parentCluster = newRoot;
                oldRoot.childrenClusters.Remove(newRoot);
                //Edit the new root cluster's children & parent
                newRoot.parentCluster = null;
                newRoot.childrenClusters.Add(oldRoot);
                rootCluster            = newRoot;
                rootClusterID          = newRoot.getID();
                MobileModel.rootTreeID = rootClusterID;
                changeRootChildren();
                //Here we need to send to all the new headers the new parametrs in it
                // oldRoot.clusterHeader.headerSensor.CellHeader.hasSinkPosition = false;
                // oldRoot.clusterHeader.headerSensor.CellHeader.isRootHeader = false;
                // oldRoot.clusterHeader.headerSensor.CellHeader.ClearBuffer();

                oldRoot.CellTable.CellHeader.TuftNodeTable.CellHeaderTable.hasSinkPosition = false;
                oldRoot.CellTable.CellHeader.TuftNodeTable.CellHeaderTable.isRootHeader    = false;
                oldRoot.CellTable.CellHeader.ClearCellHeaderBuffer();

                newRoot.CellTable.CellHeader.TuftNodeTable.CellHeaderTable.hasSinkPosition = false;
                newRoot.CellTable.CellHeader.TuftNodeTable.CellHeaderTable.SinkAgent       = null;
                newRoot.CellTable.CellHeader.TuftNodeTable.CellHeaderTable.isRootHeader    = true;
                // newRoot.CellTable.CellHeader.GenerateTreeChange(oldRoot.CellTable.CellHeader);

                CellFunctions.ChangeTreeLevels();
            }
        }
示例#17
0
        private void buildFromDirection(String direction, Point startFrom, double count)
        {
            switch (direction)
            {
            case "center":

                CellGroup cluster = new CellGroup(startFrom, assignID);
                cluster.findNearestSensor(false);
                if (cluster.isNotEmpty())
                {
                    addIdsToSensorA(cluster);
                    assignID++;
                }

                break;

            case "right":
                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster0 = new CellGroup(startFrom, assignID);
                    cluster0.incDecPos(1, i + 1);
                    cluster0.findNearestSensor(true);
                    if (cluster0.isNotEmpty())
                    {
                        //ui.MainWindow.net
                        cluster0.findNearestSensor(false);
                        addIdsToSensorA(cluster0);
                        assignID++;
                    }
                }
                break;

            case "left":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster1 = new CellGroup(startFrom, assignID);
                    cluster1.incDecPos(2, i + 1);
                    cluster1.findNearestSensor(true);
                    if (cluster1.isNotEmpty())
                    {
                        cluster1.findNearestSensor(false);
                        addIdsToSensorA(cluster1);
                        assignID++;
                    }
                }
                break;

            case "up":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster2 = new CellGroup(startFrom, assignID);
                    cluster2.incDecPos(3, i + 1);
                    cluster2.findNearestSensor(true);
                    if (cluster2.isNotEmpty())
                    {
                        cluster2.findNearestSensor(false);
                        addIdsToSensorA(cluster2);
                        assignID++;
                    }
                }
                break;

            case "down":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster3 = new CellGroup(startFrom, assignID);
                    cluster3.incDecPos(4, i + 1);
                    cluster3.findNearestSensor(true);
                    if (cluster3.isNotEmpty())
                    {
                        cluster3.findNearestSensor(false);
                        addIdsToSensorA(cluster3);
                        assignID++;
                    }
                }
                break;

            case "upright":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster4 = new CellGroup(startFrom, assignID);
                    cluster4.incDecPos(5, i + 1);
                    cluster4.findNearestSensor(true);
                    if (cluster4.isNotEmpty())
                    {
                        cluster4.buildClustersunderTop = i + 1;
                        cluster4.findNearestSensor(false);
                        addIdsToSensorA(cluster4);
                        assignID++;
                    }
                }
                break;

            case "downleft":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster5 = new CellGroup(startFrom, assignID);
                    cluster5.incDecPos(6, i + 1);
                    cluster5.findNearestSensor(true);
                    if (cluster5.isNotEmpty())
                    {
                        cluster5.buildClustersunderTop = i + 1;
                        cluster5.findNearestSensor(false);
                        addIdsToSensorA(cluster5);
                        assignID++;
                    }
                }

                break;

            case "upleft":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster6 = new CellGroup(startFrom, assignID);
                    cluster6.incDecPos(7, i + 1);
                    cluster6.findNearestSensor(true);
                    if (cluster6.isNotEmpty())
                    {
                        cluster6.buildClustersunderTop = i + 1;
                        cluster6.findNearestSensor(false);
                        addIdsToSensorA(cluster6);
                        assignID++;
                    }
                }
                break;

            case "downright":

                for (int i = 0; i < count; i++)
                {
                    CellGroup cluster7 = new CellGroup(startFrom, assignID);
                    cluster7.incDecPos(8, i + 1);
                    cluster7.findNearestSensor(true);
                    if (cluster7.isNotEmpty())
                    {
                        cluster7.buildClustersunderTop = i + 1;
                        cluster7.findNearestSensor(false);
                        addIdsToSensorA(cluster7);
                        assignID++;
                    }
                }
                break;
            }
        }