資源簡介
MATALAB
java
C++
源碼都有,好資源
源碼都有,好資源
源碼都有,好資源
還包含PPT,文檔,共33.9MB
代碼片段和文件信息
public?class?GA?{
private?int?ChrNum?=?10; //染色體數量
private?String[]?ipop?=?new?String[ChrNum]; ? //一個種群中染色體總數
private?int?generation?=?0;? //染色體代號
public?static?final?int?GENE?=?46;? //基因數
private?double?bestfitness?=?Double.MAX_VALUE;??//函數最優解
private?int?bestgenerations;??? //所有子代與父代中最好的染色體
private?String?beststr;??? //最優解的染色體的二進制碼
/**
?*?初始化一條染色體(用二進制字符串表示)
?*/
private?String?initChr()?{
String?res?=?““;
for?(int?i?=?0;?i? if?(Math.random()?>?0.5)?{
res?+=?“0“;
}?else?{
res?+=?“1“;
}
}
return?res;
}
/**
?*?初始化一個種群(10條染色體)
?*/
private?String[]?initPop()?{
String[]?ipop?=?new?String[ChrNum];
for?(int?i?=?0;?i? ipop[i]?=?initChr();
}
return?ipop;
}
/**
?*?將染色體轉換成xy變量的值
?*/
private?double[]?calculatefitnessvalue(String?str)?{
//二進制數前23位為x的二進制字符串,后23位為y的二進制字符串
int?a?=?Integer.parseInt(str.substring(0?23)?2);??????
int?b?=?Integer.parseInt(str.substring(23?46)?2);
double?x?=??a?*?(6.0?-?0)?/?(Math.pow(2?23)?-?1);????//x的基因
double?y?=??b?*?(6.0?-?0)?/?(Math.pow(2?23)?-?1);????//y的基因
//需優化的函數
double?fitness?=?3?-?Math.sin(2?*?x)?*?Math.sin(2?*?x)?
-?Math.sin(2?*?y)?*?Math.sin(2?*?y);
double[]?returns?=?{?x?y?fitness?};
return?returns;
}
/**
?*?輪盤選擇
?*?計算群體上每個個體的適應度值;?
?*?按由個體適應度值所決定的某個規則選擇將進入下一代的個體;
?*/
private?void?select()?{
double?evals[]?=?new?double[ChrNum];?//?所有染色體適應值
double?p[]?=?new?double[ChrNum];?//?各染色體選擇概率
double?q[]?=?new?double[ChrNum];?//?累計概率
double?F?=?0;?//?累計適應值總和
for?(int?i?=?0;?i? evals[i]?=?calculatefitnessvalue(ipop[i])[2];
if?(evals[i]? bestfitness?=?evals[i];
bestgenerations?=?generation;
beststr?=?ipop[i];
}
F?=?F?+?evals[i];?//?所有染色體適應值總和
}
for?(int?i?=?0;?i? p[i]?=?evals[i]?/?F;
if?(i?==?0)
q[i]?=?p[i];
else?{
q[i]?=?q[i?-?1]?+?p[i];
}
}
for?(int?i?=?0;?i? double?r?=?Math.random();
if?(r?<=?q[0])?{
ipop[i]?=?ipop[0];
}?else?{
for?(int?j?=?1;?j? if?(r? ipop[i]?=?ipop[j];
}
}
}
}
}
/**
?*?交叉操作?交叉率為60%,平均為60%的染色體進行交叉
?*/
private?void?cross()?{
String?temp1?temp2;
for?(int?i?=?0;?i? if?(Math.random()?0.60)?{
int?pos?=?(int)(Math.random()*GENE)+1;?????//pos位點前后二進制串交叉
temp1?=?ipop[i].substring(0?pos)?+?ipop[(i?+?1)?%?ChrNum].substring(pos);?
temp2?=?ipop[(i?+?1)?%?ChrNum].substring(0?pos)?+?ipop[i].substring(pos);
ipop[i]?=?temp1;
ipop[(i?+?1)?/?ChrNum]?=?temp2;
}
}
}
/**
?*?基因突變操作?1%基因變異
?*/
private?void?mutation()?{
for?(int?i?=?0;?i?4;?i++)?{
int?num?=?(int)?(Math.random()?*?GENE?*?ChrNum?+?1);
int?chromosomeNum?=?(int)?(num?/?GENE)?+?1;?//?染色體號
int?mutationNum?=?num?-?(chromosom
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-02-23?19:51??遺傳算法多份源碼\
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\
?????文件?????????301??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\.classpath
?????文件?????????378??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\.project
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\.settings\
?????文件?????????598??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\bin\
?????文件??????????10??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\bin\.gitignore
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\doc\
?????文件?????????571??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\allclasses-fr
?????文件?????????551??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\allclasses-nofr
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\doc\class-use\
?????文件????????3538??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\class-use\GA.html
?????文件????????4239??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\constant-values.html
?????文件????????3329??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\deprecated-list.html
?????文件????????8299??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\GA.html
?????文件????????6940??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\help-doc.html
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\doc\index-files\
?????文件????????4028??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\index-files\index-1.html
?????文件????????3722??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\index-files\index-2.html
?????文件????????2416??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\index.html
?????文件????????3532??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\overview-tree.html
?????文件?????????687??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\package-fr
?????文件???????????2??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\package-list
?????文件????????3752??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\package-summary.html
?????文件????????3541??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\package-tree.html
?????文件????????3409??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\package-use.html
?????目錄???????????0??2019-02-23?19:39??遺傳算法多份源碼\Ga\GA-master\doc\resources\
?????文件????????2313??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\resources\background.gif
?????文件?????????291??2016-08-07?22:29??遺傳算法多份源碼\Ga\GA-master\doc\resources\tab.gif
............此處省略554個文件信息
- 上一篇:含數據庫java酒店管理系統
- 下一篇:Android推箱子詳細源碼(僅供參考)
評論
共有 條評論