|
1 |
| -/* *************************************************************************** |
2 |
| - * This file is part of SharpNEAT - Evolution of Neural Networks. |
3 |
| - * |
4 |
| - * Copyright 2004-2016 Colin Green ([email protected]) |
5 |
| - * |
6 |
| - * SharpNEAT is free software; you can redistribute it and/or modify |
7 |
| - * it under the terms of The MIT License (MIT). |
8 |
| - * |
9 |
| - * You should have received a copy of the MIT License |
10 |
| - * along with SharpNEAT; if not, see https://opensource.org/licenses/MIT. |
11 |
| - */ |
12 |
| -using SharpNeat.View.Graph; |
13 |
| -using SharpNeat.Genomes.Neat; |
14 |
| -using SharpNeat.Network; |
15 |
| - |
16 |
| -namespace SharpNeat.Domains |
17 |
| -{ |
18 |
| - /// <summary> |
19 |
| - /// GUI control for visualizing CPPN genomes. |
20 |
| - /// </summary> |
21 |
| - public partial class CppnGenomeView : AbstractGenomeView |
22 |
| - { |
23 |
| - NetworkGraphFactory _graphFactory = new NetworkGraphFactory(); |
24 |
| - IOGraphViewportPainter _viewportPainter; |
25 |
| - |
26 |
| - #region Constructor |
27 |
| - |
28 |
| - /// <summary> |
29 |
| - /// Construct with the provided CPPN activation function library to draw CPPNs with (genome nodes contain an index into this library). |
30 |
| - /// </summary> |
31 |
| - /// <param name="actFnLib"></param> |
32 |
| - public CppnGenomeView(IActivationFunctionLibrary actFnLib) |
33 |
| - { |
34 |
| - InitializeComponent(); |
35 |
| - graphControl1.ViewportPainter = _viewportPainter = new IOGraphViewportPainter(new CppnGraphPainter(actFnLib)); |
36 |
| - } |
37 |
| - |
38 |
| - #endregion |
39 |
| - |
40 |
| - #region Public Methods |
41 |
| - |
42 |
| - /// <summary> |
43 |
| - /// Refresh/update the view with the provided genome. |
44 |
| - /// </summary> |
45 |
| - public override void RefreshView(object genome) |
46 |
| - { |
47 |
| - NeatGenome neatGenome = genome as NeatGenome; |
48 |
| - if(null == neatGenome) { |
49 |
| - return; |
50 |
| - } |
51 |
| - |
52 |
| - IOGraph graph = _graphFactory.CreateGraph(neatGenome); |
53 |
| - _viewportPainter.IOGraph = graph; |
54 |
| - graphControl1.RefreshImage(); |
55 |
| - } |
56 |
| - |
57 |
| - #endregion |
58 |
| - } |
59 |
| -} |
| 1 | +/* *************************************************************************** |
| 2 | + * This file is part of SharpNEAT - Evolution of Neural Networks. |
| 3 | + * |
| 4 | + * Copyright 2004-2016 Colin Green ([email protected]) |
| 5 | + * |
| 6 | + * SharpNEAT is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of The MIT License (MIT). |
| 8 | + * |
| 9 | + * You should have received a copy of the MIT License |
| 10 | + * along with SharpNEAT; if not, see https://opensource.org/licenses/MIT. |
| 11 | + */ |
| 12 | +using SharpNeat.View.Graph; |
| 13 | +using SharpNeat.Genomes.Neat; |
| 14 | +using SharpNeat.Network; |
| 15 | + |
| 16 | +namespace SharpNeat.Domains |
| 17 | +{ |
| 18 | + /// <summary> |
| 19 | + /// GUI control for visualizing CPPN genomes. |
| 20 | + /// </summary> |
| 21 | + public partial class CppnGenomeView : AbstractGenomeView |
| 22 | + { |
| 23 | + readonly NetworkGraphFactory _graphFactory = new NetworkGraphFactory(); |
| 24 | + readonly IOGraphViewportPainter _viewportPainter; |
| 25 | + |
| 26 | + #region Constructor |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Construct with the provided CPPN activation function library to draw CPPNs with (genome nodes contain an index into this library). |
| 30 | + /// </summary> |
| 31 | + /// <param name="actFnLib"></param> |
| 32 | + public CppnGenomeView(IActivationFunctionLibrary actFnLib) |
| 33 | + { |
| 34 | + InitializeComponent(); |
| 35 | + graphControl1.ViewportPainter = _viewportPainter = new IOGraphViewportPainter(new CppnGraphPainter(actFnLib)); |
| 36 | + } |
| 37 | + |
| 38 | + #endregion |
| 39 | + |
| 40 | + #region Public Methods |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Refresh/update the view with the provided genome. |
| 44 | + /// </summary> |
| 45 | + public override void RefreshView(object genome) |
| 46 | + { |
| 47 | + NeatGenome neatGenome = genome as NeatGenome; |
| 48 | + if(null == neatGenome) { |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + IOGraph graph = _graphFactory.CreateGraph(neatGenome); |
| 53 | + _viewportPainter.IOGraph = graph; |
| 54 | + graphControl1.RefreshImage(); |
| 55 | + } |
| 56 | + |
| 57 | + #endregion |
| 58 | + } |
| 59 | +} |
0 commit comments