91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 17KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-02
  • 語言: Java
  • 標簽: 算法??

資源簡介

用遺傳算法解決多維背包問題,采用java代碼。用遺傳算法解決多維背包問題,采用java代碼用遺傳算法解決多維背包問題,采用java代碼用遺傳算法解決多維背包問題,采用java代碼。

資源截圖

代碼片段和文件信息

import?java.util.Random;

public?class?Chromosome?implements?GA_ParamCloneable{
private?int?gene[];
private?int?fitness;
private?int?objValue;

/**
?*?Constructor
?*?@param?length:?The?length?of?Chromosome‘s?gene.
?*/
public?Chromosome(int?length){
if(length<0){
System.out.println(“The?length?of?array?is?unreasonable.“);
}
else{
this.gene=new?int[length];
}
}

/**
?*?Deep?Clone!!!
?*/
@Override??
????public?Chromosome?clone()?{??
Chromosome?c?=?null;??
????????try{??
????????????c?=?(Chromosome)super.clone();??
????????????c.setGene(c.getGene().clone());
????????}catch(CloneNotSupportedException?e)?{??
????????????e.printStackTrace();??
????????}??
????????return?c;??
????}??

/**
?*?Randomly?set?genes?on?current?chromosome.
?*/
public?void?randomSetGene(){
Random?random=new?Random();
for(int?i=0;i gene[i]=Math.round(random.nextFloat());
}
}

/**
?*?
?*?@param?primaryGeneArray
?*/
public?void?setPrimaryGene(int[]?primaryGeneArray){
Random?random=new?Random();
for(int?i=0;i gene[i]=primaryGeneArray[i]==1?1:Math.round(random.nextFloat());
}
}

/**
?*?Return?the?fitness?of?Chromosome.
?*?@return int
?*/
public?int?getFitness(){
return?this.fitness;
}

/**
?*?Set?the?fitness?of?Chromosome.
?*?@param?fitness: int
?*?@return?void
?*/
public?void?setFitness(int?fitness){
this.fitness=fitness;
}

/**
?*?Acquire?objValue.
?*?@return
?*/
public?int?getObjValue()?{
return?objValue;
}

/**
?*?Set?the?chromosome‘s?objValue.
?*?@param?objValue
?*/
public?void?setObjValue(int?objValue)?{
this.objValue?=?objValue;
}

/**
?*?Acquire?genes
?*?@return
?*/
public?int[]?getGene(){
return?this.gene;
}

/**
?*?
?*?@param?gene
?*/
public?void?setGene(int[]?gene){
this.gene=gene;
}

/**
?*?
?*?@param?index
?*/
public?void?notGene(int?index){
this.gene[index]=1-gene[index];
}

/**
?*?Calculate?the?value?of?Chromosome.
?*?@param?void
?*?@return?int
?*/
public?int?calcObjValue(){
int?chormosomeValue=0;
for(int?i=0;i chormosomeValue+=(gene[i]*VALUE_ARRAY[i]);
}
setObjValue(chormosomeValue);
return?chormosomeValue;
}

/**
?*?Carrying?out?mutation?on?the?current?chromosome.
?*?@param?size:?the?size?of?Chromosome.
?*?@return?rate:?the?rate?of?mutation.
?*?@return?void
?*/
public?void?mutate(double?rate){
Random?random=new?Random();
for(int?i=0;i if(random.nextDouble() gene[i]=1-gene[i];
}
}
}

/**
?*?Print?the?gene.
?*/
public?void?printGene(){
for(int?elem:gene){
System.out.print(elem+“?“);
}
}
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件????????232??2019-12-09?21:58??GA\.classpath

?????文件????????378??2019-12-09?21:58??GA\.project

?????文件???????3137??2019-12-16?11:23??GA\bin\Chromosome.class

?????文件???????2227??2019-12-15?19:38??GA\bin\GA_Param.class

?????文件???????2484??2019-12-17?22:02??GA\bin\GA_Solution.class

?????文件????????836??2019-12-16?11:30??GA\bin\Population$1.class

?????文件??????10286??2019-12-16?11:30??GA\bin\Population.class

?????文件????????581??2019-12-17?22:01??GA\bin\Program.class

?????文件???????2823??2019-12-16?11:23??GA\src\Chromosome.java

?????文件???????1470??2019-12-15?19:38??GA\src\GA_Param.java

?????文件????????528??2019-12-17?22:43??GA\src\GA_Solution.java

?????文件??????12166??2019-12-17?23:09??GA\src\Population.java

?????文件????????181??2019-12-17?22:01??GA\src\Program.java

?????目錄??????????0??2019-12-15?13:06??GA\bin

?????目錄??????????0??2019-12-10?12:08??GA\src

?????目錄??????????0??2019-12-17?22:42??GA

-----------?---------??----------?-----??----

????????????????37329????????????????????16


評論

共有 條評論