亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tsp.c

?? 用C編寫的部落尋優的優化算法
?? C
字號:
//======================================================== CHECK_SEQ int check_seq(struct position s) // Check how many times there is two times the same value {  int check;  int i,j;  check=0;  for (i=0;i<s.p.size-1;i++) {     for (j=i+1;j<s.p.size;j++)     {        if ((int)s.p.x[i]==(int)s.p.x[j]) check=check+1;     } } return check; } //======================================================== F_TSP double f_tsp(struct position pos,int option, int penalty,int rank1,int rank2,int level) { /*   The graph matrix P   is a global variable, in problem   problem is a global variable   If rank1>=0, positions in rank1 and rank2 have just been switched */ int        d; double  delta_eval; int        DD; int        i,j; double total;   DD=pos.p.size; /*   When there has been just a switch between positions, the f_value could be (and will be in next version)   evaluated by updating  at most 4 arcs values */ if (rank1<0) delta_eval=1; else delta_eval=4/(double)DD; eval_f[level]=eval_f[level]+delta_eval;eval_f_tot[level]=eval_f_tot[level]+delta_eval; // Option 1. Classical (discrete) way  total=0;for (d=0;d<DD-1;d++){    i=(int)pos.p.x[d];    j=(int)pos.p.x[d+1];   total=total+problem[level].P.val[i][j]; }  i=(int)pos.p.x[DD-1];  j=(int)pos.p.x[0]; total=total+problem[level].P.val[i][j];  if (penalty==0) goto end;  // ... else, add penalty if several times the same node d=check_seq(pos); if (d>0) total=total+d*problem[level].P.max_cont; end: return total;}  //======================================================== INIT_PARTICLE_TSP struct particle init_particle_tsp(int size,double target,int level){int                     d;struct particle part;struct position   x0;x0.p.size=size;for( d = 0;d<size;d++)  	x0.p.x[d] = d;// initial sequence x0.p=random_permut(x0.p); x0.f.f[0]=f_tsp(x0,1,0,-1,-1,level);   // Evaluate. We are _sure_ there is no penalty to add x0.f.f[0]=fabs(target-x0.f.f[0]); x0.f.size=problem[level].nb_f; part.x=x0; part.p_i=part.x; // Best previous = current part.prev_x=part.x; // Previous=current part.label=label[level]; label[level]=label[level]+1; return part; } //======================================================== INIT_SWARM_TSPstruct tribe init_swarm_tsp(int size,double target,int trace,int level){/* Initialization of the swarm */int 				i;int                     init_level;int                     init_option;struct   position     s1;struct tribe   T;double            total;	printf("\n Swarm initialization for TSP");	if (size>10) printf(" Please wait");init_option=2; // *** Hard coded optionT.size=size; //s1.f.size=problem[level].nb_f;   // MUST be equal to 1, for the moment  s1.f.size=1;switch (init_option){    case 1:  // Deterministic initialization, level 1      for (i=0;i<size;i++)  // Define a tour beginning on i, using systematically                                    // the smallest arc still free      {        if (trace>1) printf("\n init particle %i",i+1);           T.part[i].x=min_tour_tsp(i,level);    // Tour, built from i, with a simple greedy algorithm         total=f_tsp(T.part[i].x,1,0,-1,-1,level);   // Evaluate. We are _sure_ there is no penalty to add         T.part[i].x.f.f[0]=fabs(target-total);           //T.part[i].x.f.size=problem[level].nb_f; // Number of functions to optimize. MUST be equal to 1, for the moment           T.part[i].x.f.size=1;         T.part[i].p_i=T.part[i].x; // Best previous = current         T.part[i].prev_x=T.part[i].x; // Previous = current      }      break; case 2:  // Deterministic initialization, level 2 printf("\n init level 2. Size %i", size); init_level=1; case2:      for (i=0;i<size;i++)  // Define a tour beginning on i, using systematically                                    // the smallest 2-arcs path still free      {          // Tour, built from i, with a simple greedy algorithm         s1=min_tour_tsp(i,level);         total=f_tsp(s1,1,0,-1,-1,level);  // Evaluate. We are _sure_ there is no penalty to add           s1.f.f[0]=fabs(target-total);           //s1.f=T.part[i].x.f;         T.part[i].x=min_tour_2_tsp(i,init_level,level);         T.part[i].x.f.f[0]=f_tsp(T.part[i].x,1,0,-1,-1,level);         T.part[i].x.f.f[0]=fabs(target-T.part[i].x.f.f[0]);         if (T.part[i].x.f.f[0]>s1.f.f[0]) T.part[i].x=s1; // Choose the best         //T.part[i].x.f.size=problem[level].nb_f;         T.part[i].x.f.size=1;          T.part[i].p_i=T.part[i].x; // Best previous = current         T.part[i].prev_x=T.part[i].x; // Previous = current      }      break; case 3: printf("\n init level 2a"); init_level=2; goto case2; } for (i=0;i<size;i++)    // Set the labels {  T.part[i].label=label[level]; label[level]=label[level]+1;} printf("\n End of swarm initialization for TSP "); printf("\n");return T;}//============================================================ LOCAL_SEARCH_TSPstruct position local_search_tsp(struct position pos,double target,int level){/* Check the immediate neighbours, as long as there is some improvement Note: pos is supposed to be an integer position*/int                     DD;int                     d1,d2;double               f;double               node;struct position x1,x2; DD=pos.p.size; x1=pos; x2=pos; look_around: for (d1=0;d1<DD-1;d1++) {      for (d2=d1+1;d2<DD;d2++)      {         // Transpose         node=x2.p.x[d1];         x2.p.x[d1]= x2.p.x[d2];          x2.p.x[d2]=node;        // Evaluate        f=f_tsp(x2,1,1,d1,d2,level);        f=fabs(target-f);        if (f<x1.f.f[0])  // if improvement, memorize and try again        { //printf("\nlocal_search_tsp. x1.f %f, f %f",x1.f.f[0],f);          x1=x2;          x1.f.f[0]=f;          if((problem[level].Max_Eval<0 && eval_f_tot[level]>-problem[level].Max_Eval) || problem[level].Max_Eval>clock_tick)            return x1;          goto look_around;        }        else  // Transpose back and continue        {           node=x2.p.x[d1];           x2.p.x[d1]= x2.p.x[d2];           x2.p.x[d2]=node;        }      } }//printf("\nlocal_search_tsp. %f => %f",pos.f.f[0],x1.f.f[0]);return x1;}  //============================================================ MIN_TOUR _TSP struct   position   min_tour_tsp(int i,int level){    //    Start from node i, and systematically add the smallest arc still free double        big_value;  int             j;  double       min;  int             next;  int             rank;  double       val;  struct position x;  int          used[Max_C]={0}; if(problem[level].printlevel>1) printf("\n min_tour_tsp node %i",i);  big_value= problem[level].P.max_cont+1;  x.p.size=problem[level].P.size;  rank=0;  x.p.x[rank]=i;  used[i]=1;  loop:  min=big_value+1;  for (j =0;j<x.p.size;j++) // Check all neighbours of x.s[rank]  {     if (used[j]==1) continue;     val= problem[level].P.val[ (int)x.p.x[rank]][j];      if (val<0) val=big_value;    // For non existent arc      if (val<min)      {         next=j;         min=val;       }   }   rank=rank+1;   x.p.x[rank]=next;   used[next]=1;   if (rank<x.p.size-1)  goto loop;  x.p.x[x.p.size]=x.p.x[0]; // To complete the tour  return x;} //============================================================ MIN_TOUR_2_TSP struct   position   min_tour_2_tsp(int i,int init_level,int level){    //    Start from node i, and systematically add the smallest 2-arcs path still free double        big_value;  int             j,k;  double       min;  int             next,next2;  int             rank;  double       val_j,val_k;  struct position x;  int          used[Max_C]={0}; if(problem[level].printlevel>1) printf("\n min_tour_2_tsp node %i",i);   big_value= problem[level].P.max_cont+1;  x.p.size=problem[level].P.size;  rank=0;  x.p.x[rank]=i;  used[i]=1;  loop: //printf("\n rank %i",rank);  min=2*big_value+1;  for (j =0;j<x.p.size;j++) // Check all neighbours of x.s[rank]  { //printf("\n %i, %i, %f /",j,used[j],min);     if (used[j]==1) continue;     val_j= problem[level].P.val[(int) x.p.x[rank]][j];      if (val_j<0) val_j=big_value;    // For non existent arc      if (rank==problem[level].P.size-2)      {         x.p.x[x.p.size-1]=j;         goto end;      }      for(k=0;k<x.p.size;k++)      { //printf("\n %i",k);      if (k==j) continue;      if (used[k]==1) continue;        val_k= problem[level].P.val[ j][k];        if (val_k<0) val_k=big_value;         if (val_j+val_k<min)         {            next=j;            next2=k;            min=val_j+val_k;         }      }  }  //printf("\n next %i",next);  if(init_level==1)  {   rank=rank+1;       x.p.x[rank]=next;       used[next]=1;       if (rank<x.p.size-1) goto loop;  }  if (init_level==2)  {       rank=rank+1;       x.p.x[rank]=next;       used[next]=1;       rank=rank+1;       x.p.x[rank]=next2;       used[next2]=1;       if (rank<x.p.size-2) goto loop;  } end:  x.p.x[x.p.size]=x.p.x[0]; // To complete the tour  return x;} //========================================================  NEAREST_INTstruct position nearest_int(struct position pos,double target,int level){int                     d; struct position p; //printf("\n nearest int"); //display_position(pos); p.p.size=pos.p.size; for (d=0;d<p.p.size;d++) {    p.p.x[d]=floor(pos.p.x[d]+0.5);    if (p.p.x[d]>=p.p.size) p.p.x[d]=p.p.size-1; } p.f.f[0]=f_tsp(p,1,1,-1,-1,level); p.f.f[0]=fabs(target-p.f.f[0]); return p;} //========================================================  READ_GRAPH_TSPstruct matrix read_graph_tsp(int trace){/* TSPLIB MATRIX format. One value/line. First value = number of nodeseach value = arc value. If <0 => no arc*/char			bidon[50];char			comment[100];char              graph[80];char			edge_weight_format[30];char			edge_weight_type[30];struct matrix	Gt;int 			i,j;char			name[20];double         total;char			type[20];float         zzz;FILE *file;printf("\nFile name for the graph, please: ");gets(graph);file=fopen(graph,"r");printf("\nI am reading the graph");fscanf(file," %s %s\n",bidon,name);fscanf(file," %s %s\n",bidon,type);	fscanf(file," %s %s\n",bidon,comment);	fscanf(file,"%s %i\n",bidon,&Gt.size); // dimension	fscanf(file,"%s %s\n",bidon,edge_weight_type);	fscanf(file,"%s %s\n",bidon,edge_weight_format);	fscanf(file,"%s\n",bidon);	printf("\n Name: %s, type: %s, (%s)",name,type,comment);	printf("\n Number of nodes: %i",Gt.size);	printf("\n %s %s\n",edge_weight_type,edge_weight_format);	if (edge_weight_type[0]=='E' && edge_weight_format[0]=='F')		{		for (i=0;i<Gt.size;i++)			{                for (j=0;j<Gt.size;j++)				{                        fscanf(file,"%e ",&zzz);                            Gt.val[i][j]=zzz;                            // A negative value is for "no edge". See below					if (trace>2) printf(" %f",Gt.val[i][j]);				}			Gt.val[i][i]=0;			}            	printf("\n Weigths read. %i lines %i columns",Gt.size,Gt.size); Gt.max_cont=0;   //  Memorize the max value for future penalty  		for (i=0;i<Gt.size;i++)			{                for (j=0;j<Gt.size;j++)				{                        if (Gt.val[i][j]>Gt.max_cont) Gt.max_cont=Gt.val[i][j];                     }                  } printf(" Max arc value %f",Gt.max_cont);// Modify P to take unexistent edges into accounttotal=  1.1*Gt.max_cont*Gt.size; // Big value  for (i=0;i<Gt.size;i++)	{		for (j=0;j<Gt.size;j++)		{            if(Gt.val[i][j]<0) Gt.val[i][j]=total;         }      }		goto end;		}   printf("\nERROR by reading graph"); end: fclose(file);  return Gt;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色综合天天在线| 久久久精品影视| 欧美精品一区二区三区一线天视频| 国产三级久久久| 亚洲一区二区在线免费看| 国产成人午夜精品影院观看视频 | 国产尤物一区二区| 欧美日韩一区成人| 国产亚洲欧美中文| 日韩av不卡一区二区| 97成人超碰视| 欧美激情在线免费观看| 日韩av在线播放中文字幕| 色综合天天天天做夜夜夜夜做| xvideos.蜜桃一区二区| 午夜欧美大尺度福利影院在线看| 成人黄色av网站在线| 欧美精品一区二区三区久久久| 亚洲一区日韩精品中文字幕| 成人国产精品免费观看| 日本一区二区在线不卡| 麻豆精品视频在线| 日韩一区二区三区观看| 亚洲国产成人91porn| 欧美伊人久久久久久午夜久久久久| 欧美激情在线免费观看| 成人综合在线观看| 久久精品视频在线免费观看| 激情成人午夜视频| 精品国产3级a| 国产一区二区三区观看| 久久综合一区二区| 精品在线播放免费| 精品国产123| 国内精品嫩模私拍在线| 精品国产露脸精彩对白| 韩日欧美一区二区三区| 亚洲与欧洲av电影| 色94色欧美sute亚洲13| 亚洲精品菠萝久久久久久久| 在线观看亚洲专区| 图片区日韩欧美亚洲| 88在线观看91蜜桃国自产| 日韩精品乱码免费| 欧美电影免费观看高清完整版在线| 免费观看30秒视频久久| 欧美成va人片在线观看| 粉嫩欧美一区二区三区高清影视| 久久久99精品久久| 99久久久免费精品国产一区二区 | 精品国内二区三区| 国产一区二区在线观看视频| 久久久不卡网国产精品二区| 成人免费av网站| 亚洲资源中文字幕| 91精品国产综合久久精品图片| 国内精品伊人久久久久av影院| 国产网站一区二区| 一本大道av一区二区在线播放 | 99热99精品| 亚洲欧美一区二区不卡| 欧美日韩国产首页| 欧美亚洲一区三区| 天堂一区二区在线| 久久麻豆一区二区| 99久久99精品久久久久久| 亚洲一区二区不卡免费| 日韩三级视频在线观看| 成人涩涩免费视频| 午夜免费久久看| 国产性做久久久久久| 在线观看不卡视频| 国产精品69久久久久水密桃| 一区二区三区美女视频| 欧美xfplay| 91福利在线播放| 国产精品一区在线| 婷婷国产在线综合| 国产目拍亚洲精品99久久精品 | 99国内精品久久| 日韩精品一级二级| 日本一区二区三区久久久久久久久不| 91传媒视频在线播放| 国产乱码精品1区2区3区| 亚洲一区二区av在线| 亚洲国产成人午夜在线一区| 欧美日韩亚洲综合在线| 成人美女在线视频| 精品伊人久久久久7777人| 亚洲主播在线观看| 中文字幕一区av| 久久久久久夜精品精品免费| 欧美日韩在线三区| 91免费国产视频网站| 久久99精品国产.久久久久| 亚洲综合视频在线| 亚洲品质自拍视频网站| 国产女人aaa级久久久级| 精品va天堂亚洲国产| 欧美久久久一区| 欧美在线你懂得| 色一区在线观看| www.久久精品| 成人精品一区二区三区四区| 九一九一国产精品| 麻豆freexxxx性91精品| 香蕉av福利精品导航| 亚洲小说欧美激情另类| 亚洲免费观看在线观看| 亚洲欧美在线视频| 国产精品麻豆99久久久久久| 欧美精彩视频一区二区三区| 久久久国产精华| 国产精品视频yy9299一区| 国产日韩精品一区二区三区在线| 欧美精品一区在线观看| 26uuu欧美| 欧美韩国日本综合| 欧美激情艳妇裸体舞| 中文字幕乱码久久午夜不卡 | 欧美日韩精品欧美日韩精品一| 欧美又粗又大又爽| 欧美日韩高清一区二区三区| 欧美理论在线播放| 国产精品久久久久久久久久免费看| 久久综合狠狠综合| 久久久久国产一区二区三区四区| 国产亚洲欧美色| 欧美国产在线观看| 中文字幕欧美一| 有坂深雪av一区二区精品| 亚洲一级在线观看| 日本不卡高清视频| 精品亚洲porn| 成人看片黄a免费看在线| 色94色欧美sute亚洲线路一ni| 欧美在线你懂的| 精品国产乱码久久| 亚洲日本在线天堂| 亚洲成人久久影院| 国产精品一区二区果冻传媒| 9色porny自拍视频一区二区| 在线观看日韩一区| 日韩视频一区二区三区在线播放| 26uuu精品一区二区| 亚洲视频狠狠干| 天天色天天爱天天射综合| 日本va欧美va欧美va精品| 国产尤物一区二区| 欧美午夜精品一区二区三区 | 国产精品久久久久9999吃药| 亚洲精品久久嫩草网站秘色| 三级精品在线观看| 国产成人午夜精品影院观看视频| 91久久香蕉国产日韩欧美9色| 欧美电影一区二区三区| 欧美韩国一区二区| 首页国产欧美日韩丝袜| 懂色av噜噜一区二区三区av| 欧美最猛黑人xxxxx猛交| 久久亚洲一区二区三区四区| 日韩理论片在线| 乱中年女人伦av一区二区| 91色在线porny| 精品伦理精品一区| 亚洲综合激情网| 成人深夜福利app| 日韩欧美国产一区二区三区 | 日本不卡的三区四区五区| av午夜精品一区二区三区| 日韩一区二区三| 亚洲另类中文字| 国产成人午夜电影网| 91精品欧美一区二区三区综合在| 亚洲欧洲日产国码二区| 韩国精品一区二区| 欧美乱熟臀69xxxxxx| 亚洲免费毛片网站| 懂色av一区二区夜夜嗨| 日韩欧美资源站| 五月天精品一区二区三区| 9l国产精品久久久久麻豆| 久久精品日产第一区二区三区高清版 | 国产精品理伦片| 国模少妇一区二区三区| 欧美日韩一级黄| 一区二区高清视频在线观看| 粉嫩13p一区二区三区| 欧美大片一区二区三区| 日韩精品国产精品| 欧美主播一区二区三区| 亚洲三级小视频| av电影天堂一区二区在线观看| 久久女同互慰一区二区三区| 久久草av在线| 精品99一区二区| 国产精选一区二区三区| 亚洲精品在线电影| 国产一区啦啦啦在线观看| 精品日韩一区二区|