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

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

?? aco.txt

?? 蟻群算法 用來求解旅行商問題的經典算法
?? TXT
字號:
C/C++ code
#include <stdio.h>
#include <cmath>
#include <iostream> 
#include <fstream>
#include <time.h>
using namespace std; 

const int iAntCount=34;//螞蟻數量 
const int iCityCount=51;//城市數量 
const int iItCount=2000;//最大跌代次數 
const double Q=100; 
const double alpha=1; 
const double beta=5; 
const double rou=0.5; 

int besttour[iCityCount];//最有路徑列表 

double  rnd(int low,double uper)//獲得隨機數 
{ 
    double p=(rand()/(double)RAND_MAX)*((uper)-(low))+(low); 
    return (p); 
}; 
int rnd(int uper) 
{ 
    return (rand()%uper); 
}; 
class GInfo//tsp地圖信息,包含了信息素,城市距離,和信息素變化矩陣 
{ 
public: 
    double m_dDeltTrial[iCityCount][iCityCount]; 
    double m_dTrial[iCityCount][iCityCount]; 
    double distance[iCityCount][iCityCount]; 

}; 
GInfo Map; 
class ant 
{ 
private: 
    int ChooseNextCity();//選擇城市 
    double prob[iCityCount]; 
    int m_iCityCount; 
    int AllowedCity[iCityCount];//沒有走過的城市 
public: 
    void addcity(int city); 
    int tabu[iCityCount]; 
    void Clear(); 
    void UpdateResult(); 
    double m_dLength; 
    double m_dShortest; 
    void move(); 
    ant(); 
    void move2last(); 

}; 
void ant::move2last() 
{ 
    int i; 
    for(i=0;i<iCityCount;i++) 

        if (AllowedCity[i]==1) 
        { 
            addcity(i); 
            break; 
        } 
} 

void ant::Clear() 
{ 
    m_dLength=0; 
    int i; 
    for(i=0; i<iCityCount;i++) 
    { 
        prob[i]=0; 
        AllowedCity[i]=1; 
        i=tabu[iCityCount-1]; 
        m_iCityCount=0; 
        addcity(i); 
    } 
} 
ant::ant() 
{ 
    m_dLength=m_dShortest=0; 
    m_iCityCount=0; 
    int i; 
    for(i=0;i<iCityCount;i++) {

        AllowedCity[i]=1; 
        prob[i]=0; 
    } 
} 
void ant::addcity(int city) 
{ 
    //add city to tabu; 
    tabu[m_iCityCount]=city; 
    m_iCityCount++; 
    AllowedCity[city]=0; 
} 
int ant::ChooseNextCity() 
{ 
    //Update the probability of path selection 
    //select a path from tabu[m_iCityCount-1] to next
    int i; 
    int j=10000; 
    double temp=0; 
    int curCity=tabu[m_iCityCount-1]; 
    for (i=0;i<iCityCount;i++) {

        if((AllowedCity[i]==1)) 
        { 
            temp+=pow((1.0/Map.distance[curCity][i]),beta)*pow((Map.m_dTrial[curCity][i]),alpha); 
        } 
    }
    double sel=0; 
    for (i=0;i<iCityCount;i++) {

        if((AllowedCity[i]==1)) 
        { 
            prob[i]=pow((1.0/Map.distance[curCity][i]),(int)beta)*pow((Map.m_dTrial[curCity][i]),(int)alpha)/temp; 
            sel+=prob[i]; 
        } 
        else 
            prob[i]=0; 
    } 
    double mRate=rnd(0,sel); 
    double mSelect=0; 
    for ( i=0;i<iCityCount;i++) {

        if((AllowedCity[i]==1)) 
            mSelect+=prob[i] ; 
        if (mSelect>=mRate) {j=i;break;} 
    } 
    if (j==10000) 
    { 
        temp=-1; 
        for (i=0;i<iCityCount;i++) {

            if((AllowedCity[i]==1)) 
                if (temp)   { 
                    temp=pow((1.0/Map.distance[curCity][i]),beta)*pow((double)(Map.m_dTrial[curCity][i]),alpha); 
                    j=i; 
                } 
        } 
    } 
    return j; 
} 
void ant::UpdateResult() 
{ 
    // Update the length of tour 
    int i; 
    for(i=0;i<iCityCount-1;i++) 

        m_dLength+=Map.distance[tabu[i]][tabu[i+1]]; 
    m_dLength+=Map.distance[tabu[iCityCount-1]][tabu[0]]; 
} 
void ant::move() 
{ 
    //the ant move to next town and add town ID to tabu. 
    int j; 
    j=ChooseNextCity(); 
    addcity(j); 
} 
class project 
{ 
public: 
    void UpdateTrial(); 
    double m_dLength; 
    void initmap(); 
    ant ants[iAntCount]; 
    void GetAnt(); 
    void StartSearch(); 
    project(); 
}; 
void project::UpdateTrial() 
{ 
    //calculate the changes of trial information 
    int i; 
    int j; 
    for(i=0;i<iAntCount;i++) {
        for (j=0;j<iCityCount-1;j++) 
        {  
            Map.m_dDeltTrial[ants[i].tabu[j]][ants[i].tabu[j+1]]+=Q/ants[i].m_dLength ; 
            Map.m_dDeltTrial[ants[i].tabu[j+1]][ants[i].tabu[j]]+=Q/ants[i].m_dLength; 
        } 
        Map.m_dDeltTrial[ants[i].tabu[iCityCount-1]][ants[i].tabu[0]]+=Q/ants[i].m_dLength; 
        Map.m_dDeltTrial[ants[i].tabu[0]][ants[i].tabu[iCityCount-1]]+=Q/ants[i].m_dLength; 
    } 
    for (i=0;i<iCityCount;i++) {
        for (j=0;j<iCityCount;j++) 
        { 
            Map.m_dTrial[i][j]=(rou*Map.m_dTrial[i][j]+Map.m_dDeltTrial[i][j] ); 
            Map.m_dDeltTrial[i][j]=0; 
        } 
    } 
} 
void project::initmap() 
{ 
    int i; 
    int j; 
    for(i=0;i<iCityCount;i++) 
        for (j=0;j<iCityCount;j++) 
        { 


            Map.m_dTrial[i][j]=1; 
            Map.m_dDeltTrial[i][j]=0; 
        } 
} 
project::project() 
{ 
    //initial map,read map infomation from file . et. 
    initmap(); 
    m_dLength=10e9; 


    ifstream in("eil51.tsp"); 

    struct city 
    { 
        int num; 
        int x; 
        int  y; 
    }cc[iCityCount]; 

    for (int i=0;i<iCityCount;i++) 
    { 
        in>>cc[i].num>>cc[i].x>>cc[i].y; 
        besttour[i]=0; 
    } 
    int j; 
    for(int i=0;i<iCityCount;i++) 
        for (j=0;j<iCityCount;j++) 
        { 
            { 
                Map.distance[i][j]=sqrt(pow((double)(cc[i].x-cc[j].x),2)+pow((double)(cc[i].y-cc[j].y),2)); 
            } 
        } 
} 
void project::GetAnt() 
{ 
    //randomly put ant into map 
    int i=0; 
    int city; 
    srand( (unsigned)time( NULL ) +rand()); 
    for (i=0;i<iAntCount;i++) 
    { 
        city=rnd(iCityCount); 
        ants[i].addcity(city); 
    } 
} 
void project::StartSearch() 
{ 
    //begin to find best solution 
    int max=0;//every ant tours times 
    int i; 
    int j; 
    double temp; 
    int temptour[iCityCount]; 
    while (max<iItCount) 
    {  
        for(j=0;j<iAntCount;j++) 
        { 
            for (i=0;i<iCityCount-1;i++) 
                ants[j].move(); 
        } 
        for(j=0;j<iAntCount;j++) 
        {  ants[j].move2last(); 
        ants[j].UpdateResult (); 
        } 
        //find out the best solution of the step and put it into temp 
        int t; 
        temp=ants[0].m_dLength; 
        for (t=0;t<iCityCount;t++) 
            temptour[t]=ants[0].tabu[t]; 
        for(j=0;j<iAntCount;j++) 
        { 
            if (temp>ants[j].m_dLength) { 
                temp=ants[j].m_dLength; 
                for ( t=0;t<iCityCount;t++) 
                    temptour[t]=ants[j].tabu[t]; 
            } 
        }
        if(temp<m_dLength){ 
            m_dLength=temp; 
            for ( t=0;t<iCityCount;t++) 
                besttour[t]=temptour[t]; 
        } 
        printf("%d : %f\n",max,m_dLength); 
        UpdateTrial(); 
        for(j=0;j<iAntCount;j++) 
            ants[j].Clear(); 
        max++; 
    } 
    printf("The shortest toure is : %f\n",m_dLength); 
    for ( int t=0;t<iCityCount;t++) 
        printf(" %d ",besttour[t]); 
} 
int main() 
{ 
    project TSP; 
    TSP.GetAnt(); 
    TSP.StartSearch(); 
    return 0; 
} 

 
 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www一区二区| 日本成人在线电影网| 午夜av电影一区| 国产91精品久久久久久久网曝门 | 亚洲卡通欧美制服中文| 欧美aⅴ一区二区三区视频| av在线综合网| 久久久久久久久久久久电影| 亚洲午夜一二三区视频| eeuss鲁片一区二区三区在线观看| 日韩欧美国产电影| 91久久一区二区| 久久久精品tv| 激情国产一区二区| 欧美一级爆毛片| 99精品欧美一区二区三区小说| 精品美女在线观看| 日本中文字幕一区| 欧美精品在线观看播放| 亚洲伊人伊色伊影伊综合网| 成人黄色片在线观看| 精品美女在线播放| 免费在线视频一区| 日韩情涩欧美日韩视频| 日韩精品一区第一页| 欧美高清视频一二三区 | 国产一区二区精品在线观看| 欧美一二区视频| 蜜芽一区二区三区| 91麻豆精品久久久久蜜臀| 亚洲国产美女搞黄色| 欧美日韩黄色一区二区| 亚洲一区精品在线| 欧美三级乱人伦电影| 伊人开心综合网| 在线国产亚洲欧美| 亚洲成av人影院| 欧美精品一卡两卡| 麻豆精品在线观看| 亚洲精品在线观看视频| 精久久久久久久久久久| 2欧美一区二区三区在线观看视频| 精品一区二区国语对白| 国产视频一区在线观看| 丁香婷婷综合五月| 综合久久久久久久| 欧美日韩精品欧美日韩精品一| 午夜精品福利一区二区三区av | 奇米色一区二区三区四区| 在线不卡免费欧美| 狠狠色丁香九九婷婷综合五月| 欧美一激情一区二区三区| 麻豆中文一区二区| 久久久99久久| 91欧美一区二区| 性做久久久久久| 久久午夜羞羞影院免费观看| 国产99久久久国产精品潘金网站| 日韩一区在线免费观看| 欧美日韩国产大片| 国产一区二区三区高清播放| 亚洲人成网站影音先锋播放| 在线一区二区三区四区| 日本最新不卡在线| 中文字幕精品三区| 欧美三级韩国三级日本一级| 国产一区二区精品久久91| 亚洲欧洲制服丝袜| 欧美一区二区三区四区在线观看 | 欧美日韩国产123区| 国产一区二区精品久久99| 日韩美女啊v在线免费观看| 欧美高清激情brazzers| 丁香婷婷综合网| 午夜成人免费电影| 国产精品国产三级国产有无不卡 | 欧美日韩国产一级| 国产精品综合在线视频| 亚洲最大的成人av| 亚洲国产成人一区二区三区| 欧美日韩国产不卡| 91麻豆免费看| 国产主播一区二区| 无吗不卡中文字幕| 亚洲视频中文字幕| 国产午夜亚洲精品午夜鲁丝片 | 天堂午夜影视日韩欧美一区二区| 亚洲国产精品成人久久综合一区| 欧美精品一二三| 99久久精品国产毛片| 麻豆国产欧美一区二区三区| 亚洲国产一二三| 国产精品三级视频| 精品国产三级a在线观看| 欧美午夜寂寞影院| 91在线观看下载| 国产成人午夜片在线观看高清观看| 亚洲v精品v日韩v欧美v专区| 亚洲美女屁股眼交| 国产精品萝li| 亚洲国产精品99久久久久久久久| 日韩欧美黄色影院| 6080yy午夜一二三区久久| 91蝌蚪porny九色| 成人av午夜影院| 国产乱对白刺激视频不卡| 免费看日韩精品| 亚洲国产视频一区| 亚洲精品成人在线| 综合分类小说区另类春色亚洲小说欧美| 久久一区二区三区四区| 欧美刺激脚交jootjob| 日韩欧美一级特黄在线播放| 91精品国产一区二区三区香蕉| 欧美在线高清视频| 色婷婷国产精品| 91福利在线免费观看| 欧洲日韩一区二区三区| 欧美日韩综合不卡| 欧美精品tushy高清| 欧美一区二区三区人| 亚洲成人精品一区二区| 无码av免费一区二区三区试看 | 紧缚奴在线一区二区三区| 久久99国产精品久久99| 经典三级在线一区| 成人中文字幕合集| 99久久婷婷国产| 在线观看国产91| 3d动漫精品啪啪| 久久香蕉国产线看观看99| 久久精品亚洲一区二区三区浴池| 国产欧美日韩精品一区| √…a在线天堂一区| 亚洲一区二区三区三| 午夜精品视频一区| 国产在线精品一区二区不卡了| 激情都市一区二区| av电影在线不卡| 欧美亚洲图片小说| 日韩你懂的在线播放| 国产农村妇女毛片精品久久麻豆 | 亚洲韩国一区二区三区| 免费观看一级欧美片| 国产乱码精品一品二品| 99国产精品久久久久| 欧美日韩精品欧美日韩精品| 欧美成人性战久久| 中文字幕一区二区三| 午夜国产精品影院在线观看| 国产成人免费在线视频| 在线看一区二区| 欧美精品一区二区三区蜜桃视频| 亚洲人亚洲人成电影网站色| 日韩福利电影在线观看| 成人精品免费看| 91麻豆精品国产91久久久资源速度| 久久嫩草精品久久久久| 亚洲风情在线资源站| 国产精品亚洲专一区二区三区| 欧美三级视频在线| 久久久午夜精品| 日韩精品福利网| 91片在线免费观看| 精品欧美一区二区三区精品久久 | 天天av天天翘天天综合网 | 国产精品久久久99| 蜜桃在线一区二区三区| 91亚洲大成网污www| 久久久综合视频| 日韩精品亚洲一区| 91啪亚洲精品| 欧美激情一区三区| 精品亚洲国产成人av制服丝袜| 在线免费亚洲电影| 国产精品美女久久久久av爽李琼 | 日韩精品一区二区三区四区| 国产精品久久久久久久久晋中 | 中文字幕av资源一区| 久久不见久久见免费视频7| 色域天天综合网| 欧美激情一区在线观看| 激情文学综合丁香| 欧美一级片在线看| 丝袜亚洲另类欧美| 91久久精品网| 亚洲男同性视频| 专区另类欧美日韩| av成人动漫在线观看| 成人欧美一区二区三区黑人麻豆| 免费在线观看一区| 精品国产伦一区二区三区免费 | 欧美日韩一区二区三区视频| 国产精品乱码一区二三区小蝌蚪| 白白色 亚洲乱淫| 一区二区在线观看不卡| 欧美视频完全免费看| 日韩国产精品大片| 国产精品灌醉下药二区| 在线精品观看国产|