資源簡介
遺傳算法最短路徑c#實現

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
namespace?simpleGA
{
????public?partial?class?Form1?:?Form
????{
????????Bitmap?image;
????????Graphics?formGraphics;
????????double?Max_ratio;//圖像放大比率
????????static?int?max?=?101;
????????static?int?maxqvehicle?=?1024;
????????static?int?maxdvehicle?=?1024;
????????Random?ra;
????????int?K;//最多使用車數目
????????int?KK;//實際使用車數
????????int?L;//客戶數目染色體長度
????????double?Pw;//?W1?W2?W3;//懲罰權重
????????double?Pc?Pm;//交叉概率和變異概率
????????int?scale;//種群規模
????????int?T;//進化代數
????????int?t;//當前代數
????????int[]?bestGh?=?new?int[max];//所有代數中最好的染色體
????????double[]?timeGh?=?new?double[max];//所有代數中最好的染色體
????????double?bestEvaluation;//所有代數中最好的染色體的適應度
????????int?bestT;//最好的染色體出現的代數
????????double?decodedEvaluation;//解碼后所有車輛所走路程總和........................
????????double[]?vehicle?=?new?double[max?3];//K下標從1開始到K,0列表示車的最大載重量,1列表示車行駛的最大距離,2列表示速度
????????int[]?decoded?=?new?int[max];//染色體解碼后表達的每輛車的服務的客戶的順序
????????double[]?guest_distance?=?new?double[max?max];//客戶距離
????????double[]?guest_weight?=?new?double[max];//客戶需求量
????????int[]?oldGroup?=?new?int[max?max];//初始種群,父代種群,行數表示種群規模,一行代表一個個體,即染色體,列表示染色體基因片段
????????int[]?newGroup?=?new?int[max?max];//新的種群,子代種群
????????double[]?Fitness?=?new?double[max];//種群適應度,表示種群中各個個體的適應度
????????double[]?Pi?=?new?double[max];//種群中各個個體的累計概率
????????double[]?x1?=?new?double[max];
????????double[]?y1?=?new?double[max];
????????//初始化函數
????????void?initdata()
????????{
????????????int?i?j;
????????????Max_ratio?=?20;//圖像顯示比例
????????????decodedEvaluation?=?0;//解碼后所有車輛所走路程總和
????????????Pw?=?300;//車輛超額懲罰權重
????????????L?=?20;//客戶數目染色體長度
????????????K?=?5;//最大車數目
????????????scale?=?100;//種群規模
????????????Pc?=?0.9;//交叉概率
????????????Pm?=?0.9;//變異概率,實際為(1-Pc)*0.9=0.09
????????????T?=?400;//進化代數
????????????bestEvaluation?=?0;//所有代數中最好的染色體的適應度
????????//車輛最大載重和最大行駛
????????vehicle[10]=8.0;
????????vehicle[11]=50.0;
????????vehicle[20]=8.0;
????????vehicle[21]=50.0;
????????vehicle[30]=8.0;
????????vehicle[31]=50.0;
????????vehicle[40]=8.0;
????????vehicle[41]=50.0;
????????vehicle[50]=8.0;
????????vehicle[51]=50.0;
????????????vehicle[6?0]?=?maxqvehicle;//限制最大
????????????vehicle[6?1]?=?maxdvehicle;
????????????//客戶坐標
????????x1[0]=14.5;y1[0]=13.0;guest_weight[0]=0.0;
????????x1[1]=12.8;y1[1]=8.5;guest_weight[1]=0.1;
????????x1[2]=18.4;y1[2]=3.4;guest_weight[2]=0.4;
????????x1[3]=15.4;y1[3]=16.6;guest_weight[3]=1.2;
????????x1[4]=18.9;y1[4]=15.2;guest_weight[4]=1.5;
????????x1[5]=15.5;y1[5]=11.6;guest_weight[5]=0.8;
????????x1[6]=3.9;y1[6]=10.6;guest_weight[6]=1.3;
????????x1[7]=10.6;y1[7]=7.6;guest_weight[7]=1.7;
????????x1[8]=8.6;y1[8]=8.4;guest_weight[8]=0.6;
????????x1[9]=12.5;y1[9]=2.1;guest_weig
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-01-20?10:57??simpleGA\
?????目錄???????????0??2017-01-20?10:57??simpleGA\.vs\
?????目錄???????????0??2017-01-20?10:57??simpleGA\.vs\simpleGA\
?????目錄???????????0??2017-01-20?10:57??simpleGA\.vs\simpleGA\v14\
?????文件???????13312??2012-06-14?21:49??simpleGA\.vs\simpleGA\v14\.suo
?????目錄???????????0??2017-01-20?10:57??simpleGA\Backup\
?????目錄???????????0??2017-01-20?10:57??simpleGA\Backup\simpleGA\
?????文件???????24572??2012-06-15?00:37??simpleGA\Backup\simpleGA\Form1.cs
?????文件???????14011??2012-06-15?00:37??simpleGA\Backup\simpleGA\Form1.Designer.cs
?????文件????????5814??2012-06-15?00:37??simpleGA\Backup\simpleGA\Form1.resx
?????文件?????????489??2012-06-14?14:52??simpleGA\Backup\simpleGA\Program.cs
?????目錄???????????0??2017-01-20?10:57??simpleGA\Backup\simpleGA\Properties\
?????文件????????1372??2012-06-14?14:52??simpleGA\Backup\simpleGA\Properties\AssemblyInfo.cs
?????文件????????2866??2012-06-14?14:52??simpleGA\Backup\simpleGA\Properties\Resources.Designer.cs
?????文件????????5612??2012-06-14?14:52??simpleGA\Backup\simpleGA\Properties\Resources.resx
?????文件????????1093??2012-06-14?14:52??simpleGA\Backup\simpleGA\Properties\Settings.Designer.cs
?????文件?????????249??2012-06-14?14:52??simpleGA\Backup\simpleGA\Properties\Settings.settings
?????文件????????3762??2012-06-14?16:58??simpleGA\Backup\simpleGA\simpleGA.csproj
?????文件?????????914??2012-06-14?14:52??simpleGA\Backup\simpleGA.sln
?????目錄???????????0??2012-06-15?00:37??simpleGA\simpleGA\
?????目錄???????????0??2012-06-14?14:52??simpleGA\simpleGA\bin\
?????目錄???????????0??2012-06-14?16:59??simpleGA\simpleGA\bin\Debug\
?????文件???????20992??2017-01-20?10:58??simpleGA\simpleGA\bin\Debug\simpleGA.exe
?????文件???????36352??2017-01-20?10:58??simpleGA\simpleGA\bin\Debug\simpleGA.pdb
?????文件???????21680??2017-01-20?10:58??simpleGA\simpleGA\bin\Debug\simpleGA.vshost.exe
?????文件?????????490??2016-07-16?19:44??simpleGA\simpleGA\bin\Debug\simpleGA.vshost.exe.manifest
?????文件???????24572??2012-06-15?00:37??simpleGA\simpleGA\Form1.cs
?????文件???????14011??2012-06-15?00:37??simpleGA\simpleGA\Form1.Designer.cs
?????文件????????5814??2012-06-15?00:37??simpleGA\simpleGA\Form1.resx
?????目錄???????????0??2012-06-14?14:52??simpleGA\simpleGA\obj\
?????目錄???????????0??2017-01-20?10:58??simpleGA\simpleGA\obj\Debug\
............此處省略21個文件信息
評論
共有 條評論