Skip to content

Commit

Permalink
引入遗传算法
Browse files Browse the repository at this point in the history
引入遗传算法,使用行为执行策略,若执行交配操作,则将两种群的最优解进行杂交
  • Loading branch information
PandaPYH committed Apr 17, 2013
1 parent 7a26078 commit 4cbe092
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 53 deletions.
44 changes: 44 additions & 0 deletions TspShow/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion TspShow/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ private void button1_Click(object sender, EventArgs e)
Common.CAnt_1List.Clear();
Common.CAnt_2List.Clear();
Common.ALPHA_1 = Convert.ToDouble(textBox1.Text);
Common.BETA_2 = Convert.ToDouble(textBox2.Text);
Common.BETA_1 = Convert.ToDouble(textBox2.Text);
Common.ALPHA_2 = Convert.ToDouble(textBox3.Text);
Common.BETA_2 = Convert.ToDouble(textBox4.Text);
MTsp mtsp = new MTsp();
mtsp.InitData();
mtsp.Search();
Expand Down
18 changes: 9 additions & 9 deletions ant_C/AO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ static void Main(string[] args)
// strInfo = String.Format("{0} ", tsp.m_cBestAnt.m_nPath[i] + 1);
// Console.Write(strInfo);
//}
//double length;
//double avglength = 0.0;
//for (int i = 0; i < 10; i++)
//{
double length;
double avglength = 0.0;
for (int i = 0; i < 10; i++)
{
MTsp mtsp = new MTsp();
mtsp.InitData();
mtsp.Search();
// length = mtsp.m_cBestAnt.m_dbPathLength;
// Console.WriteLine("[{0}]: {1}", i, length);
// avglength += length;
//}
length = mtsp.m_cBestAnt.m_dbPathLength;
Console.WriteLine("[{0}]: {1}", i, length);
avglength += length;
}

//Console.WriteLine("avg: {0}", avglength / 10);
Console.WriteLine("avg: {0}", avglength / 10);


Console.Read();
Expand Down
8 changes: 5 additions & 3 deletions ant_C/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ public class Common
public static double BETA = 3.0; //期望因子,城市间距离的重要程度

public static double ALPHA_1 = 1.0; //种群1启发因子,信息素的重要程度
public static double BETA_1 = 5.0; //种群1期望因子,城市间距离的重要程度
public static double BETA_1 = 2.0; //种群1期望因子,城市间距离的重要程度

public static double ALPHA_2 = 2.0; //种群2启发因子,信息素的重要程度
public static double BETA_2 = 7.0; //种群2期望因子,城市间距离的重要程度
public static double BETA_2 = 5.0; //种群2期望因子,城市间距离的重要程度

public static double ROU = 0.7; //信息素残留参数
public static double ROU = 0.8; //信息素残留参数

public static int N_ANT_COUNT = 40; //蚂蚁数量
public static int N_IT_COUNT = 1000; //迭代次数
public static int N_CITY_COUNT = 51; //城市数量

public static TSPpoint[] tspPoint = new TSPpoint[N_CITY_COUNT];
public static double DBQ = 100.0; //总的信息素
//public static double DBQ1 = 50000.0;
//public static double DBQ2 = 20000.0;
public static double DB_MAX = 10e9; //一个标志数,10的9次方
public static string filePath = "D:\\eil51.tsp";

Expand Down
Loading

0 comments on commit 4cbe092

Please sign in to comment.