public double[] Evaluate(StubIndividual individual) { double[] output = new double[2]; output[0] = 0.0; output[1] = 0.0; return(output); }
public StubIndividual Cross(StubIndividual spouse) { if (GetType() != spouse.GetType()) { throw new InvalidOperationException(); } return(CrossWithSpouse(spouse)); }
protected override StubIndividual CrossWithSpouse(StubIndividual spouse) { var flatSpouse = (FlatIndividual)spouse; //There are several cases here - we have two children, or we have one starting with this's genome, or we have one ending with this's genome //Cut at random point along this var newChromosome = new List <Chromosome>(); //Cut at random point along them for (var i = 0; i < Utility.GetRandomNum(this._genome.Length); i++) { newChromosome.Add(this._genome[i]); } for (var i = Utility.GetRandomNum(flatSpouse._genome.Length); i < flatSpouse._genome.Length; i++) { newChromosome.Add(flatSpouse._genome[i]); } return(new FlatIndividual(newChromosome.DistinctChromosomes())); }
public double[] Evaluate(StubIndividual individual) { double[] output = new double[2]; var tcpClient = new TcpClient(); while (!tcpClient.Connected) { try { tcpClient.Connect(Utility.FitnessServerAddress, Utility.FitnessServerPort); } catch (Exception ex) { Debug.WriteLine(ex); Console.WriteLine("Connecting failed. Trying again"); System.Threading.Thread.Sleep(500); } } var interpreter = new Interpreter(); String sql = interpreter.Parse(individual); NetworkStream serverStream = tcpClient.GetStream(); byte[] bytesToSend = Encoding.UTF8.GetBytes(sql); Debug.WriteLine("Sending : " + sql); serverStream.Write(bytesToSend, 0, bytesToSend.Length); var bytesToRead = new byte[tcpClient.ReceiveBufferSize]; int bytesRead = serverStream.Read(bytesToRead, 0, tcpClient.ReceiveBufferSize); var result = Encoding.UTF8.GetString(bytesToRead, 0, bytesRead).Substring(2); tcpClient.Close(); Debug.WriteLine("Received : " + result); //Console.WriteLine(result.Split('\n')[0]); output[0] = Convert.ToDouble(result.Split('\n')[0]); output[1] = Convert.ToDouble(result.Split('\n')[1]); return(output); }
protected abstract StubIndividual CrossWithSpouse(StubIndividual spouse);
public string Parse(StubIndividual sqlIndividual) { _sqlIndividual = sqlIndividual; return(sqlIndividual.ToSql()); }
public double Evaluate(StubIndividual individual) => throw new ArgumentNullException("Stub individual had no fitness before it was evaluated.");
public double Evaluate(StubIndividual individual) { index++; return(_fitness[index]); }