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);
}
}