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); } } }
//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()); } }
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); }
/* * 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); }
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(); } }