Changeset 10285
- Timestamp:
- 01/05/14 20:47:50 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.Designer.cs
r10271 r10285 1 namespace HeuristicLab.EvolutionTracking.Views { 2 partial class GenealogyGraphChart { 1 using HeuristicLab.Core; 2 3 namespace HeuristicLab.EvolutionTracking.Views { 4 partial class GenealogyGraphChart<TGraph, TVertex, TContent> 5 where TGraph : class, IGenealogyGraph<TVertex, TContent> 6 where TVertex : class, IGenealogyGraphNode<TContent>, new() 7 where TContent : class, IItem { 3 8 /// <summary> 4 9 /// Required designer variable. -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs
r10271 r10285 6 6 using System.Windows.Forms; 7 7 using HeuristicLab.Common; 8 using HeuristicLab.Core; 8 9 using HeuristicLab.Visualization; 9 10 10 11 namespace HeuristicLab.EvolutionTracking.Views { 11 public partial class GenealogyGraphChart : ChartControl { 12 private GenealogyGraph genealogyGraph; 12 public partial class GenealogyGraphChart<TGraph, TVertex, TContent> : ChartControl 13 where TGraph : class, IGenealogyGraph<TVertex, TContent> 14 where TVertex : class, IGenealogyGraphNode<TContent>, new() 15 where TContent : class,IItem { 16 private TGraph genealogyGraph; 13 17 14 18 private const double XIncrement = 30; … … 16 20 private const double Diameter = 20; 17 21 18 public GenealogyGraph GenealogyGraph {22 public TGraph GenealogyGraph { 19 23 get { return genealogyGraph; } 20 24 set { … … 62 66 return arc; 63 67 } 64 65 68 private bool DrawInProgress { get; set; } // do not try to update the chart while the drawing is not finished 66 69 private VisualGenealogyGraphNode SelectedVisualNode { get; set; } … … 71 74 if (clicked != null) clicked(sender, e); 72 75 } 73 74 76 public GenealogyGraphChart() { 75 77 InitializeComponent(); 76 78 } 77 78 79 protected virtual void DrawGraph(double xIncrement, double yIncrement, double diameter) { 79 80 Chart.UpdateEnabled = false; … … 104 105 } 105 106 y -= yIncrement; 106 } 107 x = 0; 108 } 109 107 110 // add arcs 108 111 foreach (var node in GenealogyGraph.Nodes) { … … 116 119 var pen = new Pen(Color.Transparent); 117 120 var visualArc = AddArc(Chart, visualParent, visualNode, pen); 118 arcMap.Add(Tuple.Create(visualParent, visualNode), visualArc); 121 if (!arcMap.ContainsKey(Tuple.Create(visualParent, visualNode))) 122 arcMap.Add(Tuple.Create(visualParent, visualNode), visualArc); 119 123 } 120 124 } … … 126 130 DrawInProgress = false; 127 131 } 128 129 protected override void pictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { 132 protected override void pictureBox_MouseMove(object sender, MouseEventArgs e) { 130 133 if (!DrawInProgress) { 131 134 switch (e.Button) { … … 142 145 base.pictureBox_MouseMove(sender, e); 143 146 } 144 145 147 protected override void pictureBox_MouseUp(object sender, MouseEventArgs e) { 146 148 Cursor = Cursors.Default; … … 189 191 base.pictureBox_MouseUp(sender, e); 190 192 } 191 192 193 private void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector) { 193 194 if (node.Brush != null) return; … … 207 208 } 208 209 } 209 210 210 void MarkSelectedNode() { 211 211 var center = SelectedVisualNode.Center; … … 222 222 } 223 223 } 224 225 226 224 private static VisualGenealogyGraphArc AddArc(IChart chart, VisualGenealogyGraphNode source, VisualGenealogyGraphNode target, Pen pen, Brush brush = null) { 227 225 var arc = new VisualGenealogyGraphArc(chart, source, target, pen) { Brush = brush }; … … 232 230 return arc; 233 231 } 234 235 232 public virtual void ClearPrimitives() { 236 233 foreach (var primitive in Chart.Group.Primitives) { … … 267 264 } 268 265 } 269 270 266 internal static class Util { 271 267 public static Color GetColor(this IGenealogyGraphNode node) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphView.cs
r10271 r10285 60 60 protected override void OnContentChanged() { 61 61 base.OnContentChanged(); 62 genealogyGraphChart.GenealogyGraph = Content ?? null;62 // genealogyGraphChart.GenealogyGraph = Content ?? null; 63 63 } 64 64 private void Content_GraphChanged(object sender, EventArgs e) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/HeuristicLab.EvolutionTracking.Views-3.4.csproj
r10269 r10285 122 122 <DependentUpon>GenealogyGraphChart.cs</DependentUpon> 123 123 </Compile> 124 <Compile Include="GenealogyGraphView.cs">125 <SubType>UserControl</SubType>126 </Compile>127 <Compile Include="GenealogyGraphView.Designer.cs">128 <DependentUpon>GenealogyGraphView.cs</DependentUpon>129 </Compile>130 124 <Compile Include="Plugin.cs" /> 131 125 <Compile Include="Primitives\LabeledEllipse.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10278 r10285 1 using HeuristicLab.Common; 1 using System.Collections.Generic; 2 using System.Linq; 3 using HeuristicLab.Common; 2 4 using HeuristicLab.Core; 3 5 using HeuristicLab.Data; … … 18 20 private AfterManipulatorOperator<TGraph, TVertex, TContent> afterManipulatorOperator; 19 21 private BeforeManipulatorOperator<TGraph, TVertex, TContent> beforeManipulatorOperator; 20 // private AfterSolutionCreatorOperator<TGraph, TVertex, TContent> afterSolutionCreatorOperator;21 22 public string CrossoverParentsParameterName { get; set; } 22 23 public string CrossoverChildParameterName { get; set; } 23 24 public string ManipulatorChildParameterName { get; set; } 24 25 25 private string solutionCreatorIndividualParameterName; 26 public string SolutionCreatorIndividualParameterName { 27 get { return solutionCreatorIndividualParameterName; } 28 set { 29 if (solutionCreatorIndividualParameterName != null && Parameters.ContainsKey(solutionCreatorIndividualParameterName)) { 30 Parameters.Remove(solutionCreatorIndividualParameterName); 31 } 32 solutionCreatorIndividualParameterName = value; 33 if (!Parameters.ContainsKey(solutionCreatorIndividualParameterName)) { 34 Parameters.Add(new ScopeTreeLookupParameter<TContent>(solutionCreatorIndividualParameterName)); 35 } 36 } 37 } 26 public IScopeTreeLookupParameter<DoubleValue> QualityParameter; 27 public IScopeTreeLookupParameter<TContent> PopulationParameter; 28 29 private const string PopulationParameterName = "Population"; 30 private const string QualityParameterName = "Quality"; 38 31 39 32 private const string GenerationsParameterName = "Generations"; … … 52 45 public ILookupParameter<ResultCollection> ResultsParameter { 53 46 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; } 54 }55 public IScopeTreeLookupParameter<TContent> PopulationParameter {56 get { return (IScopeTreeLookupParameter<TContent>)Parameters[solutionCreatorIndividualParameterName]; }57 47 } 58 48 public ILookupParameter<IntValue> GenerationsParameter { … … 76 66 public ILookupParameter<ISolutionCreator> SolutionCreatorParameter { 77 67 get { return (ILookupParameter<ISolutionCreator>)Parameters[SolutionCreatorParameterName]; } 78 }79 public IntValue Generations {80 get { return GenerationsParameter.ActualValue; }81 68 } 82 69 #endregion … … 103 90 public ResultCollection Results { 104 91 get { return ResultsParameter.ActualValue; } 92 } 93 public IntValue Generations { 94 get { return GenerationsParameter.ActualValue; } 105 95 } 106 96 public IGenealogyGraph<TVertex, TContent> GenealogyGraph { … … 131 121 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations so far.")); 132 122 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName)); 123 PopulationParameter = new ScopeTreeLookupParameter<TContent>(PopulationParameterName); 124 QualityParameter = new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName); 125 Parameters.Add(PopulationParameter); 126 Parameters.Add(QualityParameter); 133 127 } 134 128 public override IDeepCloneable Clone(Cloner cloner) { … … 144 138 145 139 public override IOperation Apply() { 146 // wire the before- and after operators147 // if (EnableSolutionCreatorTracking.Value) {148 // if (afterSolutionCreatorOperator == null) {149 // afterSolutionCreatorOperator = new AfterSolutionCreatorOperator<TGraph, TVertex, TContent>();150 // afterSolutionCreatorOperator.NewIndividualParameterName = SolutionCreatorIndividualParameterName;151 // }152 // var instrumentedSolutionCreator = (InstrumentedOperator)SolutionCreator;153 // instrumentedSolutionCreator.AfterExecutionOperators.Add(afterSolutionCreatorOperator);154 // }155 156 140 if (Generations.Value == 0) { 157 141 foreach (var individual in PopulationParameter.ActualValue) { … … 162 146 GenealogyGraph.AddVertex(vertex); 163 147 } 148 // at the beginning we add the before/after operators to the instrumented operators 149 if (EnableCrossoverTracking.Value) { 150 if (afterCrossoverOperator == null) { 151 afterCrossoverOperator = new AfterCrossoverOperator<TGraph, TVertex, TContent>(); 152 afterCrossoverOperator.ParentsParameter.ActualName = CrossoverParentsParameterName; 153 afterCrossoverOperator.ChildParameter.ActualName = CrossoverChildParameterName; 154 } 155 var instrumentedCrossover = (InstrumentedOperator)Crossover; 156 instrumentedCrossover.AfterExecutionOperators.Add(afterCrossoverOperator); 157 } 158 159 if (EnableManipulatorTracking.Value && Manipulator != null) { 160 if (beforeManipulatorOperator == null) { 161 beforeManipulatorOperator = new BeforeManipulatorOperator<TGraph, TVertex, TContent>(); 162 beforeManipulatorOperator.ChildParameter.ActualName = ManipulatorChildParameterName; 163 } 164 if (afterManipulatorOperator == null) { 165 afterManipulatorOperator = new AfterManipulatorOperator<TGraph, TVertex, TContent>(); 166 afterManipulatorOperator.ChildParameter.ActualName = ManipulatorChildParameterName; 167 } 168 var instrumentedManipulator = (InstrumentedOperator)Manipulator; 169 instrumentedManipulator.BeforeExecutionOperators.Add(beforeManipulatorOperator); 170 instrumentedManipulator.AfterExecutionOperators.Add(afterManipulatorOperator); 171 } 164 172 } else { 165 // add missing individuals in the current generation 173 // add missing elite individuals in the current generation 174 // TODO: optimize for speed 175 var currGen = new HashSet<TContent>(GenealogyGraph.Ranks[Generations.Value].Select(x => x.Content)); 166 176 foreach (var individual in PopulationParameter.ActualValue) { 167 if ( !GenealogyGraph.Contains(individual)) continue;177 if (currGen.Contains(individual)) continue; 168 178 // it is an elite which was already added to the graph in the previous generation 169 179 var vertex = new TVertex { 170 180 Content = individual, 171 Rank = Generations.Value 181 Rank = Generations.Value, 182 IsElite = true 172 183 }; 173 184 GenealogyGraph.AddVertex(vertex); 174 185 } 175 186 } 176 177 if (EnableCrossoverTracking.Value) {178 if (afterCrossoverOperator == null) {179 afterCrossoverOperator = new AfterCrossoverOperator<TGraph, TVertex, TContent>();180 afterCrossoverOperator.ParentsParameterName = CrossoverParentsParameterName;181 afterCrossoverOperator.ChildParameterName = CrossoverChildParameterName;187 // update qualities for the nodes in the graph 188 var population = PopulationParameter.ActualValue.ToList(); 189 var qualities = QualityParameter.ActualValue.ToList(); 190 for (int i = 0; i < population.Count; ++i) { 191 foreach (var v in GenealogyGraph[population[i]]) { 192 v.Quality = qualities[i].Value; 182 193 } 183 var instrumentedCrossover = (InstrumentedOperator)Crossover;184 instrumentedCrossover.AfterExecutionOperators.Add(afterCrossoverOperator);185 }186 187 if (EnableManipulatorTracking.Value) {188 if (beforeManipulatorOperator == null) {189 beforeManipulatorOperator = new BeforeManipulatorOperator<TGraph, TVertex, TContent>();190 beforeManipulatorOperator.ChildParameterName = ManipulatorChildParameterName;191 }192 if (afterManipulatorOperator == null) {193 afterManipulatorOperator = new AfterManipulatorOperator<TGraph, TVertex, TContent>();194 afterManipulatorOperator.ChildParameterName = ManipulatorChildParameterName;195 }196 var instrumentedManipulator = (InstrumentedOperator)Manipulator;197 instrumentedManipulator.BeforeExecutionOperators.Add(beforeManipulatorOperator);198 instrumentedManipulator.AfterExecutionOperators.Add(afterManipulatorOperator);199 194 } 200 195 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IVertex.cs
r10271 r10285 42 42 } 43 43 44 public interface IVertex<T> : IVertex { 44 public interface IVertex<T> : IVertex 45 where T : class,IItem { 45 46 T Content { get; set; } 46 47 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs
r10278 r10285 77 77 // (they do not appear in the nodes Dictionary). It is the programmers responsibility to 78 78 // enforce the correct and desired behavior. 79 public void AddForwardArc(IVertex target, double w eight= 0.0, object data = null) {80 var e = new Arc { Source = this, Target = target, Data = data, Weight = w eight};79 public void AddForwardArc(IVertex target, double w = 0.0, object data = null) { 80 var e = new Arc { Source = this, Target = target, Data = data, Weight = w }; 81 81 if (OutArcs == null) OutArcs = new List<IArc> { e }; 82 82 else OutArcs.Add(e); … … 92 92 if (InArcs == null) { InArcs = new List<IArc> { arc }; } else { InArcs.Add(arc); } 93 93 } 94 public void AddReverseArc(IVertex source, double w eight= 0.0, object data = null) {95 var e = new Arc { Source = source, Target = this, Data = data, Weight = w eight};94 public void AddReverseArc(IVertex source, double w = 0.0, object data = null) { 95 var e = new Arc { Source = source, Target = this, Data = data, Weight = w }; 96 96 if (InArcs == null) InArcs = new List<IArc> { e }; 97 97 else InArcs.Add(e); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs
r10278 r10285 27 27 [StorableClass] 28 28 [Item("GenealogyGraphArc", "A graph arc connecting two GenealogyGraphNodes and holding some data.")] 29 public class GenealogyGraphArc<T> : Arc, IGenealogyGraphArc where T : class,IItem { 29 public class GenealogyGraphArc : Arc, IGenealogyGraphArc { 30 [StorableConstructor] 31 protected GenealogyGraphArc(bool deserializing) : base(deserializing) { } 32 protected GenealogyGraphArc(GenealogyGraphArc original, Cloner cloner) 33 : base(original, cloner) { 34 } 35 36 public GenealogyGraphArc() { } 37 38 public override IDeepCloneable Clone(Cloner cloner) { 39 return new GenealogyGraphArc(this, cloner); 40 } 41 public new IGenealogyGraphNode Source { get; set; } 42 public new IGenealogyGraphNode Target { get; set; } 43 44 45 } 46 47 [StorableClass] 48 [Item("GenealogyGraphArc", "")] 49 public class GenealogyGraphArc<T> : GenealogyGraphArc where T : class,IItem { 30 50 [StorableConstructor] 31 51 protected GenealogyGraphArc(bool deserializing) : base(deserializing) { } … … 34 54 Data = (T)original.Data.Clone(); 35 55 } 56 public GenealogyGraphArc() { } 57 36 58 public override IDeepCloneable Clone(Cloner cloner) { 37 59 return new GenealogyGraphArc<T>(this, cloner); 38 60 } 39 public new IGenealogyGraphNode Source { get; set; } 40 public new IGenealogyGraphNode Target { get; set; } 41 public new T Data { get; set; } 61 public new T Data { 62 get { 63 return (T)base.Data; 64 } 65 set { 66 base.Data = value; 67 } 68 } 42 69 } 43 70 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r10278 r10285 43 43 public new List<IGenealogyGraphArc> InArcs { 44 44 get { 45 return base.InArcs .Cast<IGenealogyGraphArc>().ToList();45 return base.InArcs == null ? null : base.InArcs.Cast<IGenealogyGraphArc>().ToList(); 46 46 } 47 47 } 48 48 public new List<IGenealogyGraphArc> OutArcs { 49 49 get { 50 return base.OutArcs .Cast<IGenealogyGraphArc>().ToList();50 return base.OutArcs == null ? null : base.OutArcs.Cast<IGenealogyGraphArc>().ToList(); 51 51 } 52 52 } … … 109 109 return Quality.CompareTo(other.Quality); 110 110 } 111 112 public new void AddForwardArc(IVertex target, double w = 0, object data = null) { 113 var e = new GenealogyGraphArc { Source = this, Target = (IGenealogyGraphNode)target, Data = data, Weight = w }; 114 base.AddForwardArc(e); 115 } 116 public new void AddReverseArc(IVertex source, double w = 0.0, object data = null) { 117 var e = new GenealogyGraphArc { Source = (IGenealogyGraphNode)source, Target = this, Data = data, Weight = w }; 118 base.AddReverseArc(e); 119 } 111 120 } 112 121 113 122 [StorableClass] 114 123 [Item("GenealogyGraphNode", "A genealogy graph node which also has a Content")] 115 public class GenealogyGraphNode<T> : GenealogyGraphNode, IGenealogyGraphNode<T> {124 public class GenealogyGraphNode<T> : GenealogyGraphNode, IGenealogyGraphNode<T> where T : class,IItem { 116 125 public T Content { get; set; } 126 117 127 } 118 128 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphArc.cs
r10278 r10285 20 20 #endregion 21 21 22 using HeuristicLab.Core; 23 22 24 namespace HeuristicLab.EvolutionTracking { 23 25 public interface IGenealogyGraphArc : IArc { 24 26 new IGenealogyGraphNode Source { get; set; } 25 27 new IGenealogyGraphNode Target { get; set; } 26 object Data { get; set; } 28 } 29 30 public interface IGenealogyGraphArc<T> : IGenealogyGraphArc where T : class, IItem { 31 T Data { get; set; } 27 32 } 28 33 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphNode.cs
r10278 r10285 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Core; 24 25 25 26 namespace HeuristicLab.EvolutionTracking { … … 27 28 IEnumerable<IGenealogyGraphNode> Ancestors(); 28 29 IEnumerable<IGenealogyGraphNode> Descendants(); 29 30 30 new List<IGenealogyGraphArc> InArcs { get; } 31 31 new List<IGenealogyGraphArc> OutArcs { get; } … … 36 36 } 37 37 38 public interface IGenealogyGraphNode<T> : IGenealogyGraphNode, IVertex<T> { } 38 public interface IGenealogyGraphNode<T> : IGenealogyGraphNode, IVertex<T> where T : class,IItem { 39 40 } 39 41 40 42 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterCrossoverOperator.cs
r10278 r10285 33 33 where TVertex : class,IGenealogyGraphNode<TContent>, new() 34 34 where TContent : class,IItem { 35 36 private string parentsParameterName; 37 public string ParentsParameterName { 38 get { return parentsParameterName; } 39 set { 40 if (parentsParameterName != null && Parameters.ContainsKey(parentsParameterName)) Parameters.Remove(parentsParameterName); // remove old parameter 41 parentsParameterName = value; 42 if (!Parameters.ContainsKey(parentsParameterName)) Parameters.Add(new ScopeTreeLookupParameter<TContent>(parentsParameterName)); 43 } 44 } 45 private string childParameterName; 46 public string ChildParameterName { 47 get { return childParameterName; } 48 set { 49 if (childParameterName != null && Parameters.ContainsKey(childParameterName)) Parameters.Remove(childParameterName); 50 childParameterName = value; 51 if (!Parameters.ContainsKey(childParameterName)) Parameters.Add(new LookupParameter<TContent>(childParameterName)); 52 } 53 } 54 55 public IScopeTreeLookupParameter<TContent> ParentsParameter { 56 get { return (IScopeTreeLookupParameter<TContent>)Parameters[ParentsParameterName]; } 57 } 58 59 public ILookupParameter<TContent> ChildParameter { 60 get { return (ILookupParameter<TContent>)Parameters[ChildParameterName]; } 61 } 35 private const string defaultParentsParameterName = "Parents"; 36 private const string defaultChildParameterName = "Child"; 37 public IScopeTreeLookupParameter<TContent> ParentsParameter; 38 public ILookupParameter<TContent> ChildParameter; 62 39 63 40 protected AfterCrossoverOperator(AfterCrossoverOperator<TGraph, TVertex, TContent> original, Cloner cloner) 64 41 : base(original, cloner) { 65 ParentsParameterName = original.ParentsParameterName;66 ChildParameterName = original.ChildParameterName;67 42 } 68 43 public override IDeepCloneable Clone(Cloner cloner) { … … 70 45 } 71 46 72 public AfterCrossoverOperator() { } 47 public AfterCrossoverOperator() { 48 ParentsParameter = new ScopeTreeLookupParameter<TContent>(defaultParentsParameterName); 49 ChildParameter = new LookupParameter<TContent>(defaultChildParameterName); 50 Parameters.Add(ParentsParameter); 51 Parameters.Add(ChildParameter); 52 } 73 53 74 54 public override IOperation Apply() { 75 55 // var parentVertices = ParentsParameter.ActualValue.Select(x => GenealogyGraph[x].Last()).ToList(); 76 56 var lastGen = GenealogyGraph.Ranks[Generations.Value].ToList(); 77 var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => lastGen[int.Parse(s.Name)]).ToList(); 57 var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => lastGen[int.Parse(s.Name)]).ToList(); // because the individuals in the execution scope are copies of the ones in the graph 58 78 59 var childVertex = new TVertex { 79 60 Content = ChildParameter.ActualValue, … … 85 66 v.AddForwardArc(childVertex); 86 67 } 68 // if (parentVertices[0].Content == parentVertices[1].Content) 69 // throw new Exception("Self-crossover"); 87 70 return base.Apply(); 88 71 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterManipulatorOperator.cs
r10278 r10285 33 33 where TContent : class,IItem { 34 34 35 private string childParameterName; 36 public string ChildParameterName { 37 get { return childParameterName; } 38 set { 39 if (childParameterName != null && Parameters.ContainsKey(childParameterName)) Parameters.Remove(childParameterName); 40 childParameterName = value; 41 if (!Parameters.ContainsKey(childParameterName)) Parameters.Add(new LookupParameter<TContent>(childParameterName)); 42 } 43 } 35 private const string ChildParameterName = "Child"; 36 public ILookupParameter<TContent> ChildParameter; 44 37 45 #region parameter properties46 public ILookupParameter<TContent> ChildParameter {47 get { return (ILookupParameter<TContent>)Parameters[ChildParameterName]; }48 }49 #endregion50 38 protected AfterManipulatorOperator(AfterManipulatorOperator<TGraph, TVertex, TContent> original, Cloner cloner) 51 39 : base(original, cloner) { … … 55 43 } 56 44 57 public AfterManipulatorOperator() { } 45 public AfterManipulatorOperator() { 46 ChildParameter = new LookupParameter<TContent>(ChildParameterName); 47 Parameters.Add(ChildParameter); 48 } 58 49 59 50 public override IOperation Apply() { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r10278 r10285 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 32 34 where TVertex : class,IGenealogyGraphNode<TContent>, new() 33 35 where TContent : class,IItem { 34 private string childParameterName;35 public string ChildParameterName {36 get { return childParameterName; }37 set {38 if (childParameterName != null && Parameters.ContainsKey(childParameterName)) Parameters.Remove(childParameterName);39 childParameterName = value;40 if (!Parameters.ContainsKey(childParameterName)) Parameters.Add(new LookupParameter<TContent>(childParameterName));41 }42 }43 36 44 #region parameter properties 45 public ILookupParameter<TContent> ChildParameter { 46 get { return (ILookupParameter<TContent>)Parameters[ChildParameterName]; } 47 } 48 #endregion 37 private const string ChildParameterName = "Child"; 38 public ILookupParameter<TContent> ChildParameter; 39 49 40 protected BeforeManipulatorOperator(BeforeManipulatorOperator<TGraph, TVertex, TContent> original, Cloner cloner) 50 41 : base(original, cloner) { … … 54 45 } 55 46 56 public BeforeManipulatorOperator() { } 47 public BeforeManipulatorOperator() { 48 ChildParameter = new LookupParameter<TContent>(ChildParameterName); 49 Parameters.Add(ChildParameter); 50 } 57 51 58 52 public override IOperation Apply() { 59 53 if (GenealogyGraph.Contains(ChildParameter.ActualValue)) { 60 54 // if the individual has been affected by crossover before mutation, we keep it in the graph and feed a clone of it to the mutation operator 61 ChildParameter.ActualValue = (TContent)ChildParameter.ActualValue.Clone(); 55 var child = ChildParameter.ActualValue; 56 var clone = (TContent)child.Clone(); 57 var vertex = GenealogyGraph[child].Last(); 58 vertex.Content = clone; 59 GenealogyGraph.Ranks[vertex.Rank].Remove(vertex); 60 var newVertex = new TVertex { 61 Content = child, 62 Rank = vertex.Rank 63 }; 64 vertex.Rank -= 0.5; 65 if (!GenealogyGraph.Ranks.ContainsKey(vertex.Rank)) { 66 GenealogyGraph.Ranks[vertex.Rank] = new LinkedList<TVertex>(); 67 } 68 GenealogyGraph.Ranks[vertex.Rank].AddLast(vertex); 69 70 newVertex.AddForwardArc(vertex); 71 vertex.AddReverseArc(vertex); 72 } else { 73 // mutation should never happen without crossover 62 74 } 63 75 return base.Apply(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/EvolutionTrackingOperator.cs
r10278 r10285 33 33 where TContent : class,IItem { 34 34 // evolution tracking-related parameters 35 private const string ResultsParameterName = "Results";36 private const string PopulationGraphParameterName = "PopulationGraph";37 private const string GenerationsParameterName = "Generations";35 private const string resultsParameterName = "Results"; 36 private const string populationGraphParameterName = "PopulationGraph"; 37 private const string generationsParameterName = "Generations"; 38 38 39 39 public ILookupParameter<ResultCollection> ResultsParameter { 40 get { return (ILookupParameter<ResultCollection>)Parameters[ ResultsParameterName]; }40 get { return (ILookupParameter<ResultCollection>)Parameters[resultsParameterName]; } 41 41 } 42 42 public ILookupParameter<IntValue> GenerationsParameter { 43 get { return (ILookupParameter<IntValue>)Parameters[ GenerationsParameterName]; }43 get { return (ILookupParameter<IntValue>)Parameters[generationsParameterName]; } 44 44 } 45 45 public ResultCollection Results { … … 52 52 get { 53 53 IResult result; 54 if (!Results.ContainsKey( PopulationGraphParameterName)) {55 result = new Result( PopulationGraphParameterName, new GenealogyGraph<TVertex, TContent>());54 if (!Results.ContainsKey(populationGraphParameterName)) { 55 result = new Result(populationGraphParameterName, new GenealogyGraph<TVertex, TContent>()); 56 56 Results.Add(result); 57 57 } else { 58 result = Results[ PopulationGraphParameterName];58 result = Results[populationGraphParameterName]; 59 59 } 60 60 var graph = (GenealogyGraph<TVertex, TContent>)result.Value; … … 63 63 } 64 64 public EvolutionTrackingOperator() { 65 Parameters.Add(new LookupParameter<IntValue>( GenerationsParameterName));66 Parameters.Add(new LookupParameter<ResultCollection>( ResultsParameterName));65 Parameters.Add(new LookupParameter<IntValue>(generationsParameterName)); 66 Parameters.Add(new LookupParameter<ResultCollection>(resultsParameterName)); 67 67 } 68 68 protected EvolutionTrackingOperator(EvolutionTrackingOperator<TGraph, TVertex, TContent> original, Cloner cloner) -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/SymbolGraph.cs
r10278 r10285 76 76 public IVertex Target { get; set; } 77 77 public double Weight { get; set; } 78 79 public object Data { get; set; } 78 80 } 79 81 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r10271 r10285 167 167 <Private>False</Private> 168 168 </Reference> 169 <Reference Include="HeuristicLab.Visualization-3.3, Version=3.3.0.9491, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 170 <SpecificVersion>False</SpecificVersion> 171 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Visualization-3.3.dll</HintPath> 172 </Reference> 169 173 <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 170 174 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Visualization.ChartControlsExtensions-3.3.dll</HintPath> … … 195 199 <DependentUpon>InteractiveSymbolicExpressionTreeChart.cs</DependentUpon> 196 200 </Compile> 197 <Compile Include="LatexSymbolicDataAnalysisModelView.cs" /> 201 <Compile Include="LatexSymbolicDataAnalysisModelView.cs"> 202 <SubType>UserControl</SubType> 203 </Compile> 198 204 <Compile Include="LatexSymbolicDataAnalysisModelView.designer.cs"> 199 205 <DependentUpon>LatexSymbolicDataAnalysisModelView.cs</DependentUpon> … … 212 218 <Compile Include="SlidingWindowDataView.Designer.cs"> 213 219 <DependentUpon>SlidingWindowDataView.cs</DependentUpon> 220 </Compile> 221 <Compile Include="SymbolicDataAnalysisGenealogyView.cs"> 222 <SubType>UserControl</SubType> 223 </Compile> 224 <Compile Include="SymbolicDataAnalysisGenealogyView.Designer.cs"> 225 <DependentUpon>SymbolicDataAnalysisGenealogyView.cs</DependentUpon> 214 226 </Compile> 215 227 <Compile Include="TextualSymbolicDataAnalysisModelView.cs"> … … 295 307 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4</Name> 296 308 <Private>False</Private> 309 </ProjectReference> 310 <ProjectReference Include="..\..\HeuristicLab.EvolutionTracking.Views\3.4\HeuristicLab.EvolutionTracking.Views-3.4.csproj"> 311 <Project>{318dfe8c-ca23-4f1b-a4ac-62b425060241}</Project> 312 <Name>HeuristicLab.EvolutionTracking.Views-3.4</Name> 313 </ProjectReference> 314 <ProjectReference Include="..\..\HeuristicLab.EvolutionTracking\3.4\HeuristicLab.EvolutionTracking-3.4.csproj"> 315 <Project>{1f75cea3-464f-4a6f-b2f0-04b9841ebc16}</Project> 316 <Name>HeuristicLab.EvolutionTracking-3.4</Name> 297 317 </ProjectReference> 298 318 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> … … 323 343 <CopyToOutputDirectory>Always</CopyToOutputDirectory> 324 344 </Content> 345 </ItemGroup> 346 <ItemGroup> 347 <EmbeddedResource Include="SymbolicDataAnalysisGenealogyView.resx"> 348 <DependentUpon>SymbolicDataAnalysisGenealogyView.cs</DependentUpon> 349 </EmbeddedResource> 325 350 </ItemGroup> 326 351 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r10278 r10285 358 358 // add tracking analyzer 359 359 foreach (var op in operators.OfType<GenealogyAnalyzer<TGraph, TVertex, ISymbolicExpressionTree>>()) { 360 // get crossover parameter names 360 361 var crossover = operators.OfType<ISymbolicExpressionTreeCrossover>().First(); 361 362 op.CrossoverParentsParameterName = crossover.ParentsParameter.Name; 362 363 op.CrossoverChildParameterName = crossover.ChildParameter.Name; 364 // get munipulator parameter names 363 365 var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().First(); 364 366 op.ManipulatorChildParameterName = manipulator.SymbolicExpressionTreeParameter.Name; 365 var creator = operators.OfType<ISymbolicExpressionTreeCreator>().First();366 op.SolutionCreatorIndividualParameterName = creator.SymbolicExpressionTreeParameter.Name;367 367 } 368 368 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs
r9456 r10285 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.EvolutionTracking; 27 29 using HeuristicLab.Optimization; 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 33 using TGraph = HeuristicLab.EvolutionTracking.IGenealogyGraph<HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>, 34 HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>; 35 using TVertex = HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>; 30 36 31 37 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 115 121 op.MaximizationParameter.ActualName = MaximizationParameterName; 116 122 } 123 124 foreach (var op in Operators.OfType<GenealogyAnalyzer<TGraph, TVertex, ISymbolicExpressionTree>>()) { 125 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 126 op.PopulationParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; 127 } 117 128 } 118 129 }
Note: See TracChangeset
for help on using the changeset viewer.