public virtual void reset() { representative = clients.random_element(); foreach (Client c in clients.Data) { c.Species = null; } clients.clear(); clients.add(representative); representative.Species = this; score = 0; }
public virtual void mutate_node() { ConnectionGene con = connections.random_element(); if (con == null) { return; } NodeGene from = con.From; NodeGene to = con.To; int replaceIndex = neat.getReplaceIndex(from, to); NodeGene middle; if (replaceIndex == 0) { middle = neat.Node; middle.X = (from.X + to.X) / 2; middle.Y = (from.Y + to.Y) / 2 + GlobalRandom.NextDouble * 0.1 - 0.05; neat.setReplaceIndex(from, to, middle.Innovation_number); } else { middle = neat.getNode(replaceIndex); } ConnectionGene con1 = neat.getConnection(from, middle); ConnectionGene con2 = neat.getConnection(middle, to); con1.Weight = 1; con2.Weight = con.Weight; con2.Enabled = con.Enabled; connections.remove(con); connections.add(con1); connections.add(con2); nodes.add(middle); }
public virtual void mutate_link() { for (int i = 0; i < 100; i++) { NodeGene a = nodes.random_element(); NodeGene b = nodes.random_element(); if (a == null || b == null) { continue; } if (a.X == b.X) { continue; } ConnectionGene con; if (a.X < b.X) { con = new ConnectionGene(a, b); } else { con = new ConnectionGene(b, a); } if (connections.contains(con)) { continue; } con = neat.getConnection(con.From, con.To); con.Weight = (GlobalRandom.NextDouble * 2 - 1) * neat.WEIGHT_RANDOM_STRENGTH; data_structures.RandomHashSet <Gene> hi = new data_structures.RandomHashSet <Gene>(); hi.add_sorted(connections, con); return; } }