我正在開發線性Evol.Algrm。我正在爲我的基因組實施「可比較」以使評估更簡單;這裏是該類:無法獲得可比較的接口工作
public class Chromosome extends Thread implements Comparable
{
private String[] chromosome;
private double fitness;
private Random chromoGen;
public Chromosome(double[] candidate)
{
super();
//encode candidate PER parameter; using Matrix as storage
chromosome = encode(candidate);
}
//De-fault
public Chromosome()
{
super();
}
public int compareTo(Chromosome c)
{
return (fitness - c.fitness);
}
/**
* Fitness stored in chromosome!
*/
public void setFitness()
{
fitness = FF.fitness(this);
}
public double getFitness()
{
return fitness;
}
/**
* ENCODERS/DECODERS
*/
public String[] encode(double[] solution)
{
//subtract 2^n from solution until you reach 2^-n
/**
* THE PRECISION IS [2^10 <-> 2^-8]!!!
*/
double parameter = 0.00;
String row = "";
String[] encoded = new String[6];
for (int j = 0; (j < 6); j++){
parameter = solution[j];
for (int i = 10; (i < (-8)); i--){
if ((parameter - Math.pow(2, i)) >= 0){
parameter = parameter - Math.pow(2, i);
row += "1";
}
else{
row += "0";
}
}
encoded[j] = row;
//refresh
row = "";
}
return encoded;
}
public String encode(double sol)
{
//subtract 2^n from solution until you reach 2^-n
/**
* THE PRECISION IS [2^10 <-> 2^-8]!!!
*/
String row = "";
for (int i = 10; (i < (-8)); i--){
if ((sol - Math.pow(2, i)) >= 0){
sol = sol - Math.pow(2, i);
row += "1";
}
else{
row += "0";
}
}
return row;
}
public double decoded(int number)
{
//returns UN-ENCODED solution
double decoded = 0.00;
String parameter = "";
parameter = chromosome[number];
for (int i = 10; (i < (-8)); i--){
if (parameter.substring(i, (i+1)).equals("1")){
decoded += Math.pow(2, i);
}
}
return decoded;
}
/**
* GETTERS
* ---------------\/--REDUNDANT!!
*/
public double getParameter(int parameter)
{
//decoded solution
return decoded(parameter);
}
/**
* Used in E-algrm.
*/
public String getRow(int row)
{
//encoded solution
return chromosome[row];
}
/**
* SETTERS
*/
public void setRow(String encoded, int row)
{
chromosome[row] = encoded;
}
public void setRow(double decoded, int row)
{
chromosome[row] = encode(decoded);
}
/**
* MUTATIONS IFF (mutate?)
*/
public void mutate(double mutationRate)
{
//range of: 0-17
int ran = 0;
char[] temp;
for (int m = 0; (m < 6); m++){
temp = String.toCharArray(chromosome[m]);
ran = chromoGen.nextDouble();
if (ran <= mutationRate){
}
}
}
}
我的問題是,即使我明確實施了比較方法;編譯器仍然不高興,並說'必須聲明摘要或執行等等等等等等''
任何幫助?
「Blah blah blah」在這裏沒有幫助。指定完整的錯誤語句。 – Mangesh