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

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

?? ls.c

?? 蟻群算法的程序
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*       AAAA    CCCC   OOOO   TTTTTT   SSSSS  PPPPP      AA  AA  CC     OO  OO    TT    SS      PP  PP      AAAAAA  CC     OO  OO    TT     SSSS   PPPPP      AA  AA  CC     OO  OO    TT        SS  PP      AA  AA   CCCC   OOOO     TT    SSSSS   PP################################################################    ACO algorithms for the TSP    ################################################################      Version: 1.0      File:    ls.c      Author:  Thomas Stuetzle      Purpose: implementation of local search routines      Check:   README and gpl.txt      Copyright (C) 1999  Thomas Stuetzle*//***************************************************************************    Program's name: acotsp    Ant Colony Optimization algorithms (AS, ACS, EAS, RAS, MMAS, BWAS) for the     symmetric TSP     Copyright (C) 2004  Thomas Stuetzle    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    email: stuetzle no@spam informatik.tu-darmstadt.de    mail address: Universitaet Darmstadt                  Fachbereich Informatik                  Hochschulstr. 10                  D-64283 Darmstadt		  Germany***************************************************************************/#include <stdio.h>#include <assert.h>#include <stdlib.h>#include <limits.h>#include "InOut.h"#include "TSP.h"#include "ants.h"#include "utilities.h"long int ls_flag;          /* indicates whether and which local search is used */ long int nn_ls;            /* maximal depth of nearest neighbour lists used in the 			      local search */ long int dlb_flag = TRUE;  /* flag indicating whether don't look bits are used. I recommend 			      to always use it if local search is applied */long int * generate_random_permutation( long int n )/*          FUNCTION:       generate a random permutation of the integers 0 .. n-1      INPUT:          length of the array      OUTPUT:         pointer to the random permutation      (SIDE)EFFECTS:  the array holding the random permutation is allocated in this                       function. Don't forget to free again the memory!      COMMENTS:       only needed by the local search procedures*/{   long int  i, help, node, tot_assigned = 0;   double    rnd;   long int  *r;   r = malloc(n * sizeof(int));     for ( i = 0 ; i < n; i++)      r[i] = i;   for ( i = 0 ; i < n ; i++ ) {     /* find (randomly) an index for a free unit */      rnd  = ran01 ( &seed );     node = (long int) (rnd  * (n - tot_assigned));      assert( i + node < n );     help = r[i];     r[i] = r[i+node];     r[i+node] = help;     tot_assigned++;   }   return r;}void two_opt_first( long int *tour ) /*          FUNCTION:       2-opt a tour       INPUT:          pointer to the tour that undergoes local optimization      OUTPUT:         none      (SIDE)EFFECTS:  tour is 2-opt      COMMENTS:       the neighbourhood is scanned in random order (this need                       not be the best possible choice). Concerning the speed-ups used 		      here consult, for example, Chapter 8 of		      Holger H. Hoos and Thomas Stuetzle, 		      Stochastic Local Search---Foundations and Applications, 		      Morgan Kaufmann Publishers, 2004.		      or some of the papers online available from David S. Johnson.*/{    long int c1, c2;             /* cities considered for an exchange */    long int s_c1, s_c2;         /* successor cities of c1 and c2     */    long int p_c1, p_c2;         /* predecessor cities of c1 and c2   */       long int pos_c1, pos_c2;     /* positions of cities c1, c2        */    long int i, j, h, l;    long int improvement_flag, improve_node, help, n_improves = 0, n_exchanges=0;    long int h1=0, h2=0, h3=0, h4=0;    long int radius;             /* radius of nn-search */    long int gain = 0;    long int *random_vector;    long int *pos;               /* positions of cities in tour */     long int *dlb;               /* vector containing don't look bits */       pos = malloc(n * sizeof(long int));    dlb = malloc(n * sizeof(long int));    for ( i = 0 ; i < n ; i++ ) {	pos[tour[i]] = i;	dlb[i] = FALSE;    }    improvement_flag = TRUE;    random_vector = generate_random_permutation( n );    while ( improvement_flag ) {	improvement_flag = FALSE;	for (l = 0 ; l < n; l++) {	    c1 = random_vector[l]; 	    DEBUG ( assert ( c1 < n && c1 >= 0); )		if ( dlb_flag && dlb[c1] )		    continue;	    improve_node = FALSE;	    pos_c1 = pos[c1];	    s_c1 = tour[pos_c1+1];	    radius = instance.distance[c1][s_c1];	    /* First search for c1's nearest neighbours, use successor of c1 */	    for ( h = 0 ; h < nn_ls ; h++ ) {		c2 = instance.nn_list[c1][h]; /* exchange partner, determine its position */		if ( radius > instance.distance[c1][c2] ) {		    s_c2 = tour[pos[c2]+1];		    gain =  - radius + instance.distance[c1][c2] + 			instance.distance[s_c1][s_c2] - instance.distance[c2][s_c2];		    if ( gain < 0 ) {			h1 = c1; h2 = s_c1; h3 = c2; h4 = s_c2; 			improve_node = TRUE;			goto exchange2opt;		    }		}		else 		    break;	    }      	    /* Search one for next c1's h-nearest neighbours, use predecessor c1 */	    if (pos_c1 > 0)		p_c1 = tour[pos_c1-1];	    else 		p_c1 = tour[n-1];	    radius = instance.distance[p_c1][c1];	    for ( h = 0 ; h < nn_ls ; h++ ) {		c2 = instance.nn_list[c1][h];  /* exchange partner, determine its position */		if ( radius > instance.distance[c1][c2] ) {		    pos_c2 = pos[c2];		    if (pos_c2 > 0)			p_c2 = tour[pos_c2-1];		    else 			p_c2 = tour[n-1];		    if ( p_c2 == c1 )			continue;		    if ( p_c1 == c2 )			continue;		    gain =  - radius + instance.distance[c1][c2] + 			instance.distance[p_c1][p_c2] - instance.distance[p_c2][c2];		    if ( gain < 0 ) {			h1 = p_c1; h2 = c1; h3 = p_c2; h4 = c2; 			improve_node = TRUE;			goto exchange2opt;		    }		}		else 		    break;	    }      	    if (improve_node) {	    exchange2opt:		n_exchanges++;		improvement_flag = TRUE;		dlb[h1] = FALSE; dlb[h2] = FALSE;		dlb[h3] = FALSE; dlb[h4] = FALSE;		/* Now perform move */		if ( pos[h3] < pos[h1] ) {		    help = h1; h1 = h3; h3 = help;		    help = h2; h2 = h4; h4 = help;		}		if ( pos[h3] - pos[h2] < n / 2 + 1) {		    /* reverse inner part from pos[h2] to pos[h3] */		    i = pos[h2]; j = pos[h3];		    while (i < j) {			c1 = tour[i];			c2 = tour[j];			tour[i] = c2;			tour[j] = c1;			pos[c1] = j;			pos[c2] = i;			i++; j--;		    }		}		else {		    /* reverse outer part from pos[h4] to pos[h1] */		    i = pos[h1]; j = pos[h4];		    if ( j > i )			help = n - (j - i) + 1;		    else 			help = (i - j) + 1;		    help = help / 2;		    for ( h = 0 ; h < help ; h++ ) {			c1 = tour[i];			c2 = tour[j];			tour[i] = c2;			tour[j] = c1;			pos[c1] = j;			pos[c2] = i;			i--; j++;			if ( i < 0 )			    i = n-1;			if ( j >= n )			    j = 0;		    }		    tour[n] = tour[0];		}	    } else {		dlb[c1] = TRUE;	    }      	}	if ( improvement_flag ) {	    n_improves++;	}    }    free( random_vector );    free( dlb );    free( pos );}void two_h_opt_first( long int *tour ) /*          FUNCTION:       2-h-opt a tour      INPUT:          pointer to the tour that undergoes local optimization      OUTPUT:         none      (SIDE)EFFECTS:  tour is 2-h-opt      COMMENTS:       for details on 2-h-opt see J. L. Bentley. Fast algorithms for geometric                       traveling salesman problems. ORSA Journal on Computing, 		      4(4):387--411, 1992. 		      The neighbourhood is scanned in random order (this need                       not be the best possible choice). Concerning the speed-ups used 		      here consult, for example, Chapter 8 of		      Holger H. Hoos and Thomas Stuetzle, 		      Stochastic Local Search---Foundations and Applications, 		      Morgan Kaufmann Publishers, 2004.		      or some of the papers online available from David S. Johnson.*/{    long int c1, c2;         /* cities considered for an exchange */    long int s_c1, s_c2;     /* successors of c1 and c2           */    long int p_c1, p_c2;     /* predecessors of c1 and c2         */       long int pos_c1, pos_c2;     /* positions of cities c1, c2        */    long int i, j, h, l;    long int improvement_flag, improve_node;    long int h1=0, h2=0, h3=0, h4=0, h5=0, help;    long int radius;             /* radius of nn-search */    long int gain = 0;    long int *random_vector;    long int two_move, node_move;    long int *pos;               /* positions of cities in tour */     long int *dlb;               /* vector containing don't look bits */       pos = malloc(n * sizeof(long int));    dlb = malloc(n * sizeof(long int));    for ( i = 0 ; i < n ; i++ ) {	pos[tour[i]] = i;	dlb[i] = FALSE;    }    improvement_flag = TRUE;    random_vector = generate_random_permutation( n );    while ( improvement_flag ) {	improvement_flag = FALSE; two_move = FALSE; node_move = FALSE;	for (l = 0 ; l < n; l++) {	    c1 = random_vector[l]; 	    DEBUG ( assert ( c1 < n && c1 >= 0); )		if ( dlb_flag && dlb[c1] )		    continue;	    improve_node = FALSE;	    pos_c1 = pos[c1];	    s_c1 = tour[pos_c1+1];	    radius = instance.distance[c1][s_c1];	    /* First search for c1's nearest neighbours, use successor of c1 */	    for ( h = 0 ; h < nn_ls ; h++ ) {		c2 = instance.nn_list[c1][h]; /* exchange partner, determine its position */		if ( radius > instance.distance[c1][c2] ) {		    pos_c2 = pos[c2];		    s_c2 = tour[pos_c2+1];		    gain =  - radius + instance.distance[c1][c2] + 			instance.distance[s_c1][s_c2] - instance.distance[c2][s_c2];		    if ( gain < 0 ) {			h1 = c1; h2 = s_c1; h3 = c2; h4 = s_c2; 			improve_node = TRUE; two_move = TRUE; node_move = FALSE;			goto exchange;		    }		    if (pos_c2 > 0)			p_c2 = tour[pos_c2-1];		    else 			p_c2 = tour[n-1];		    gain = - radius + instance.distance[c1][c2] + instance.distance[c2][s_c1]			+ instance.distance[p_c2][s_c2] - instance.distance[c2][s_c2]			- instance.distance[p_c2][c2]; 		    if ( c2 == s_c1 )			gain = 0;		    if ( p_c2 == s_c1 )			gain = 0;		    gain = 0;		    if ( gain < 0 ) {			h1 = c1; h2 = s_c1; h3 = c2; h4 = p_c2; h5 = s_c2; 			improve_node = TRUE; node_move = TRUE; two_move = FALSE;			goto exchange;		    }		}		else 		    break;	    }      	    /* Second search for c1's nearest neighbours, use predecessor c1 */	    if (pos_c1 > 0)		p_c1 = tour[pos_c1-1];	    else 		p_c1 = tour[n-1];	    radius = instance.distance[p_c1][c1];	    for ( h = 0 ; h < nn_ls ; h++ ) {		c2 = instance.nn_list[c1][h];  /* exchange partner, determine its position */		if ( radius > instance.distance[c1][c2] ) {		    pos_c2 = pos[c2];		    if (pos_c2 > 0)			p_c2 = tour[pos_c2-1];		    else 			p_c2 = tour[n-1];		    if ( p_c2 == c1 )			continue;		    if ( p_c1 == c2 )			continue;		    gain =  - radius + instance.distance[c1][c2] + 			instance.distance[p_c1][p_c2] - instance.distance[p_c2][c2];		    if ( gain < 0 ) {			h1 = p_c1; h2 = c1; h3 = p_c2; h4 = c2; 			improve_node = TRUE; two_move = TRUE; node_move = FALSE;			goto exchange;		    }		    s_c2 = tour[pos[c2]+1];		    gain = - radius + instance.distance[c2][c1] + instance.distance[p_c1][c2]			+ instance.distance[p_c2][s_c2] - instance.distance[c2][s_c2]			- instance.distance[p_c2][c2]; 		    if ( p_c1 == c2 )			gain = 0;		    if ( p_c1 == s_c2 )			gain = 0;		    if ( gain < 0 ) {			h1 = p_c1; h2 = c1; h3 = c2; h4 = p_c2; h5 = s_c2; 			improve_node = TRUE; node_move = TRUE; two_move = FALSE;			goto exchange;		    }		}		else 		    break;	    }      	exchange:	    if (improve_node) {		if ( two_move ) {		    improvement_flag = TRUE;		    dlb[h1] = FALSE; dlb[h2] = FALSE;		    dlb[h3] = FALSE; dlb[h4] = FALSE;		    /* Now perform move */		    if ( pos[h3] < pos[h1] ) {			help = h1; h1 = h3; h3 = help;			help = h2; h2 = h4; h4 = help;		    }		    if ( pos[h3] - pos[h2] < n / 2 + 1) {			/* reverse inner part from pos[h2] to pos[h3] */			i = pos[h2]; j = pos[h3];			while (i < j) {			    c1 = tour[i];			    c2 = tour[j];			    tour[i] = c2;			    tour[j] = c1;			    pos[c1] = j;			    pos[c2] = i;			    i++; j--;			}		    }		    else {			/* reverse outer part from pos[h4] to pos[h1] */			i = pos[h1]; j = pos[h4];			if ( j > i )			    help = n - (j - i) + 1;			else 			    help = (i - j) + 1;			help = help / 2;			for ( h = 0 ; h < help ; h++ ) {			    c1 = tour[i];			    c2 = tour[j];			    tour[i] = c2;			    tour[j] = c1;			    pos[c1] = j;			    pos[c2] = i;			    i--; j++;			    if ( i < 0 )				i = n-1;			    if ( j >= n )				j = 0;			}			tour[n] = tour[0];		    }		} else if ( node_move ) {		    improvement_flag = TRUE;		    dlb[h1] = FALSE; dlb[h2] = FALSE; dlb[h3] = FALSE; 		    dlb[h4] = FALSE; dlb[h5] = FALSE;		    /* Now perform move */		    if ( pos[h3] < pos[h1] ) {			help = pos[h1] - pos[h3];			i = pos[h3];			for ( h = 0 ; h < help ; h++ ) {			    c1 = tour[i+1];			    tour[i] = c1;			    pos[c1] = i;			    i++;			}			tour[i] = h3;			pos[h3] = i;			tour[n] = tour[0];		    } else {			/* pos[h3] > pos[h1] */ 			help = pos[h3] - pos[h1];			/*  	    if ( help < n / 2 + 1) { */			i = pos[h3];			for ( h = 0 ; h < help - 1 ; h++ ) {			    c1 = tour[i-1];			    tour[i] = c1;			    pos[c1] = i;			    i--;			}			tour[i] = h3;			pos[h3] = i;			tour[n] = tour[0];			/*  	  } */		    }  		} else {		    fprintf(stderr,"this should never occur, 2-h-opt!!\n"); 		    exit(0);		}		two_move = FALSE; node_move = FALSE;	    } else {		dlb[c1] = TRUE;	    }      	}    }    free( random_vector );    free( dlb );    free( pos );}void three_opt_first( long int *tour )/*          FUNCTION:       3-opt the tour      INPUT:          pointer to the tour that is to optimize      OUTPUT:         none      (SIDE)EFFECTS:  tour is 3-opt      COMMENT:        this is certainly not the best possible implementation of a 3-opt                       local search algorithm. In addition, it is very lengthy; the main 		      reason herefore is that awkward way of making an exchange, where 		      it is tried to copy only the shortest possible part of a tour. 		      Whoever improves the code regarding speed or solution quality, please 		      drop me the code at stuetzle no@spam informatik.tu-darmstadt.de		      The neighbourhood is scanned in random order (this need                       not be the best possible choice). Concerning the speed-ups used 		      here consult, for example, Chapter 8 of		      Holger H. Hoos and Thomas Stuetzle, 		      Stochastic Local Search---Foundations and Applications, 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产在线一区观看| 日韩不卡在线观看日韩不卡视频| 欧美日韩三级视频| 欧美性xxxxxx少妇| 欧美日韩dvd在线观看| 欧美日韩一区成人| 国产喷白浆一区二区三区| 国产精品免费视频观看| 亚洲色图欧美在线| 亚洲福利一二三区| 另类的小说在线视频另类成人小视频在线 | 国产精品久久久久久户外露出 | 国产一区二区三区香蕉| 成人妖精视频yjsp地址| 91九色02白丝porn| 日韩你懂的电影在线观看| 国产欧美日韩在线视频| 另类调教123区| 91精品福利在线一区二区三区| 欧美xxxxxxxx| 亚洲欧美在线另类| 日本一不卡视频| 欧美午夜精品一区二区蜜桃| 亚洲欧美一区二区不卡| 麻豆专区一区二区三区四区五区| 成人一级黄色片| 久久免费看少妇高潮| 亚洲午夜免费电影| 91黄视频在线观看| 亚洲风情在线资源站| 在线观看免费亚洲| 国产网红主播福利一区二区| 亚洲夂夂婷婷色拍ww47| 国产一区二区调教| 久久精品日韩一区二区三区| 国产精品12区| 日韩一卡二卡三卡| 亚洲国产欧美在线| 欧美三级日韩在线| 免费欧美日韩国产三级电影| 91官网在线观看| 亚洲成人在线免费| 色婷婷综合久色| 国产免费成人在线视频| 国产成人午夜99999| 国产精品卡一卡二卡三| 色国产精品一区在线观看| 亚洲一区二区欧美| 欧美一区二区三区白人| 麻豆成人av在线| 国产日产亚洲精品系列| 99久久婷婷国产| 中文字幕免费观看一区| 麻豆精品视频在线| 欧美高清在线精品一区| 一本到不卡精品视频在线观看| 亚洲第一久久影院| 欧美v日韩v国产v| 成人福利视频网站| 国产精品青草综合久久久久99| 一本久道中文字幕精品亚洲嫩| 五月婷婷综合激情| 欧美日韩国产在线观看| 国产乱妇无码大片在线观看| 精品欧美一区二区三区精品久久| 国产成人亚洲精品狼色在线| 一区二区视频免费在线观看| 国产乱码一区二区三区| 亚洲乱码国产乱码精品精小说 | 久久99精品国产.久久久久久 | 色素色在线综合| 男女性色大片免费观看一区二区| 国产精品美女视频| 欧美欧美午夜aⅴ在线观看| 国产精品一级在线| 亚洲国产日韩a在线播放性色| 26uuu另类欧美亚洲曰本| 加勒比av一区二区| 亚洲精品成人天堂一二三| 欧美一激情一区二区三区| kk眼镜猥琐国模调教系列一区二区 | 欧美亚洲图片小说| 国产在线精品一区二区夜色 | 亚洲欧洲色图综合| 日韩视频一区二区在线观看| 91视频国产资源| 一卡二卡三卡日韩欧美| 久久久夜色精品亚洲| 欧美精品 国产精品| 国产综合久久久久影院| 婷婷国产在线综合| 最新高清无码专区| 亚洲国产岛国毛片在线| 精品欧美久久久| 日韩小视频在线观看专区| 欧美天天综合网| 91在线无精精品入口| 成人免费视频国产在线观看| 韩国av一区二区三区在线观看| 日韩成人免费看| 五月天欧美精品| 亚洲高清不卡在线| 性感美女极品91精品| 一区二区高清在线| 亚洲精品免费看| 亚洲精品日韩一| 亚洲激情校园春色| 亚洲区小说区图片区qvod| 最新中文字幕一区二区三区 | 7799精品视频| 成人黄色片在线观看| 国产成人一区在线| 国产**成人网毛片九色 | 亚洲精品视频自拍| 亚洲色图一区二区| 一区二区在线电影| 亚洲一区欧美一区| 一区二区三区视频在线看| 亚洲与欧洲av电影| 日韩高清欧美激情| 蜜桃av一区二区| 国内成人免费视频| 成人一区二区三区视频| 99久久婷婷国产综合精品| 一本色道久久综合亚洲91| 欧美午夜精品免费| 日韩亚洲电影在线| ww久久中文字幕| 综合网在线视频| 性做久久久久久免费观看欧美| 日韩国产精品91| 国产一区二区剧情av在线| 成人污视频在线观看| 在线观看日韩毛片| 日韩一二三区视频| 日本一区二区久久| 亚洲国产日韩在线一区模特| 久久99久久99精品免视看婷婷 | 欧美女孩性生活视频| 日韩精品在线一区| 国产精品狼人久久影院观看方式| 一区二区三区高清不卡| 美女性感视频久久| 成人va在线观看| 欧美老人xxxx18| 久久精品亚洲精品国产欧美| 亚洲男女毛片无遮挡| 日本亚洲电影天堂| 国产91高潮流白浆在线麻豆| 欧美视频一区二区三区在线观看| 日韩欧美色综合网站| 亚洲日本一区二区| 免费的成人av| 色综合中文字幕国产| 成人美女视频在线观看18| 欧日韩精品视频| 久久综合久久鬼色中文字| 亚洲一区二区三区三| 韩国av一区二区| 欧美日本在线播放| 日本一区二区成人在线| 日本va欧美va瓶| 一本色道久久综合精品竹菊| 精品国产伦理网| 国产精品网站在线观看| 爽好久久久欧美精品| 九九九久久久精品| 91官网在线观看| 中文字幕中文字幕在线一区 | 国产精品美女久久久久久久| 日韩av成人高清| 日本乱人伦aⅴ精品| 国产视频一区二区在线| 日本不卡中文字幕| 欧美性大战久久久久久久蜜臀| 日韩电影在线免费看| 99re8在线精品视频免费播放| 精品美女在线播放| 三级一区在线视频先锋| 在线日韩一区二区| 亚洲欧美在线另类| 国产成人精品免费| 久久久影视传媒| 久久国产精品99精品国产| 欧美福利视频导航| 一区二区三区精品在线| 97久久超碰国产精品电影| 中日韩免费视频中文字幕| 国内精品国产成人| 精品va天堂亚洲国产| 另类小说图片综合网| 欧美一级高清片| 免费欧美高清视频| 欧美成人免费网站| 久久69国产一区二区蜜臀| 日韩一区二区在线观看| 青青草91视频| 欧美xxxxx牲另类人与| 国产一区日韩二区欧美三区| 精品sm捆绑视频|