当前位置:首页 » 编程软件 » eil编译器怎么样

eil编译器怎么样

发布时间: 2022-06-29 21:30:57

㈠ VB或C++的蚁群算法源码

//建议使用vc2005以上的编译器,加油!!~!

#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;
}

㈡ keil5多大

因为KEIL是可以装在一起的,我装了KEIL2,KEIL3,KEIL4,对应的核心包括了C51和C251,目前总共大小是162M

_eil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上、结构性、可读性、可维护性上有明显的优势,因而易学易用。Keil提供了包括C编译器、宏汇编、链接器、库管理和一个功能强大的仿真调试器等在内的完整开发方案,通过一个集成开发环境(μVision)将这些部分组合在一起。运行Keil软件需要WIN98、NT、WIN2000、WINXP等操作系统。如果你使用C语言编程,那么Keil几乎就是你的不二之选,即使不使用C语言而仅用汇编语言编程,其方便易用的集成环境、强大的软件仿真调试工具也会令你事半功倍。

热点内容
交通银行怎么登陆不了密码 发布:2024-05-17 13:54:48 浏览:543
安卓如何自动连接无线 发布:2024-05-17 13:53:51 浏览:262
python的urlparse 发布:2024-05-17 13:44:20 浏览:769
linux命令全称 发布:2024-05-17 12:07:54 浏览:110
ftpnas区别 发布:2024-05-17 12:06:18 浏览:949
512g存储芯片价格 发布:2024-05-17 12:04:48 浏览:963
脚本运行周期 发布:2024-05-17 11:39:09 浏览:809
阿里云服务器怎么配置发信功能 发布:2024-05-17 11:37:24 浏览:313
编程中的变量 发布:2024-05-17 11:33:06 浏览:777
加密视频怎么解密 发布:2024-05-17 11:02:52 浏览:572