Esempio n. 1
0
void Node::PacketGenerating(int time){//节点是否产生数据包,以及能量消耗
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}
	double pos = (double) (rand() + 1) / (double)RAND_MAX;
	if(time % SENSE_DURATION == 1){//因为是从第一秒开始计算的么
		if(pos <= POSIBILITY_PACKET_GENERATING){//产生数据包
			bufferedPackets.push(Packet(id, MAX_TIME));
		}
		if(currentWorkState == Sleeping){
			return;
		}
		
		int i = 0;
		while(!bufferedPackets.empty() && i < MAX_PACKETS_PER_SLOT){
			//RoutingWithBufferedPackets();
			bufferedPackets.pop();
			++i;
		}
		if(bufferedPackets.empty() && currentState == NonGatewayNode){
			pos = (double) (rand() + 1) / (double)RAND_MAX;
			if(pos <= POSIBILITY_PACKET_GENERATING){
				currentWorkState = Sleeping;
				workingTime = 0;
				relaxingTime = 0;
			}
		}
	}
}
void CmpMemoryMonitor::setLogFilename(const char *logFilename)
{
  if(logFilename) 
  {
    // Clean up file name and stream since we are changing the 
    // output filename.
    fileCleanUp();

    setIsMemMonitor(TRUE);

    logFilename_ = new(heap_) char[strlen(logFilename)+1];
    strcpy(logFilename_, logFilename);
    // Initialize the log file and write appropriate headers.
    ofstream outLogFile(logFilename_);
    outLogFile.width(19); outLogFile << "";
    outLogFile << "Memory Usage Information for SQL/MX Compiler" << endl;
    outLogFile.width(23); outLogFile << "" << "  ";
    outLogFile.width(11); outLogFile << "StmtH Alloc" << " ";
    outLogFile.width(15); outLogFile << "StmtH HgWtrMark" << " ";
    outLogFile.width(11); outLogFile << "CxtH Alloc" << " ";
    outLogFile.width(15); outLogFile << "CxtH HgWtrMark" << endl;
    outLogFile.close();

    // Now open the file stream to append memery usage data as we get it.
    logFilestream_ = new(heap_) ofstream(logFilename_, ios::app);
  }
}
Esempio n. 3
0
bool Node::ForcedSleep(){
	assert(currentWorkState == Receiving);
	//assert(relaxingTime == 0);
	if(currentState == GatewayNode){
		
		//如果gateway节点,要导致邻居节点重新选择啦
		for(size_t i = 0; i < neighbors.size(); ++i){
			if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == NonGatewayNode){
				//
				/*if(!nodes[neighbors[i]]->routingTable.size()){
					nodes[neighbors[i]]->UpdateRoutingTable();
				}*/
				assert(nodes[neighbors[i]]->routingTable.size());
				
				if(nodes[neighbors[i]]->routingTable[0].destination != id && nodes[nodes[neighbors[i]]->routingTable[0].destination]->GetNodeWorkState() == Receiving){
					continue;
					//这个邻居节点本来就不用自己来转发节点,自己睡不睡,人家一点都不关心
				}
				double bestGatewayNodeCondition = 0.0;
				RoutingEntry entry;
				for(size_t j = 0; j < nodes[neighbors[i]]->GetNeighbors().size(); ++j){
					if(nodes[ nodes[neighbors[i]]->GetNeighbors()[j]]->IsGatewayNodeOrNot() == GatewayNode
						&&nodes[ nodes[neighbors[i]]->GetNeighbors()[j]]->GetId() != id
						&& nodes[nodes[neighbors[i]]->GetNeighbors()[j]]->GetNodeWorkState() == Receiving){
						if(nodes[nodes[neighbors[i]]->GetNeighbors()[j]]->GetBattery()->GetEnergyGrade() > bestGatewayNodeCondition){
							bestGatewayNodeCondition = nodes[nodes[neighbors[i]]->GetNeighbors()[j]]->GetBattery()->GetEnergyGrade();//暂时就先选择一个吧
							entry.destination = nodes[neighbors[i]]->GetNeighbors()[j];
							entry.nextHop = entry.destination;
							entry.distance = 1;
						}
				
					}
				}
				if(bestGatewayNodeCondition == double(0)){
					
					ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
					assert(!outLogFile.fail());
					outLogFile<<__TIME__<<"NonGateway节点"<<neighbors[i]<< "在邻居节点"<<id<<" Sleep后孤立"<<endl;
					outLogFile.close();
					return false;//有一个节点是不连通,fail to get a dominating set,网络瘫痪
				}else{
					if(routingTable.size()){
						routingTable[0].destination = entry.destination;
						routingTable[0].nextHop = entry.nextHop;
					}else{
						routingTable.push_back(entry);
					}
				}
			}
			//else情况下,可能发生的情况是:
			//邻居的gateway节点可能需要当前节点转发消息,可是当前节点处于睡眠状态,不能参与转发,其他没有妨碍吧
		}
	}
	//else情况下,在实际的网络中,节点在睡之前通知一下邻居节点,使得邻居节点在进行状态抉择的时候不要把自己忘记啦
	//节点在sleep阶段错过的消息,会在节点醒来的时候,重新收集一下
	return true;
}
Esempio n. 4
0
void Node::MakeSureIsGatewayNodeOrNot(){//确定自己是否是gateway node,只是初步确定而已
	assert(currentWorkState == Receiving);
	//assert(relaxingTime == 0);
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}
	if(neighbors.size() == 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<< "孤立"<<endl;
		outLogFile.close();
		return;//有一个节点是不连通,fail to get a dominating set,网络瘫痪
	}
	if(neighbors.size() == 1){//即使这个唯一的邻居已经是gateway节点啦,可以在furtherdecision中进行比较选择比较合理的一个
		currentState = GatewayNode;
		return;
	}
	currentState = NonGatewayNode;	
	for(size_t i = 0; i < neighbors.size(); ++i){//Node 0是sink节点,我们约定sink节点
		size_t j = 0;
		for(; j < neighbors.size(); ++j){
			if(neighbors[i] == neighbors[j]){
				continue;
			}
			if(DIS(nodes[neighbors[i]]->GetXLoc(), nodes[neighbors[i]]->GetYLoc(),nodes[neighbors[j]]->GetXLoc(), nodes[neighbors[j]]->GetYLoc()) >= nodes[neighbors[i]]->GetTransDis()){
				//实现通信距离的不对称, 如果该节点的两个节点没有直接通信,则该节点就应该标记为gateway node
				currentState = GatewayNode;
				break;
			}
		}
		if(j < neighbors.size()){
			break;
		}
	}
}
Esempio n. 5
0
void Node::AddTime(){//增加距离上次作为gateway node工作的休息时间,
	if(id == 0){
		workingTime++;
		totalWorkTime++;
		return;//作为sink节点,要一直工作
	}
	switch(currentWorkState){
	case Receiving:
		workingTime++;
		totalWorkTime++;
		if(currentState == NonGatewayNode && workingTime >= MAX_WORK_TIME){
			//导致其他的邻居
			/*if(ForcedSleep()){
				currentWorkState = Sleeping;
				currentState = WhoKnows;
				//在睡着之前给所有的邻居节点发送信息。
			
				relaxingTime = 0;
				workingTime = 0;
			}
			*/
			currentWorkState = Sleeping;
			currentState = WhoKnows;
			//在睡着之前给所有的邻居节点发送信息。
			
			relaxingTime = 0;
			workingTime = 0;
		}
		
		break;
	case Sleeping:
		relaxingTime++;
		if(relaxingTime >= THRESHOLD){
			//确定需不需要醒过过来
			relaxingTime = 0;
			workingTime = 0;
			currentWorkState = Receiving;
			WakeupAfterSleep();
		}
		break;
	default:
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"CurrentWorkStatus Error"<<endl;
		outLogFile.close();
	}
}
Esempio n. 6
0
void Node::Routing(){//路由,确定数据包在路由阶段经过哪些节点,相应节点就需要能量减少
	if(currentWorkState == Sleeping){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"处于睡眠状态怎么能路由呢><"<<endl;
		outLogFile.close();
		return;
	}
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}
	allNodesOfForwardedPacket.push(id);
	allNodesOfForwardedPacket.push(-1);
	Node* currentNode = NULL;
	while(allNodesOfForwardedPacket.front() != -1){
		if(hop > MAX_TIME){
			//TTL expired
			ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
			assert(!outLogFile.fail());
			outLogFile<<__TIME__<<"数据包TTL过期"<<id<<endl;
			outLogFile.close();
			return;
		}
		currentNode = nodes[allNodesOfForwardedPacket.front()];
		//currentNode->SetNodeWorkStatus(Receiving);
		assert(currentNode->GetNodeWorkState() == Receiving);
		size_t i = 0;
		size_t j = 0;
		for(i = 0; i < currentNode->domainMembers.size(); ++i){
			if(currentNode->GetDomainMembers()[i] == 0){//暂定sink节点Id为0
				//找到该sink节点
				//nodes[currentNode->domainMembers[i]]->AddEnergy( -(SEND_PACKET_ENERGY + RECEIVE_PACKET_ENERGY));
				nodes[0]->AddEnergy( -(RECEIVE_PACKET_ENERGY));
				break;
			}
		}
		if(i == currentNode->domainMembers.size()){
			for(i = 0; i < currentNode->routingTable.size(); ++i){
				j = 0;
				for(; j < nodes[currentNode->routingTable[i].destination]->GetDomainMembers().size(); ++j){
					if(nodes[currentNode->routingTable[i].destination]->GetDomainMembers()[j] == 0){//暂定sink节点Id为0
						//找到该sink节点
						if(currentNode->routingTable[i].destination == currentNode->routingTable[i].nextHop){
							nodes[currentNode->routingTable[i].destination]->AddEnergy( -(SEND_PACKET_ENERGY + RECEIVE_PACKET_ENERGY));
							nodes[0]->AddEnergy( -(RECEIVE_PACKET_ENERGY));
						}else{
							nodes[currentNode->routingTable[i].nextHop]->AddEnergy( -(SEND_PACKET_ENERGY + RECEIVE_PACKET_ENERGY));
							allNodesOfForwardedPacket.push(currentNode->routingTable[i].nextHop);
						}
						
						break;
					}
				}
				if(j < nodes[currentNode->routingTable[i].destination]->GetDomainMembers().size()){
					break;
				}	
			}
			if(i == currentNode->routingTable.size()){//没有现成的路由,只有广播啦啦
				for(size_t m = 0; m < currentNode->routingTable.size(); ++m){
					if(currentNode->routingTable[m].distance == 1){//当然只广播一跳的邻居啦
						allNodesOfForwardedPacket.push(currentNode->routingTable[m].destination);
						nodes[currentNode->routingTable[m].destination]->AddEnergy( -(SEND_PACKET_ENERGY + RECEIVE_PACKET_ENERGY));
					}
				}
			}
		}
		allNodesOfForwardedPacket.pop();
		if(allNodesOfForwardedPacket.front() == -1){
			++hop;
			allNodesOfForwardedPacket.pop();
			allNodesOfForwardedPacket.push(-1);
		}
	}
}
Esempio n. 7
0
void Node::RoutingWithBufferedPackets(){
	
	assert(bufferedPackets.size());
	
	assert(currentWorkState == Receiving);
	if(currentWorkState == Sleeping){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"处于睡眠状态怎么能路由呢,一定是哪里弄错了><"<<endl;
		outLogFile.close();
		return;
	}
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池都耗尽啦,还路由什么啊><"<<endl;
		outLogFile.close();
		return;
	}
	if(bufferedPackets.empty()){
		return;//No Packets in the queue
	}
	--(bufferedPackets.front().TTL);
	if(bufferedPackets.front().TTL >= 0){
		if(id == 0){
			assert(bufferedPackets.size());
			bufferedPackets.pop();
			return;
		}
		if(currentState == NonGatewayNode){
			if(!routingTable.size() || nodes[routingTable[0].nextHop]->GetNodeWorkState() == Sleeping){
				double bestGatewayNodeCondition = 0.0;
				RoutingEntry entry;
				for(size_t i = 0; i < neighbors.size(); ++i){
					if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode 
						&& nodes[neighbors[i]]->GetNodeWorkState() == Receiving){
						if(nodes[neighbors[i]]->GetBattery()->GetEnergyGrade() > bestGatewayNodeCondition){
							bestGatewayNodeCondition = nodes[neighbors[i]]->GetBattery()->GetEnergyGrade();//暂时就先选择一个吧
							entry.destination = neighbors[i];
							entry.nextHop = entry.destination;
							entry.distance = 1;
						}
				
					}
				}
				if(bestGatewayNodeCondition == double(0)){
					ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
					assert(!outLogFile.fail());
					outLogFile<<__TIME__<<"NonGateway节点"<<id<< "孤立,无法路由啦"<<endl;
					outLogFile.close();
					return;//有一个节点是不连通,fail to get a dominating set,网络瘫痪
				}else{
					if(routingTable.size()){
						routingTable[0].destination = entry.destination;
						routingTable[0].nextHop = entry.nextHop;
					}else{
						routingTable.push_back(entry);
					}
				}
			}
			assert(bufferedPackets.size());
			nodes[routingTable[0].nextHop]->PushPackets(bufferedPackets.front());
			
			bufferedPackets.pop();
			return;
		}
		size_t d = 0;
		size_t j = 0;
		for(d = 0; d < domainMembers.size(); ++d){
			if(domainMembers[d] == 0){//暂定sink节点Id为0,0节点一直都是醒着的啊啊啊
				assert(bufferedPackets.size());
				nodes[0]->PushPackets(bufferedPackets.front());
				
				bufferedPackets.pop();
				//找到该sink节点
				//nodes[currentNode->domainMembers[i]]->AddEnergy( -(SEND_PACKET_ENERGY + RECEIVE_PACKET_ENERGY));
				//nodes[0]->AddEnergy( -(RECEIVE_PACKET_ENERGY));
				break;
			}
		}
		if(d == domainMembers.size()){
			size_t i = 0;
			for(i = 0; i < routingTable.size(); ++i){
				j = 0;
				for(; j < nodes[routingTable[i].destination]->GetDomainMembers().size()
					&& nodes[routingTable[i].nextHop]->GetNodeWorkState() == Receiving; ++j){
					if(nodes[routingTable[i].destination]->GetDomainMembers()[j] == 0){//暂定sink节点Id为0
						assert(bufferedPackets.size());
						nodes[routingTable[i].nextHop]->PushPackets(bufferedPackets.front());
						
						bufferedPackets.pop();
						break;
					}
				}
				if(j < nodes[routingTable[i].destination]->GetDomainMembers().size()){
					break;
				}	
			}
			if(i == routingTable.size()){//没有现成的路由,只有广播啦啦
				/*if(currentState == NonGatewayNode){
					double bestGatewayNodeCondition = 0.0;
					RoutingEntry entry;
					for(size_t i = 0; i < neighbors.size(); ++i){
						if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode && nodes[neighbors[i]]->GetNodeWorkState() == Receiving){
							if(nodes[neighbors[i]]->GetBattery()->GetEnergyGrade() > bestGatewayNodeCondition){
								bestGatewayNodeCondition = nodes[neighbors[i]]->GetBattery()->GetEnergyGrade();//暂时就先选择一个吧
								entry.destination = neighbors[i];
								entry.nextHop = entry.destination;
								entry.distance = 1;
							}
				
						}
					}
					if(bestGatewayNodeCondition == double(0)){
						ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
						assert(!outLogFile.fail());
						outLogFile<<__TIME__<<"NonGateway节点"<<id<< "孤立"<<endl;
						outLogFile.close();
						return;//有一个节点是不连通,fail to get a dominating set,网络瘫痪
					}else{
						if(routingTable.size()){
							routingTable[0].destination = entry.destination;
							routingTable[0].nextHop = entry.nextHop;
						}else{
							routingTable.push_back(entry);
						}
					}

				}else{
				*/
					bool isOut = false;
					for(size_t m = 0; m < routingTable.size() 
						&& nodes[routingTable[m].nextHop]->GetNodeWorkState() == Receiving; ++m){
						if(routingTable[m].distance == 1){//当然只广播一跳的邻居啦
							
							assert(bufferedPackets.size());
							
							nodes[routingTable[m].nextHop]->PushPackets(bufferedPackets.front());
							isOut = true;
						}
					}
					if(isOut){
						assert(bufferedPackets.size());
						bufferedPackets.pop();
					}
				//}
			}
		}
	}
	
}
Esempio n. 8
0
void Node::UpdateRoutingTable(){//更新路由表和domain nodes
//根据自己当前的状态确定自己的routing table,必要的话 nodes in its domain
	assert(currentWorkState == Receiving);//因为需要与邻居节点的交换路由表
	//assert(relaxingTime == 0);
	if(id == 0){
		id = 0;
	}
	if(id != 0 && m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}

	RoutingEntry entry;
	if(currentState == NonGatewayNode){
		//has no domain
		//routing table 只有一条,自己选择好的能量最高的gateway node,可不可以多选择几个,
		//再根据休息时间什么的确定,因为能量小的那个说不定再休息多久也不会再增加能量啦,而能量高的那个节点说不定还可以继续增加能量
		double bestGatewayNodeCondition = 0.0;
		if(routingTable.size()){
			bestGatewayNodeCondition = nodes[routingTable[0].nextHop]->GetBattery()->GetEnergyGrade();
		}
		for(size_t i = 0; i < neighbors.size(); ++i){
			if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode 
				&& nodes[neighbors[i]]->GetNodeWorkState() == Receiving){
				if(nodes[neighbors[i]]->GetBattery()->GetEnergyGrade() > bestGatewayNodeCondition){
					bestGatewayNodeCondition = nodes[neighbors[i]]->GetBattery()->GetEnergyGrade();//暂时就先选择一个吧
					entry.destination = neighbors[i];
					entry.nextHop = entry.destination;
					entry.distance = 1;
				}
				
			}
		}
		if(bestGatewayNodeCondition == double(0)){
			ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
			assert(!outLogFile.fail());
			outLogFile<<__TIME__<<"NonGateway节点"<<id<< "孤立"<<endl;
			outLogFile.close();
			return;//有一个节点是不连通,fail to get a dominating set,网络瘫痪
		}else{
			if(routingTable.size()){
				if(bestGatewayNodeCondition != nodes[routingTable[0].nextHop]->GetBattery()->GetEnergyGrade()){
					routingTable[0].destination = entry.destination;
					routingTable[0].nextHop = entry.nextHop;
				}
			}else{
				routingTable.push_back(entry);
			}
		}
		
	}else{//Gateway节点
		for(size_t i = 0; i < neighbors.size(); ++i){
			if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode){
				size_t j = 0;
				for(; j < routingTable.size(); ++j){
					if(neighbors[i] == routingTable[j].nextHop){//已经存在
						break;
					}
				}
				if(j == routingTable.size()){
					entry.destination = neighbors[i];
					entry.nextHop = entry.destination;
					entry.distance = 1;
					routingTable.push_back(entry);
				}
			}else{
				size_t m = 0;
				for(; m < domainMembers.size(); ++m){
					if(i == domainMembers[m]){//已经存在
						break;
					}
				}
				if(m == domainMembers.size()){
					domainMembers.push_back(neighbors[i]);
				}
				
			}
		}
		if(!routingTable.size()){
			ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
			assert(!outLogFile.fail());
			outLogFile<<__TIME__<<"Gateway节点"<<id<< "孤立"<<endl;
			outLogFile.close();
		}
		//根据邻居节点的routing table再更新一下
		for(size_t i = 0; i < neighbors.size(); ++i){
			if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode){
				for(size_t j = 0; j < nodes[neighbors[i]]->routingTable.size(); ++j){
					size_t k = 0;
					for(; k < routingTable.size(); ++k){
						if(nodes[neighbors[i]]->routingTable[j].destination == routingTable[k].destination 
							|| nodes[neighbors[i]]->routingTable[j].destination == id){
							break;
						}
					}
					if(k == routingTable.size()){
						entry.destination = nodes[neighbors[i]]->routingTable[j].destination;
						entry.nextHop = neighbors[i];
						entry.distance = nodes[neighbors[i]]->routingTable[j].distance + 1;
						routingTable.push_back(entry);
					}
				}
			}
		}
	}
}
Esempio n. 9
0
void Node::FurtherDecision(const int& time){//进一步确定自己是不是gateway node,从而精简dominating set的大小
	assert(currentState == GatewayNode);
	assert(currentWorkState == Receiving);
	/*if(currentWorkState == Sleeping){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"都睡着了,还怎么进一步判断自己是不是gateway啊啊啊><"<<endl;
		outLogFile.close();
		return;
	}*/
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}
	//Rule 1
	for(size_t i = 0; i < neighbors.size(); ++i){
		if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode){
			if(VectorBelong2Vector(neighbors,id, nodes[neighbors[i]]->GetNeighbors(), neighbors[i])){
				//如果当前节点的所有邻居也是其邻居gateway节点neighbor[i]的邻居
				Rule1(id, neighbors[i]);
				//Rule11(id, neighbors[i]);
			}
		}
	}
	if(currentState == NonGatewayNode){
		return;
	}
	//Rule 2
	for(size_t i = 0; i < neighbors.size(); ++i){
		for(size_t j = 0; j < neighbors.size(); ++j){
			if(neighbors[i] == neighbors[j]){
				continue;
			}
			if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == GatewayNode && nodes[neighbors[j]]->IsGatewayNodeOrNot() == GatewayNode){
				if(VectorBelong2VectorAndVector(neighbors, nodes[neighbors[i]]->GetNeighbors(), nodes[neighbors[j]]->GetNeighbors())
					&& !VectorBelong2VectorAndVector(nodes[neighbors[i]]->GetNeighbors(),neighbors, nodes[neighbors[j]]->GetNeighbors())
					&& !VectorBelong2VectorAndVector(nodes[neighbors[j]]->GetNeighbors(),neighbors, nodes[neighbors[i]]->GetNeighbors())
					){
					currentState = NonGatewayNode;
				}else{
					if(VectorBelong2VectorAndVector(neighbors, nodes[neighbors[i]]->GetNeighbors(), nodes[neighbors[j]]->GetNeighbors())
						&& VectorBelong2VectorAndVector(nodes[neighbors[i]]->GetNeighbors(),neighbors, nodes[neighbors[j]]->GetNeighbors())
						&& !VectorBelong2VectorAndVector(nodes[neighbors[j]]->GetNeighbors(),neighbors, nodes[neighbors[i]]->GetNeighbors())
						){
							Rule1(id, neighbors[i]);
							//Rule11(id, neighbors[i]);
					}else{
						if(VectorBelong2VectorAndVector(neighbors, nodes[neighbors[i]]->GetNeighbors(), nodes[neighbors[j]]->GetNeighbors())
							&& VectorBelong2VectorAndVector(nodes[neighbors[i]]->GetNeighbors(),neighbors, nodes[neighbors[j]]->GetNeighbors())
							&& VectorBelong2VectorAndVector(nodes[neighbors[j]]->GetNeighbors(),neighbors, nodes[neighbors[i]]->GetNeighbors())
							){
								Rule2(id, neighbors[i], neighbors[j]);
								//Rule22(id, neighbors[i], neighbors[j]);
						}
					}
				}
			}
		}
	}
	/*if(time != -1 && currentState == GatewayNode){
		double pos = ((double)(totalWorkTime) / (double)(time));
		double randN = ((double) (rand() + 1) / (double)(RAND_MAX));
		if( totalWorkTime >= MAX_WORK_TIME &&  randN < pos){
			size_t i = 0;
			for(; i < neighbors.size(); ++i){
				if(nodes[neighbors[i]]->GetNodeWorkState() == Sleeping){
					continue;
				}
				size_t j = 0;
				for(; j < nodes[neighbors[i]]->neighbors.size(); ++j){
					if(nodes[nodes[neighbors[i]]->neighbors[j]]->IsGatewayNodeOrNot() == GatewayNode && id != nodes[neighbors[i]]->neighbors[j]){
						break;
					}
				}
				if(j == nodes[neighbors[i]]->neighbors.size()){
					break;
				}
			}
			if(i == neighbors.size()){
				currentState = NonGatewayNode;
			}
		}
	}*/
	//Rule 3
	/*
	size_t i = 0;
	for(; i < neighbors.size(); ++i){
		if(nodes[neighbors[i]]->IsGatewayNodeOrNot() == NonGatewayNode){
			size_t n = 0;
			for(; n < nodes[neighbors[i]]->GetNeighbors().size(); ++n){
				if(nodes[nodes[neighbors[i]]->GetNeighbors()[n]]->IsGatewayNodeOrNot() == GatewayNode
					&& nodes[neighbors[i]]->GetNeighbors()[n] != id){
					break;
				}
			}
			if(n == nodes[neighbors[i]]->GetNeighbors().size()){
				//当前邻居的一个NonGateway节点没有其他Gateway节点邻居了,只有该节点一个,好可怜啊TQT,当前节点不能改为nongatwayNode啦
				return;
			}
		}else{
			size_t m = 0;
			for(; m < neighbors.size(); ++m){
				if(neighbors[i] == neighbors[m]){
					continue;
				}else{
					if(nodes[neighbors[m]]->IsGatewayNodeOrNot() == GatewayNode){
						size_t x = 0;
						size_t y = 0;
						for(x = 0; x < nodes[neighbors[i]]->GetNeighbors().size(); ++x){						
							for(y = 0; y < nodes[neighbors[m]]->GetNeighbors().size(); ++y){
								if(nodes[neighbors[i]]->GetNeighbors()[x] == nodes[neighbors[m]]->GetNeighbors()[y]
								&& nodes[nodes[neighbors[i]]->GetNeighbors()[x]]->IsGatewayNodeOrNot() == GatewayNode
									&& nodes[neighbors[i]]->GetNeighbors()[x] != id){
									//当前节点的两个gateway邻居节点通过另外一个邻居节点相连
									//并且其能量要高一点,或者其他比较方式
										Rule1(id, nodes[neighbors[i]]->GetNeighbors()[x]);
										if(currentState == NonGatewayNode){
											currentState = GatewayNode;//只是其中两个gateway节点有相连的而已,并不是所有的
											break;
										}
								}
							}
							if(y < nodes[neighbors[m]]->GetNeighbors().size()){
								break;
							}
						}
						if(y < nodes[neighbors[m]]->GetNeighbors().size()){
							break;
						}
					}
				}
			}
			if(m == neighbors.size()){//当前邻居的两个Gateway节点没有其他Gateway节点邻居了,只有该节点一个,也比较可怜
				return;
			}
		}
	}
	if( i == neighbors.size()){
		currentState = NonGatewayNode;
	}
	
	//relaxingTime = 0;
	*/
}