private bool LoadSeedInit() { NetworkGenome genome = NetworkGenome.LoadFromFile(this.Init.Seed.file); if (genome == null) { return(false); } genome.Fitness = 0.0; genome.Age = 0; genome.Species = 0; genome.Id = 0; this.Current.Genomes.Add(genome); this.species.Add(new Species(0, 0, 0.0, genome)); this.Init.MaxLayers = Enumerable.First <NodeGene>((IEnumerable <NodeGene>)genome.Nodes, (Func <NodeGene, bool>)(g => g.Type == NodeType.Output)).Layer + 1; this.Init.Inputs = Enumerable.Count <NodeGene>((IEnumerable <NodeGene>)genome.Nodes, (Func <NodeGene, bool>)(g => g.Type == NodeType.Input)); this.Init.Outputs = Enumerable.Count <NodeGene>((IEnumerable <NodeGene>)genome.Nodes, (Func <NodeGene, bool>)(g => g.Type == NodeType.Output)); NetworkGenome.NextId = 1; foreach (LinkGene LinkGenes in genome.Links) { LinkGene.NextId = Math.Max(LinkGene.NextId, LinkGenes.Id); } foreach (NodeGene NodeGenes in genome.Nodes) { NodeGene.NextId = Math.Max(NodeGene.NextId, NodeGenes.Id); } while (this.Current.Genomes.Count < this.Init.PopulationSize) { NetworkGenome networkGenomes = genome.Clone() as NetworkGenome; networkGenomes.Id = NetworkGenome.NextId; networkGenomes.Parent1 = 0; networkGenomes.Parent2 = -1; this.RandomizeWeights(networkGenomes); double num1 = 1000000.0; int index1 = 0; for (int index2 = 0; index2 < this.species.Count; ++index2) { double num2 = this.species[index2].GenomeCompatibility(networkGenomes); if (num2 < num1) { num1 = num2; index1 = index2; } } if (num1 <= this.Speciate.Threshold) { this.species[index1].Genomes.Add(networkGenomes); networkGenomes.Species = index1; } else { this.species.Add(new Species(0, 0, 0.0, networkGenomes)); networkGenomes.Species = this.species.Count - 1; } this.Current.Genomes.Add(networkGenomes); } return(true); }
private bool TestInit() { this.TestRun = true; if (this.Tests.Directory.test) { DirectoryInfo directoryInfo = new DirectoryInfo(this.Tests.Directory.path); foreach (FileSystemInfo fileSystemInfo in directoryInfo.GetFiles("*.xml")) { NetworkGenome networkGenomes = NetworkGenome.LoadFromFile(fileSystemInfo.FullName); if (networkGenomes != null) { this.Current.Genomes.Add(networkGenomes); } } } else { this.Current.Genomes.Add(NetworkGenome.LoadFromFile(this.Tests.Genome.path)); } return(true); }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } NetworkGenome networkGenome = NetworkGenome.LoadFromFile(openFileDialog.FileName); Graph graph = new Graph("Genome: " + (object)networkGenome.Id); graph.GraphAttr.LayerDirection = LayerDirection.BT; graph.Directed = true; graph.GraphAttr.LayerSep = 10.0; graph.BuildNodeHierarchy = true; graph.GraphAttr.OptimizeLabelPositions = true; graph.GraphAttr.NodeAttr.Padding = 1.0; int num = networkGenome.Nodes.Find((Predicate <NodeGene>)(n => n.Type == NodeType.Output)).Layer; ArrayList arrayList1 = new ArrayList(); for (int i = 0; i < num + 1; ++i) { ArrayList arrayList2 = new ArrayList(); foreach (NodeGene nodeGene in Enumerable.Where <NodeGene>((IEnumerable <NodeGene>)networkGenome.Nodes, (Func <NodeGene, bool>)(node => node.Layer == i))) { arrayList2.Add((object)nodeGene.Id.ToString()); } graph.AddSameLayer((IEnumerable)arrayList2); } graph.GraphAttr.Orientation = Microsoft.Glee.Drawing.Orientation.Landscape; graph.NeedCalculateLayout = true; graph.GraphAttr.Fontsize = 8; graph.GraphAttr.EdgeAttr.Fontsize = 7; graph.Cluster = true; graph.GraphAttr.LabelFloat = LabelFloat.Float; using (List <LinkGene> .Enumerator enumerator = networkGenome.Links.GetEnumerator()) { while (enumerator.MoveNext()) { LinkGene link = enumerator.Current; if (link.Weight != 0.0 && link.Source != -1) { //Edge edge = graph.AddEdge(link.Source.ToString(), link.Id.ToString(), link.Target.ToString()); Edge edge = graph.AddEdge(link.Source.ToString(), link.Weight.ToString("0.##"), link.Target.ToString()); edge.Attr.Fontsize = 7; edge.EdgeAttr.Fontsize = 7; if (link.Weight <= 0.0) { edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red; } NodeGene nodeGene1 = networkGenome.Nodes.Find((Predicate <NodeGene>)(n => n.Id == link.Source)); NodeGene nodeGene2 = networkGenome.Nodes.Find((Predicate <NodeGene>)(n => n.Id == link.Target)); edge.Attr.Weight = Math.Max(nodeGene1.Layer - nodeGene2.Layer, 0); edge.UserData = (object)link; } } } for (int index = 0; index < networkGenome.Nodes.Count; ++index) { (graph.FindNode(networkGenome.Nodes[index].Id.ToString()) ?? graph.AddNode(networkGenome.Nodes[index].Id.ToString())).UserData = (object)networkGenome.Nodes[index]; } foreach (NodeGene nodeGene in networkGenome.Nodes) { if (nodeGene.Layer == 0) { Visualizers.CreateSourceNode(graph.FindNode(nodeGene.Id.ToString())); } else if (nodeGene.Layer == num) { this.CreateTargetNode(graph.FindNode(nodeGene.Id.ToString())); } else { this.CreateHiddenNode(graph.FindNode(nodeGene.Id.ToString())); } } this.gViewer.Graph = graph; }