دانلود پایان نامه ارشد با موضوع “، this.currentCH، double

دانلود پایان نامه ارشد

“Receive a ACK_CLUSTER_PACKET from ” + spkt.getSrc_nid() + ” in ” + this.nid + ” at time” + getTime());
* sendGet = false;
* this.currentCH = spkt.getSrc_nid();
* addRoute(this.nid,this.currentCH,-1);
* return;
* }
*
* if (spkt.getPktType() == ACK_SCH_PACKET) {
* System.out.println(“Receive a ACK_SCH_PACKET from ” + spkt.getSrc_nid() + ” in ” + this.nid + ” at time” + getTime());
* for(int i = 0 ; i* if(((neighbor)joinedList.get(i)).getNid() == spkt.getSrc_nid()){
* ((neighbor)joinedList.get(i)).setAck(1);
* }
* }
* this.currentCH = spkt.getSrc_nid();
* addRoute(this.nid,this.currentCH,-1);
* return;
* }
* if (spkt.getPktType() == YOU_CLUSTER_PCKET) {
* LaClusteringPacket msg = (LaClusteringPacket)spkt.getBody();
* System.out.println(“Receive a YOU_CLUSTER_PCKET from ” + spkt.getSrc_nid() + ” in ” + this.nid);
* if(!isch_){
* laClustering.setState(1);
* this.currentCH = this.nid;
* this.CHloc = this.myPos;
* isch_ = true;
* LaClusteringApp.CHinfo ch_ = new LaClusteringApp.CHinfo(this.nid, 0, this.myPos,0,4);
* clusterChoices.add(ch_);
* this.sendState();
* }
* return;
* }
* if (spkt.getPktType() == SCH_CLUSTER_PACKET) {
* LaClusteringSchPacket msg = (LaClusteringSchPacket)spkt.getBody();
* if ((msg.getchID() == this.currentCH) || ((msg.getPreChID() == this.currentCH))) {
* if(msg.getchID() != msg.getPreChID()){
* if((sendGet) && (msg.getPreChID() == this.nid)){
* sendGet = false;
* }
* this.currentCH = spkt.getSrc_nid();
* addRoute(this.nid,this.currentCH,-1);
* this.GoToSleep();
* }
* else
* this.recvADV_SCH(msg);
* }
* return;
* }
* return;
* } else {
* super.recvSensorPacket(data_) ;
* }
* }
* /*************************** Steady State ***********************************************/
* /******************************************************************************************/
* boolean hasCluster(){
* for(int i=0; i < neighbors.size() ; i++){
* if(((neighbor)neighbors.get(i)).getState() == 1 || ((neighbor)neighbors.get(i)).getState() == 4){
* return true;
* }
* }
* return false;
* }
* /********************************************************************************************/
* public int maxNeighborIndex(){
* int max = neighborCounts;
* int index = -1;
* for(int i=0; i < neighbors.size() ; i++){
* if(((neighbor)neighbors.get(i)).getNeighborCounts() > max){
* max = ((neighbor)neighbors.get(i)).getNeighborCounts();
* index = i;
* }
* }
* return index;
* }
* public void startSteadyState(){
* laClustering.setSteady(0);
* steady_state = true;
* if (lTimer != null)
* cancelTimeout(lTimer);
* if (vTimer != null)
* cancelTimeout(vTimer);
* if(laClustering.getState() == 1){
* this.isch_ = true;
* }
* if(laClustering.getState() == 4){
* this.isch_ = true;
* }
* if(laClustering.getState() == 0){
* if(!hasCluster()){
* setTimeout(“setCluster” , generator.nextDouble() );
* }
* }
* setTimeout(“startSteadyState2”, 1.5);
* }
* /********************************************************************************************/
* public void setCluster(){
* if(!hasCluster()){
* int maxIndex = maxNeighborIndex();
* if(maxIndex = 0){
* this.currentCH = ((neighbor)neighbors.get(maxIndex)).getNid();
* this.isch_ = false;
* this.CHloc = ((neighbor)neighbors.get(maxIndex)).getloc();
* double distance = this.distance(this.getX(),this.CHloc[0],this.getY(),this.CHloc[1]);
* LaClusteringApp.CHinfo ch_ = new LaClusteringApp.CHinfo(this.currentCH, distance, this.CHloc,0,4);
* clusterChoices.add(ch_);
* addRoute(this.nid,this.currentCH,-1);
* System.out.println(” Sensor”+ this.nid + ” Sending YOU_CLUSTER_PCKET to ” + this.currentCH);
* int datasize = -58;
* LaClusteringPacket newPacket = new LaClusteringPacket(this.nid, this.myPos, datasize, laClustering.getState(), getEnergy());
* if (!(this.sensorDEAD)) {
* downPort.doSending(new SensorAppWirelessAgentContract.Message(SensorAppWirelessAgentContract.UNICAST_SENSOR_PACKET, this.currentCH, this.nid, this.CHloc, dataSize, YOU_CLUSTER_PCKET, eID, ((SensorAppAgentContract.Message)phenomenon).getTargetNid(), newPacket));
* eID = eID + 1; //every message sent is associated with an event ID
* } else {
* System.out.println(“Sensor”+this.nid+” Trying to forward a packet but im dead!”);
* dropped_packets ++;
* }
* }
* else{
* laClustering.setState(1);
* this.currentCH = this.nid;
* this.CHloc = this.myPos;
* isch_ = true;
* this.sendState();
* }
* }
* }
* /********************************************************************************************/
* public void startSteadyState2(){
* if(laClustering.getState() == 1 || laClustering.getState() == 4) {
* isch_ = true;
* }
* else{
* isch_ = false;
* }
* laClustering.setFirstProbCH(firstProbCH);
* memCount = joinedNodes.size();
* startFindTimer = setTimeout(“startFind_timer”, 1);
* }
* /********************************************************************************************/
* public synchronized void findBestCluster()
* {
* long temp_ID;
* double temp_distance;
* double min_distance = 100000;
*
* setupStartTime = getTime();
* if (this.isClusterHead()) {
* this.currentCH = this.nid;
* System.out.println(“Sensor”+this.nid+ ” Current Cluster head is Sensor”+this.currentCH);
* double scheduleTime = (3 + (generator.nextDouble()));
* setTimeout(“createSchedule”, scheduleTime);
* CHData.clear();
* } else {
* if(!hasCluster()) {
* System.out.println(“Sensor”+this.nid+ “: Warning No Cluster Head ADVs were heard at time: “+getTime());
* this.isch_ = true;
* this.currentCH = this.nid;
* double scheduleTime = (3 + (generator.nextDouble()));
* setTimeout(“createSchedule”, scheduleTime);
* CHData.clear();
* return;
* }
* for (int i = 0; i neighbors.size(); i ++ ) {
* if(((neighbor)neighbors.get(i)).getState()==1 || ((neighbor)neighbors.get(i)).getState()==4){
* temp_ID = ((neighbor)neighbors.get(i)).getNid();
* temp_distance = this.EuclideanDist(this.getX(), this.getY(), this.getZ(),((neighbor)neighbors.get(i)).getloc()[0],((neighbor)neighbors.get(i)).getloc()[1], 0);
* if (temp_distance min_distance) {
* min_distance = temp_distance;
* this.currentCH = temp_ID; //store its ID
* this.CHloc = ((neighbor)neighbors.get(i)).getloc(); //store its position
* }
* }
* }//end for
* this.dist_ = min_distance; //update state variable
* System.out.println(“Sensor”+this.nid+ ” Current Cluster head is Sensor” + this.currentCH + ” whose distance is: ” + this.dist_);
* double random_access = generator.nextDouble()*1.9;
* iTimer = setTimeout(“inforCmlusterHead”, random_access);
* setTimeout(“recvADV”, 4);
* }
* return;
* }
* /********************************************************************************************/
* public synchronized void informClusterHead()
* {
* addRoute(this.nid,this.currentCH,-1);
* LaClusteringJoinPacket newPacket = new LaClusteringJoinPacket(this.nid, this.currentCH,this.myPos , getEnergy());
* if (!(this.sensorDEAD)) {
* downPort.doSending(new SensorAppWirelessAgentContract.Message(SensorAppWirelessAgentContract.UNICAST_SENSOR_PACKET, this.currentCH, this.nid, this.CHloc, dataSize, JOIN_CLUSTER_PCKET, eID, ((SensorAppAgentContract.Message)phenomenon).getTargetNid(), newPacket));
* eID = eID + 1; //every message sent is associated with an event ID
* } else {
* System.out.println(“Sensor”+this.nid+” Trying to forward a packet but im dead!”);
* dropped_packets ++;
* }
* return;
* }
* /********************************************************************************************/
* protected void processNextHopPacket(LaClusteringNextHopPacket msg){
* CHinfo nextHop;
* LaClusteringNextHopPacket newPacket;
* double[] senderLoc = msg.getLoc();
* switch(msg.getOp()){
* case 1: //send state at first
* if(distance(getX(), senderLoc[0] , getY() , senderLoc[1]) clusterHop * this.radiusTransmit){
* System.out.println(“Receive a NEXTHOP_CLUSTER_PACKET from ” + msg.getchID() + ” in ” + this.nid + ” at time” + getTime() + ” $ OP = ” + msg.getOp());
* if(distance(getX(), sinkPos[0] , getY() , sinkPos[1]) distance(senderLoc[0] , sinkPos[0] ,

پایان نامه
Previous Entries دانلود پایان نامه ارشد با موضوع /********************************************************************************************/، public، -1; Next Entries منبع پایان نامه درباره اعتبار برند، قصد خرید مجدد، خرید مجدد