當前位置:首頁 » 操作系統 » 禁忌搜索演算法

禁忌搜索演算法

發布時間: 2022-01-10 13:58:44

1. 約束條件是怎麼加入禁忌搜索演算法中的

組合優化是TS演算法應用最多的領域。置換問題,如TSP、調度問題等,是一大批組合優化問題的典型代表,在此用它來解釋簡單的禁忌搜索演算法的思想和操作。對於n元素的置換問題,其所有排列狀態數為n!,當n較大時搜索空間的大小將是天文數字,而禁忌

2. 禁忌搜索演算法源代碼

禁忌搜索法:使用一個禁忌表,記錄下不允許搜索的元素。在後面的搜索中,根據禁忌表來決定如何處理當前元素。用在約瑟夫環中,我們可以用一個數組記錄下已經出圈的人的編號,這樣再數數時,可以根據禁忌表來判斷此人是否還在圈內。

#define N 100
void yuesefu1(int data[],int result[],int sum,int k)
{
int i=0,j=0,count=0;
int n;
while(count<sum)
{
for(n=0;n<count;n++)/*根據禁忌表判斷此人是否還在圈內*/
if(result[n]==data[i])
break;
if(n>=count)/*若此人還在圈內*/
j++;
if(j==k)
{
result[count++]=data[i];/*把出圈的人的編號存入禁忌表*/
j=0;
}
i++;
if(i==sum)
i=0;
}
}

void main()
{
int data[N];
int result[N]={0};
int i,j,total,k;
printf("\nPlease input the number of every people.\n");
for(i=0;i<N;)
{
int input;
scanf("%d",&input);
if(input==0)
break;
for(j=0;j<i;j++)
if(data[j]==input)
break;
if(j>=i&&input>0)
{
data[i]=input;
i++;
}
else
printf("\nData error.Re-input:");
}
total=i;
printf("\nYou have input:\n");
for(i=0;i<total;i++)
{
if(i%10==0)
printf("\n");
printf("%4d",data[i]);
}
printf("\nPlease input a number to count:");
scanf("%d",&k);
yuesefu1(data,result,total,k);
printf("\nThe sequence is:\n");
for(i=0;i<total;i++)
printf("%d ",result[i]);

3. c++ 求禁忌搜索演算法與遺傳演算法結合的代碼

//個體編碼方案:十進制的數列,1至26代表A至Z
//交配方法:使用整數編碼的交配規則的常規交配法,
//變異方法 :使用基於次序的變異,隨機的產生兩個變異位,然後交換這兩個變異位上的基因
//新種群構成方法:輪盤賭法進行篩選
//演算法結束條件:種群不再發生變化時停止
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<cmath>
#include<time.h>
#define random(x) (rand()%x)//隨機整數
#define initial {0,2,11,1,8,16,5,19,12,4,15,17,6,18,14,9,7,3,10,13}//隨機初值

using namespace std;
//參數
int city_number;
double pm = 0.92;
double initiall = 280;//種群數量
double length_table[26][26];
double pc = 0.02;
struct node
{
char name;
int num;
double x;
double y;
};
struct answer
{
int i;
int jie[26];// 十進制的數列,1至26代表A至Z
double length;
};
double f(int* x)
{
double fi = 0;
for(int i = 0; i < city_number-1; i++)
{
fi = fi + length_table[x[i]][x[i+1]];
}
fi = fi + length_table[x[city_number-1]][x[0]];
return fi;
}
double p(double fi,double fj,double t)
{
double P = exp(-(fj-fi)/t);
return P;
}

int main(int argc,char*argv[])
{
time_t tm; time(&tm);
int flag1 = tm;
int cities;
ifstream in(argv[1]);
in >> cities;
city_number = cities;
node* nodes = new node[city_number];
for(int i = 0; i < cities; i++)
{
in >> nodes[i].name >> nodes[i].x >> nodes[i].y;
nodes[i].num = i;
}
//cout << cities<<endl;
//for(int i = 0; i < cities; i++)
// cout <<nodes[i].name <<" "<< nodes[i].x <<" "<< nodes[i].y<<endl;
int i,j;
for(i = 0; i < cities; i++)
{
length_table[i][i] = (double)INT_MAX;
for(j = i+1; j < cities; j++)
{
length_table [i][j] = length_table[j][i] =sqrt(
(nodes[i].x - nodes[j].x) * (nodes[i].x - nodes[j].x) +
(nodes[i].y - nodes[j].y) * (nodes[i].y - nodes[j].y) );
//cout << length_table [i][j]<<endl;
}
}
ofstream out(argv[2]);
///////////////////////////////////////////////////////////初始設定
double t= initiall;//種群數量
int* temp = new int[cities]; answer* Ans1 = new answer;//群體
answer* Ans2 = new answer;//種群
int text[20] = initial;
int* son1 = new int[cities];
int* son2 = new int[cities];
for(int i = 0; i < cities; i++) {
temp[i] = i; Ans1->jie[i] = temp[i];
Ans2->jie[i] = text[i];
//cout << Ans2->jie[i]<<endl;
}
Ans1->length = f(Ans1->jie);
Ans2->length = f(Ans2->jie);
if(cities<15)Ans2->length =10000;
//cout << Ans2->length;
Ans1->i = random(cities);
//cout <<Ans1->i<<endl;
int pre_length = 0;
//
while(Ans1->length!=pre_length)//種群不再發生變化時停止
{
time(&tm);
double fenmu = 0;//輪盤賭法進行選擇
for(int i = 0; i < cities*cities; i++)
{
fenmu = fenmu + 1/Ans1->length;
}
int j1 = 0;double s1 = 0;int r1 = rand();
while(s1*32767<=r1) { s1 = s1 + (1/Ans1->length)/fenmu; j1++; }
int j2 = 0;double s2 = 0;int r2 = rand();
while(s2*32767<=r2) { s2 = s2 + (1/Ans1->length)/fenmu; j2++; }
if(tm-flag1>270)break;
pre_length = Ans1->length;
for(int i = 0; i < 100*cities; i++)//
{
int j = random(cities);
int text = temp[Ans1->i]; temp[Ans1->i] = temp[j]; temp[j] = text;
double length = f(temp);//f(j)
if(length < Ans1->length)
{
Ans1->i = j;
for(int l = 0; l < cities; l++)
Ans1->jie[l] = temp[l];
Ans1->length = length;
}
else if(p(length,Ans1->length,t)*32767 > rand())
{
Ans1->i = j;
for(int l = 0; l < cities; l++)
Ans1->jie[l] = temp[l];
Ans1->length = length;
}
}
t = t * pm;int point = random(cities);
//使用整數編碼的交配規則的常規交配法
for(int z = 0;z < point;z++) { son1[z] = Ans1->jie[z]; son2[z] = Ans1->jie[z]; }
int text1 = point;int text2 = point;int flag = 0;
for(int x = 0;x < cities;x++)
{
flag =0;
for(int c = 0;c< point;c++)
{
if(Ans1->jie[x]==son1[c])flag=1;
}
if(flag==0){ son1[text1] = Ans1->jie[x]; text1++; }
}

for(int x = 0;x < cities;x++)
{
flag =0;
for(int c = 0;c< point;c++)
{
if(Ans1->jie[x]==son2[c])flag=1;
}
if(flag==0){ son2[text2] = Ans1->jie[x]; text2++; }
}
if(Ans1->length<Ans2->length)
{
for(int m = 0; m < cities; m++)
Ans2->jie[m] = Ans1->jie[m];
Ans2->length = Ans1->length;
}
}
for(int l = 0; l < cities; l++)
{
out << char(Ans2->jie[l]+65)<<" ";
}
out <<Ans2->length<<endl;
return 0;
}

4. 禁忌搜索演算法。能不能推薦一些禁忌搜索演算法的書籍

好冷門。。。。
卓越亞馬孫也許有

5. 什麼是禁忌搜索遺傳演算法

http://book.idoican.com.cn/detail/DefaultView.aspx?BookId=ISBN7-111-08090-4.1

6. 請問關於禁忌搜索演算法

禁忌(TabuSearch)演算法是一種亞啟發式(meta-heuristic)隨機搜索演算法[1],它從一個初始可行解出發,選擇一系列的特定搜索方向(移動)作為試探,選擇實現讓特定的目標函數值變化最多的移動。為了避免陷入局部最優解,TS搜索中採用了一種靈活的「記憶」技術,對已經進行的優化過程進行記錄和選擇,指導下一步的搜索方向,這就是Tabu表的建立。Tabu表中保存了最近若干次迭代過程中所實現的移動的反方向移動,凡是處於Tabu表中的移動,在當前迭代過程中是不允許實現的,這樣可以避免演算法重新訪問在最近若干次迭代過程中已經訪問過的解群,從而防止了循環,幫助演算法擺脫局部最優解。另外,為了盡可能不錯過產生最優解的「移動」,TS搜索還採用「釋放准則」的策略。

7. 禁忌搜索演算法能不能解決函數優化問題

總的思路就是建立禁忌表、鄰域、禁忌長度這一套結構,這些要看你具體解決什麼問題!
你的採納是我前進的動力!
記得好評和採納,答題不易,互相幫助,
手機提問的朋友在客戶端右上角評價點滿意即可.
如果你認可我的回答,請及時點擊採納為滿意回答按鈕!

8. 禁忌搜索演算法的主要思想和特徵

禁忌演算法是一種亞啟發式隨機搜索演算法1,它從一個初始可行解出發,選擇一系列的特定搜索方向(移動)作為試探,選擇實現讓特定的目標函數值變化最多的移動。為了避免陷入局部最優解,TS搜索中採用了一種靈活的「記憶」技術,對已經進行的優化過程進行記錄和選擇,指導下一步的搜索方向,這就是Tabu表的建立。 禁忌搜索是對人類思維過程本身的一種模擬,它通過對一些局部最優解的禁忌(也可以說是記憶)達到接納一部分較差解,從而跳出局部搜索的目的.

9. 禁忌搜索演算法的偽碼表達

procere tabu search;
begin
initialize a string vc at random,clear up the tabu list;
cur:=vc;
repeat
select a new string vn in the neighborhood of vc;
if va&gt;best_to_far then {va is a string in the tabu list}
begin
cur:=va;
let va take place of the oldest string in the tabu list;
best_to_far:=va;
end else
begin
cur:=vn;
let vn take place of the oldest string in the tabu list;
end;
until (termination-condition);
end;
以上程序中的關鍵在於: 禁忌對象:可以選取當前的值(cur)作為禁忌對象放進tabu list,也可以把和當前值在同一「等高線」上的都放進tabu list。 為了降低計算量,禁忌長度和禁忌表的集合不宜太大,但是禁忌長度太小容易循環搜索,禁忌表太大容易陷入「局部極優解」。 上述程序段中對best_so_far的操作是直接賦值為最優的「解禁候選解」,但是有時候會出現沒有大於best_so_far的,候選解也全部被禁的「死鎖」狀態,這個時候,就應該對候選解中最佳的進行解禁,以能夠繼續下去。 終止准則:和模擬退火,遺傳演算法差不多,常用的有:給定一個迭代步數;設定與估計的最優解的距離小於某個范圍時,就終止搜索;當與最優解的距離連續若干步保持不變時,終止搜索; 鄰域:由偽碼 select a new string vn in the neighborhood of vc,可以看出,系統總是在初始點的鄰域搜索可能解的,因而必須定義適合的鄰域空間,如果解空間存在一個最優解X*,初始搜索點為S0,那麼如果S0不存在到達X*的通路,就會使搜索陷入S0的鄰域的局部最優解。可以證明如果鄰域滿足對稱性條件,則在假設禁忌表足夠長的情況下必然可搜索到全局最優解。

10. 智能演算法,禁忌搜索演算法

好比線性解析式 y=kx,設置一個k,x的取值在[a,b],即可獲得所求的解。感覺像那麼回事。

熱點內容
單片機android 發布:2024-09-20 09:07:24 瀏覽:759
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:659
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:306
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:284
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:812
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:158
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:89
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:503
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:655
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:479