我已经设置了 log4j,但我注意到这样的奇怪输出(我希望看到 0 1 2 3 4 作为行号) -
0 [main] DEBUG org.dnsdojo.ryanhost.GA.MuPlusOne.Genome - 0011110101101010110110111011101111110001010001110011100011110111011001011100100100101001100110100000011100010100
2 [main] DEBUG org.dnsdojo.ryanhost.GA.MuPlusOne.Genome - 112
2 [main] DEBUG org.dnsdojo.ryanhost.GA.MuPlusOne.Genome - 0010100111111010110110010001000100000110110111111011011100101010011100011001111111111011110011001111010100100101
3 [main] DEBUG org.dnsdojo.ryanhost.GA.MuPlusOne.Genome - 112
3 [main] DEBUG org.dnsdojo.ryanhost.GA.MuPlusOne.Genome - 0101101000001010000001101000101001001000111111111110001010011001111011010101011010010000111000100011110010101100
3 [main] DEBUG org.dnsdojo.ryanhost.GA.MuPlusOne.Genome - 112
谁能解释为什么会发生这种情况?log4j.properties #定义控制台追加器 log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender
# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# now map our console appender as a root logger, means all log messages will go to this appender
log4j.rootLogger = DEBUG, consoleAppender
基因组类
package org.dnsdojo.ryanhost.GA.MuPlusOne;
import java.util.Random;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Genome
{
private static Logger logger = Logger.getLogger(Genome.class);
byte[] genome;
Random rng = new Random();
String genomeString = "";
public Genome ( int stringLength, int motorSet )
{
PropertyConfigurator.configure("log4j.properties");
genome = new byte[ stringLength * 7 * motorSet]; // stringLength depends on how many bytes you wish to have. For the arpibot this is dependant on the number of sensor readings taken
for (int i = 0; i < genome.length; i++)
{
genome[i] = (byte)rng.nextInt(2);
genomeString += genome[i];
}
logger.debug(genomeString);
logger.debug(genomeString.length());
}
public byte[] getGenome()
{
return genome;
}
public byte[] mutate (float mutationStep)
{
return genome; //placeholder
}
}
司机班
package org.dnsdojo.ryanhost.GA.MuPlusOne;
import java.util.ArrayList;
public class Driver
{
int populationSize = 0; //mu
int evaluationTime = 0; //tau measured in seconds
double reevaluationRate, mutationStep = 0;//rho = reevaluationRate, sigma = mutationStep
int numberOfSensors, numberOfMotors = 0;
ArrayList<Genome> population = new ArrayList<Genome>();
public Driver (int populationSize, int evaluationTime, double reevaluationRate, double mutationStep, int numberOfSensors, int numberOfMotors)
{
this.populationSize = populationSize;
this.evaluationTime = evaluationTime;
this.reevaluationRate = reevaluationRate;
this.mutationStep = mutationStep;
this.numberOfSensors = numberOfSensors;
this.numberOfMotors = numberOfMotors;
for(int i = 0; i < populationSize; i++)
{
population.add (new Genome (numberOfSensors , numberOfMotors) );
}
}
public static void main( String[] args)
{
Driver gADriver = new Driver(100, 60 , 0.2, 0.2, 8, 2);
}
}