Ejemplo n.º 1
0
bool JSM_Menu::ConfigSubMenuItem(int menu,int item,int sub,Fl_Input* prog_label,Fl_Input* prog_icon,Fl_Input* prog_input,Fl_Check_Button* conf_button){
	debug_out("bool ConfigMenuItem(int menu,int item,int sub,Fl_Input* prog_label,Fl_Input* prog_icon,Fl_Input* prog_input,Fl_Check_Button* conf_button)");
	const char* lbl=NULL;
	if(prog_label!=NULL)lbl=prog_label->value();
	const char* icn=NULL;
	if(prog_icon!=NULL)icn=prog_icon->value();
	const char* prog=NULL;
	if(prog_input!=NULL)prog=prog_input->value();
	char chk='a';
	if(conf_button!=NULL)chk=conf_button->value();
	std::string check="false";
	switch (chk){
		case '0':check="true";
		default:check="false";
	}
	bool retval = true;
	pugi::xml_node noder=getNode(menu, "RootMenu", item);
	if(!noder){return false;}
	pugi::xml_node node=getSubNode(sub,noder);
	pugi::xml_node node1=node;
	pugi::xml_node node2=node;
	if(!node){return false;}
	if(lbl!=NULL){if(!setAttribute(node,"label",lbl)){retval=false;}}
	noder=getNode(menu, "RootMenu", item);
	if(!noder){return false;}
	node=getSubNode(sub,noder);
	if(icn!=NULL){if(!setAttribute(node,"icon",icn)){retval=false;}}
	noder=getNode(menu, "RootMenu", item);
	if(!noder){return false;}
	node=getSubNode(sub,noder);
	if(prog!=NULL){if(!setNodeText(node,prog)){retval=false;}}
	//TODO toggle button issue...
	return retval;
}
Ejemplo n.º 2
0
//显示Topo内容
void DisplayTopo(T_Node Head,Info_Node& info){
	for(int i = 0;i < info.nodeNumber;i++){
		cout<<"{节点【"<<i<<"】 :  \n[TYPE] : "<<getNode(Head,i,NODE_TYPE)<<"\n [NUMBER] : "<<getNode(Head,i,NODE_NUMBER)<<endl;
		for(int j = 0;j<getNode(Head,i,NODE_NUMBER);j++)
		{
			cout<<getSubNode(Head,i,j,SUB_NODE_INDEX)<<":"<<getSubNode(Head,i,j,SUB_NODE_NEXT)<<endl;
		}
		cout<<"}"<<endl;
	}
}
Ejemplo n.º 3
0
void GmSrcEntryNode::expand (vector<GmRestoreNode*> * & subNodes)
{
	if (_vSubNodes.size () == 0)
		getSubNode (_vSubNodes, _pSource, this, _pEntryNode);

	subNodes = &_vSubNodes;
}
Ejemplo n.º 4
0
void Update_Pheromone(T_Node Head,A_Node Ants,Info_Node& info) {
	double pheromone_to_sum;
	int city;
	int next_city;
	for (int i = 0; i < info.antNumber; i++) {
		if((Ants+i)->rout[(Ants+i)->posi]==info.endNode){
			pheromone_to_sum = POSITIVE_CONTS / (Ants+i)->fitn;

			for (int j = 0; j <((Ants+i)->posi); j++) {
				city = (Ants+i)->rout[j];
				next_city = (Ants+i)->rout[j+1];
				if (info.pheromone.data[city][next_city] != INVALID) {
					info.pheromone.data[city][next_city] += pheromone_to_sum;
					//info.pheromone.data[city][next_city] += EVAPORATION_RATE; 
				}
			}
		}
	}
	/*for (int j = 0; j < info.bestLength-1; j++) {
			info.pheromone.data[info.bestRout[j]][info.bestRout[j+1]] += EVAPORATION_RATE;
	}*/
	for (int i = 0; i < info.nodeNumber; i++) {
		for (int j = 0; j < getNode(Head,i,NODE_NUMBER); j++){
			int idata = getSubNode(Head,i,j,SUB_NODE_NEXT);
			if(idata>=0){
				if(info.pheromone.data[i][idata]>MAX_PHEROMONE)
					info.pheromone.data[i][idata]=MAX_PHEROMONE;
				else if(info.pheromone.data[i][idata]<MIN_PHEROMONE)
					info.pheromone.data[i][idata]=MIN_PHEROMONE;
			}
		}
	}
}
Ejemplo n.º 5
0
std::string JSM_Menu::getItemIcon(int menu, int item, int sub){
	debug_out("std::string getItemIcon(int menu, int item, int sub)");
	pugi::xml_node noder=getNode(menu, "RootMenu", item);
	pugi::xml_node node=getSubNode(sub,noder);
	std::string ret=getAttribute(node,"icon");
	debug_out("icon="+ret);
	return ret;
}
Ejemplo n.º 6
0
//检测节点是否访问过,访问过返回true,否则返回no,未知idata
bool Check_Visit(T_Node Head,int start,int offset,A_Node Ants,int index){

	int idata = getSubNode(Head,start,offset,SUB_NODE_NEXT); //获取尾节点

	if((Ants+index)->node[idata] == ANT_GOST){               //检测尾节点是否为经过
		return true;
	}
	return false;
}
Ejemplo n.º 7
0
std::string JSM_Menu::getItemLabel(int menu, int item, int sub){
	debug_out("std::string getItemLabel(int menu, int itemline, int sub)");
	pugi::xml_node noder=getNode(menu, "RootMenu", item);
	if(!noder){return "";}
	pugi::xml_node node=getSubNode(sub,noder);
	if(!node){return "";}
	std::string ret=getAttribute(node,"label");
	debug_out("label="+ret);
	return ret;
}
Ejemplo n.º 8
0
//计算挥发洗漱
void Pheromone_Evaporates(T_Node Head,Info_Node& info) {
	for (int i = 0; i < info.nodeNumber; i++) {
		for (int j = 0; j < getNode(Head,i,NODE_NUMBER); j++){
			int idata = getSubNode(Head,i,j,SUB_NODE_NEXT);
			if(idata>=0){
				info.pheromone.data[i][idata] = (1 - EVAPORATION_RATE) * info.pheromone.data[i][idata];
			}
		}
	}
}
Ejemplo n.º 9
0
void Init_Pheromone(T_Node Head,Info_Node& info){
	for(int i=0;i<info.nodeNumber;i++){
		for(int j=0;j<getNode(Head,i,NODE_NUMBER);j++){
			int idata=getSubNode(Head,i,j,SUB_NODE_NEXT);
			if(idata>=0){
				info.pheromone.data[i][idata]=PHEROMONE_INIT;
			}
		}
	}
}
Ejemplo n.º 10
0
   INT32 _qgmOptiAggregation::done()
   {
      PD_TRACE_ENTRY( SDB__QGMOPTIAGGREGATION_DONE ) ;
      INT32 rc = SDB_OK ;
      qgmOpStream subOpStream ;
      BOOLEAN bSame = TRUE ;

      if ( SDB_OK == getSubNode( 0 )->outputStream( subOpStream ) &&
           NULL == subOpStream.next && !subOpStream.isWildCard() &&
           subOpStream.stream.size() == _selector.size() )
      {
         UINT32 count = _selector.size() ;
         UINT32 index = 0 ;
         while ( index < count )
         {
            qgmOpField &left = _selector[index].value ;
            qgmOpField &right = subOpStream.stream[index] ;

            if ( SQL_GRAMMAR::FUNC == left.type ||
                 !left.alias.empty() )
            {
               bSame = FALSE ;
               break ;
            }
            else if ( ( !right.alias.empty() &&
                         left.value.attr() != right.alias ) ||
                      ( right.alias.empty() &&
                         left.value.attr() != right.value.attr() ) )
            {
               bSame = FALSE ;
               break ;
            }
            ++index ;
         }

         if ( bSame )
         {
            _selector.clear() ;
         }
      }

      PD_TRACE_EXITRC( SDB__QGMOPTIAGGREGATION_DONE, rc ) ;
      return rc ;
   }
Ejemplo n.º 11
0
 const qgmField&      getAlias( BOOLEAN recursive = FALSE )
 {
    if ( !recursive || QGM_OPTI_TYPE_JOIN == _type || !_alias.empty() )
       return _alias ;
    return getSubNode(0)->getAlias( recursive ) ;
 }
Ejemplo n.º 12
0
void Update_Best_Route(T_Node Head,A_Node Ants,Info_Node& info){
	short visitCount=0;
	short left_dist=0;
	short right_dist=0;
	short left_endNode;
	short leftRout[600];
	short rightRout[600];
	short orig_dist=0;
	short start_Position=0;
	double* transfer; 
	memset(leftRout,-1,600);
	memset(rightRout,-1,600);
	Ant_Init(Ants,info); 
	//int roulette0 = Get_Random(0, info.bestLength-1);
	int roulette0=Get_Random(0, info.bestLength-1);
	int i=0;
	int k=0;
	for(int j=roulette0;j>0;j--){
		if(Check_Visit(Head,info.bestRout[j])){//将路由表进行分割,左边路由表的position为roulette
			start_Position=j;
			visitCount++;
			break;
		}
	}
	for(i=0;i<start_Position;i++)
	{
		leftRout[i]=info.bestRout[i];
		left_dist+=info.distances.data[info.bestRout[i]][info.bestRout[i+1]];
	}
	leftRout[i]=info.bestRout[i];
	orig_dist=info.distances.data[info.bestRout[i]][info.bestRout[i+1]];//需要比较的距离
	i++;
	while(Check_Visit(Head,info.bestRout[i])==false && i<info.bestLength-1)//统计两个优化位置之间的间距
	{
		orig_dist+=info.distances.data[info.bestRout[i]][info.bestRout[i+1]];
		visitCount++;
		i++;
		
	}
	if(visitCount>3){
		left_endNode=info.bestRout[i];
		while(i<info.bestLength-1){//右边路由表的起点为优化间距的右端点
			rightRout[k]=info.bestRout[i];
			right_dist+=info.distances.data[info.bestRout[i]][info.bestRout[i+1]];
			i++;
			k++;
		}
		(Ants+0)->dist=left_dist;
		while((Ants+0)->posi!=start_Position){
			(Ants+0)->rout[(Ants+i)->posi]=leftRout[(Ants+0)->posi];
			(Ants+0)->node[leftRout[(Ants+0)->posi]] = ANT_GOST;        //添加到已经过
			(Ants+0)->posi += 1;
		}
		for(int j=1;j<=k;j++){
			(Ants+0)->tabu[j]=rightRout[j];
			(Ants+0)->node[rightRout[j]] = ANT_TABU;
		}
		rightRout[k]=info.bestRout[i];
		(Ants+0)->rout[(Ants+0)->posi]=leftRout[(Ants+0)->posi];
		(Ants+0)->node[leftRout[(Ants+0)->posi]] = ANT_GOST; 
		(Ants+1)->rout[(Ants+1)->posi]=leftRout[(Ants+0)->posi];
		int best=MAX_DIST_VAL;
		int next=1;
		int i=2;
		int m,n,temp;
		int nextDist;
		int count;
		ofstream fp;
		while(true){
			int position=(Ants+next)->rout[(Ants+next)->posi];
			count = 0;
			nextDist=(Ants+next)->dist;
			for (int j = 0; j < getNode(Head,position,NODE_NUMBER); j++){//获取当前节点的出度值
				temp=0;
				n=0;
				short idata = getSubNode(Head,position,j,SUB_NODE_NEXT);// 获取出度j尾节点的值
				if (Check_Visit(Ants,0,idata)==false && Check_Tabu(Ants,0,idata)==false && Check_Visit(Ants,next,idata)==false){
					if(info.distances.data[position][idata]>0){
						while(n<i){
							n++;
							if(idata==(Ants+next)->rout[(Ants+next)->posi]){
								if(((Ants+next)->dist+info.distances.data[position][idata])<(Ants+i)->dist){
									for(m=0;m<=(Ants+next)->posi;m++){
											(Ants+n)->rout[m]=(Ants+next)->rout[m];
											(Ants+n)->node[(Ants+n)->rout[m]]=ANT_GOST;
										};
										(Ants+n)->dist=(Ants+next)->dist+info.distances.data[position][idata];
										(Ants+n)->rout[m]=idata;
										(Ants+n)->node[idata]=ANT_GOST;
										(Ants+n)->posi=m;
									}
								temp=1;
								break;
							}
						}
							if(temp==0){
								if(count==0){
									(Ants+next)->posi += 1;
									(Ants+next)->rout[(Ants+next)->posi]=idata;
									(Ants+next)->node[idata]=ANT_GOST;
									(Ants+next)->dist += info.distances.data[position][idata];
								}
								else{
									for(m=0;m<(Ants+next)->posi;m++){
										(Ants+i)->rout[m]=(Ants+next)->rout[m];
										(Ants+i)->node[(Ants+i)->rout[m]]=ANT_GOST;
									}
									(Ants+i)->posi=m;
									(Ants+i)->rout[(Ants+i)->posi]=idata;
									(Ants+i)->node[idata]=ANT_GOST;
									(Ants+i)->dist=nextDist+info.distances.data[position][idata];
									i++;
								}
								count++;
							}
							else
								continue;
					}
				}
			}
			n=1;
			best=MAX_DIST_VAL;
			while(n<i){
				if((Ants+n)->dist<best && Check_Visit(Ants,0,(Ants+n)->rout[(Ants+n)->posi])==false){
					next=n;
					best=(Ants+n)->dist;
				}
				n++;
			}
			(Ants+0)->posi += 1;
			(Ants+0)->rout[(Ants+0)->posi]=(Ants+next)->rout[(Ants+next)->posi];
			(Ants+0)->node[(Ants+0)->rout[(Ants+0)->posi]]=ANT_GOST;
			if((Ants+next)->rout[(Ants+next)->posi]==left_endNode)
			{
				break;
			}
		}
		if((Ants+next)->dist<orig_dist){
			int r=1;
			int i;
			for(i=1;i<=(Ants+next)->posi;i++){
				info.bestRout[start_Position+i]=(Ants+next)->rout[i];
			}
			while(rightRout[r]!=-1){
				info.bestRout[start_Position+i]=rightRout[r];
				i++;
				r++;
			}
			info.bestDist=left_dist+(Ants+next)->dist+right_dist;
			info.bestLength=start_Position+i;
		}
	}			
}
Ejemplo n.º 13
0
//链表节点 蚂蚁节点 蚂蚁数量 开始节点 数量
void Build_Solution(T_Node Head,A_Node Ants,Info_Node& info,double init_prob) {

	int nodeNumber = info.nodeNumber;                      //获取节点总数
	double* transfer;                                      //转移概率分子值
	double linkRate = 0;                                   //连接度总和
	short count=0;                                         //计数器
	short tabuCount = 0;                                  //禁忌表计数器
	short tabuTemp=-1;
	if(nodeNumber>0){
	 transfer = new double[nodeNumber];                    //申请空间
	}
	Ant_Init(Ants,info);                                   //初始化蚂蚁节点,清空

	for (int i = 0; i < info.antNumber; i++) {   //根据蚂蚁只数完成一次循环
		count=0;
		short cycleCount = 0;
		tabuCount=0;
		while ((Ants+i)->rout[(Ants+i)->posi] != info.endNode){//若当前节点不是终止节点且走过的点数小于总点数
			cycleCount++;
			int position = (Ants+i)->rout[(Ants+i)->posi]; //获取当前位置节点值,相当于A->B中的A

			memset(transfer,0,nodeNumber);                 //清零概率分子值

			linkRate = 0;                                  //初始化概率分母和
			for (int j = 0; j < getNode(Head,position,NODE_NUMBER); j++){//获取当前节点的出度值
				short idata = getSubNode(Head,position,j,SUB_NODE_NEXT);// 获取出度j尾节点的值
				if (Check_Visit(Ants,i,idata) == false){
					if(info.distances.data[position][idata]>0 && Check_Visit(Ants,i,idata) == false && Check_Tabu(Ants,i,idata)==false && idata!=tabuTemp){
						if(idata == info.endNode && count != info.mustNumber){
							continue;}
						else{
							if(Check_Visit(Head,idata) && (Ants+i)->posi>1){
									info.pheromone.data[position][idata] *= 1.2;
									info.pheromone.data[(Ants+i)->rout[(Ants+i)->posi-1]][position] *= 1.2;
								}
						double current = pow(info.pheromone.data[position][idata], info.alpha) * pow(double(info.maxWeight - info.distances.data[position][idata]),info.beta);;
							linkRate += current; //连接度加和     
							transfer[idata] = current;//当前节点量值
						}
					}
				}
			}

			for (short j = 0; j < getNode(Head,position,NODE_NUMBER); j++){
				short idata = getSubNode(Head,position,j,SUB_NODE_NEXT);      //获取尾节点值
				if(info.distances.data[position][idata]>0 && Check_Visit(Ants,i,idata) == false && Check_Tabu(Ants,i,idata)==false){ 
					if(idata == info.endNode && count != info.mustNumber){
							continue;}//查看当前节点是否访问过
					else
					transfer[idata] = transfer[idata] / linkRate;
				}
			}

			double roulette = (double) Get_Random(0, 100) / 100.0;
			double minor = 0;
			double major = 0;
			short selectidata = -1;
			if(roulette<=init_prob)
			{ 
				double temp=0;
				for (int j = 0; j <getNode(Head,position,NODE_NUMBER); j++){
					short idata = getSubNode(Head,position,j,SUB_NODE_NEXT);
					if (Check_Visit(Ants,i,idata) == false && info.distances.data[position][idata]>0 && Check_Tabu(Ants,i,idata)==false)
					{
						if(idata == info.endNode && count != info.mustNumber){
							continue;}//查看当前节点是否访问过
						else
						{
							if(transfer[idata]>temp)
							{
								temp=transfer[idata];
								selectidata=idata;
							}
						}
					}
				}
			}
			else{
				for (int j = 0; j <getNode(Head,position,NODE_NUMBER); j++)
				{
					short idata = getSubNode(Head,position,j,SUB_NODE_NEXT);
					if(info.distances.data[position][idata]>0 && Check_Visit(Ants,i,idata) == false && Check_Tabu(Ants,i,idata)==false) 
					{
						if(idata == info.endNode && count != info.mustNumber){
							continue;}//查看当前节点是否访问
						else
						{
							major += transfer[idata];
							if (roulette >= minor && roulette <= major) 
							{/*
								(Ants+i)->posi += 1;                    
								(Ants+i)->rout[(Ants+i)->posi] = idata;  

								(Ants+i)->node[idata] = ANT_GOST;      
								(Ants+i)->dist += info.distances.data[position][idata];
								info.pheromone.data[position][idata] *= 0.8;

								if(Check_Visit(Head,idata))
								{
									count++;
									info.pheromone.data[position][idata] *= 1.5;
								}*/
								selectidata=idata;
								break;
							} 
						}
					}
						else
						{
							minor = major;
						}
					}
			}
			if(selectidata==-1)
			{
				if(Check_Visit(Head,(Ants+i)->rout[(Ants+i)->posi]))//查看是否为必经点
				{
					count--;
					(Ants+i)->rout[(Ants+i)->posi]=ANT_UNGO;
					(Ants+i)->tabu[tabuCount] = INVALID;
				}
				else
				{
					(Ants+i)->tabu[tabuCount] = (Ants+i)->rout[(Ants+i)->posi];
					(Ants+i)->node[position] = ANT_TABU;      //添加到已经过
				}
				(Ants+i)->rout[(Ants+i)->posi] = INVALID;
				(Ants+i)->posi -= 1;
				(Ants+i)->dist -= info.distances.data[(Ants+i)->rout[(Ants+i)->posi]][position];
				
				tabuCount++;
				//tabuTemp=(Ants+i)->rout[(Ants+i)->posi];
				if((tabuCount>nodeNumber*0.1) || (cycleCount>nodeNumber))
				{
					//cout<<cycleCount<<" "<<endl;
					break;
				}
			}
			else
			{
				(Ants+i)->posi += 1;                     //位置标记++
				(Ants+i)->rout[(Ants+i)->posi] =selectidata;  //保存下一节点值

				(Ants+i)->node[selectidata] = ANT_GOST;        //添加到已经过
				(Ants+i)->dist += info.distances.data[position][selectidata];
				info.pheromone.data[position][selectidata] *= 0.9;
				
				if(Check_Visit(Head,selectidata)){
					count++;
				}
			}
			if(count == info.mustNumber && (Ants+i)->rout[(Ants+i)->posi]==info.endNode)
					break;
		}
	}
	delete[] transfer;
}