public Node(NodeGene nodeGene) { this.id = nodeGene.id; this.activation = nodeGene.activation; this.type = nodeGene.type; value = 0f; inConnections = new List <Connection>(); outConnections = new List <Connection>(); }
public Connection(ConnectionGene con, NodeGene.Type inType, NodeGene.Type outType) { inNode = con.inNode; outNode = con.outNode; value = 0f; ready = false; weight = con.weight; recurrent = false; if (inType == NodeGene.Type.Output && (outType == NodeGene.Type.Input || outType == NodeGene.Type.Hidden)) { recurrent = true; } else if (inType == NodeGene.Type.Hidden && outType == NodeGene.Type.Input) { recurrent = true; } else if (inType == outType) { recurrent = true; } }
public void LoadGenome(string filename, bool all) { string path = filename; Genome genome = new Genome(); using (StreamReader reader = new StreamReader(path)) { bool node = false; bool connection = false; string line; while ((line = reader.ReadLine()) != null) { if (line.Equals("Nodes")) { node = true; connection = false; } else if (line.Equals("Connections")) { node = false; connection = true; } else { string[] info = line.Split(','); if (node) { int id = int.Parse(info[0]); NodeGene.Type type = (NodeGene.Type)System.Enum.Parse(typeof(NodeGene.Type), info[1]); GenomeUtils.Activation activation = (GenomeUtils.Activation)System.Enum.Parse(typeof(GenomeUtils.Activation), info[2]); genome.AddNodeGene(new NodeGene(type, id, activation)); Counter.SetNodeCounter(id); } else if (connection) { int innovation = int.Parse(info[0]); bool expressed = bool.Parse(info[1]); int inNode = int.Parse(info[2]); int outNode = int.Parse(info[3]); float weight = float.Parse(info[4]); genome.AddConnectionGene(new ConnectionGene(inNode, outNode, weight, expressed, innovation)); Counter.SetConnectionCounter(innovation); } else { Debug.LogError("Invalid genome file"); } } } } genomes.Clear(); genomes.Add(genome); if (all) { for (int i = 1; i < GenomeUtils.POP_SIZE; i++) { genomes.Add(GenomeUtils.Clone(genome)); } } else { for (int i = 1; i < GenomeUtils.POP_SIZE; i++) { genomes.Add(new Genome(inputNodes, outputNodes)); } } SetSpecies(); MakeNNets(); }