private NeatGenome LoadGenomeFromXml(string path) { // Load genome from the xml file XmlDocument xmlChampion = new XmlDocument(); xmlChampion.Load(path); return(NeatGenomeXmlIO.LoadGenome(xmlChampion.DocumentElement, true)); }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } XmlDocument xmlDocu = new XmlDocument(); xmlDocu.Load(openFileDialog.FileName); XmlNode newNode = xmlDocu.SelectSingleNode("//Root//Networks//Network"); NeatGenome networkGenome = NeatGenomeXmlIO.LoadGenome(newNode, false); 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 = 10.0; //int num = networkGenome.NeuronGeneList.Find((Predicate<NeuronGene>)(n => n.NodeType == NodeType.Output)); ; ArrayList arrayList1 = new ArrayList(); // for (int i = 0; i < 3 + 1; ++i) //{ ArrayList arrayList2 = new ArrayList(); foreach (NeuronGene nodeGene in Enumerable.Where <NeuronGene>((IEnumerable <NeuronGene>)networkGenome.NeuronGeneList, (Func <NeuronGene, bool>)(node => node.NodeType == NodeType.Output))) //node => node.layer=i { arrayList2.Add((object)nodeGene.Id.ToString()); } graph.AddSameLayer((IEnumerable)arrayList2); ArrayList arrayList3 = new ArrayList(); foreach (NeuronGene nodeGene in Enumerable.Where <NeuronGene>((IEnumerable <NeuronGene>)networkGenome.NeuronGeneList, (Func <NeuronGene, bool>)(node => node.NodeType == NodeType.Input))) //node => node.layer=i { arrayList3.Add((object)nodeGene.Id.ToString()); } graph.AddSameLayer((IEnumerable)arrayList3); ArrayList arrayList4 = new ArrayList(); foreach (NeuronGene nodeGene in Enumerable.Where <NeuronGene>((IEnumerable <NeuronGene>)networkGenome.NeuronGeneList, (Func <NeuronGene, bool>)(node => node.NodeType == NodeType.Hidden))) //node => node.layer=i { arrayList4.Add((object)nodeGene.Id.ToString()); } graph.AddSameLayer((IEnumerable)arrayList4); //} graph.GraphAttr.Orientation = Microsoft.Glee.Drawing.Orientation.Landscape; //graph.NeedCalculateLayout = true; graph.GraphAttr.Fontsize = 8; graph.GraphAttr.EdgeAttr.Fontsize = 4; graph.Cluster = true; graph.GraphAttr.LabelFloat = LabelFloat.Float; using (List <ConnectionGene> .Enumerator enumerator = networkGenome.ConnectionGeneList.GetEnumerator()) { while (enumerator.MoveNext()) { ConnectionGene link = enumerator.Current; //if (link.Weight != 0.0 )//&& link.SourceNodeId != -1) //{ if (link.SourceNodeId >= 14 && link.SourceNodeId <= 16) { continue; } Edge edge = graph.AddEdge(link.SourceNodeId.ToString(), link.Weight.ToString("0.##"), link.TargetNodeId.ToString()); edge.Attr.Fontsize = 4; edge.EdgeAttr.Fontsize = 4; if (link.Weight < 0.0) { edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red; } if (link.Weight == 0.0) { edge.Attr.Color = Microsoft.Glee.Drawing.Color.White; } edge.UserData = (object)link; // } } } for (int index = 0; index < networkGenome.NeuronGeneList.Count; ++index) { (graph.FindNode(networkGenome.NeuronGeneList[index].Id.ToString()) ?? graph.AddNode(networkGenome.NeuronGeneList[index].Id.ToString())).UserData = (object)networkGenome.NeuronGeneList[index]; } foreach (NeuronGene nodeGene in networkGenome.NeuronGeneList) { if (nodeGene.NodeType == NodeType.Input || nodeGene.NodeType == NodeType.Bias) { Visualizers.CreateSourceNode(graph.FindNode(nodeGene.Id.ToString())); } else if (nodeGene.NodeType == NodeType.Output) { this.CreateTargetNode(graph.FindNode(nodeGene.Id.ToString())); } else { this.CreateHiddenNode(graph.FindNode(nodeGene.Id.ToString())); } } this.gViewer.Graph = graph; }