Changeset 3107
- Timestamp:
- 03/19/10 04:56:06 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 added
- 4 deleted
- 11 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs
r3095 r3107 183 183 ParameterizeStochasticOperator(Problem.SolutionCreator); 184 184 ParameterizeStochasticOperator(Problem.Evaluator); 185 ParameterizeStochasticOperator(Problem.Visualizer); 185 186 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 186 187 ParameterizeSolutionsCreator(); … … 204 205 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 205 206 base.Problem_EvaluatorChanged(sender, e); 207 } 208 protected override void Problem_VisualizerChanged(object sender, EventArgs e) { 209 ParameterizeStochasticOperator(Problem.Visualizer); 210 ParameterizeSGAMainLoop(); 211 base.Problem_VisualizerChanged(sender, e); 206 212 } 207 213 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { … … 253 259 SGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 254 260 SGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 261 SGAMainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name; 262 SGAMainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName; 255 263 } 256 264 private void ParameterizeStochasticOperator(IOperator op) { -
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAMainLoop.cs
r3096 r3107 74 74 get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; } 75 75 } 76 public ValueLookupParameter<IOperator> VisualizerParameter { 77 get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; } 78 } 79 public LookupParameter<IItem> VisualizationParameter { 80 get { return (LookupParameter<IItem>)Parameters["Visualization"]; } 81 } 76 82 private ScopeParameter CurrentScopeParameter { 77 83 get { return (ScopeParameter)Parameters["CurrentScope"]; } … … 104 110 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.")); 105 111 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 112 Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions.")); 113 Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions.")); 106 114 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the SGA should be applied.")); 107 115 #endregion … … 114 122 DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector(); 115 123 QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator(); 124 Placeholder visualizer1 = new Placeholder(); 116 125 ResultsCollector resultsCollector = new ResultsCollector(); 117 126 Placeholder selector = new Placeholder(); … … 135 144 DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector(); 136 145 QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator(); 146 Placeholder visualizer2 = new Placeholder(); 137 147 ConditionalBranch conditionalBranch = new ConditionalBranch(); 138 148 … … 164 174 qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 165 175 qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality"; 176 177 visualizer1.Name = "Visualizer"; 178 visualizer1.OperatorParameter.ActualName = "Visualizer"; 166 179 167 180 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); … … 173 186 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest")); 174 187 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest")); 188 resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, "Visualization")); 175 189 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities")); 176 190 resultsCollector.ResultsParameter.ActualName = "Results"; … … 233 247 qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest"; 234 248 qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality"; 249 250 visualizer2.Name = "Visualizer"; 251 visualizer2.OperatorParameter.ActualName = "Visualizer"; 235 252 236 253 conditionalBranch.ConditionParameter.ActualName = "Terminate"; … … 244 261 bestAverageWorstQualityCalculator1.Successor = dataTableValuesCollector1; 245 262 dataTableValuesCollector1.Successor = qualityDifferenceCalculator1; 246 qualityDifferenceCalculator1.Successor = resultsCollector; 263 qualityDifferenceCalculator1.Successor = visualizer1; 264 visualizer1.Successor = resultsCollector; 247 265 resultsCollector.Successor = selector; 248 266 selector.Successor = sequentialSubScopesProcessor1; … … 272 290 bestAverageWorstQualityCalculator2.Successor = dataTableValuesCollector2; 273 291 dataTableValuesCollector2.Successor = qualityDifferenceCalculator2; 274 qualityDifferenceCalculator2.Successor = conditionalBranch; 292 qualityDifferenceCalculator2.Successor = visualizer2; 293 visualizer2.Successor = conditionalBranch; 275 294 conditionalBranch.FalseBranch = selector; 276 295 conditionalBranch.TrueBranch = null; -
trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
r3017 r3107 152 152 problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged); 153 153 problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged); 154 problem.VisualizerChanged -= new EventHandler(Problem_VisualizerChanged); 154 155 problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged); 155 156 } … … 157 158 problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged); 158 159 problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged); 160 problem.VisualizerChanged += new EventHandler(Problem_VisualizerChanged); 159 161 problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged); 160 162 } … … 162 164 protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { } 163 165 protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { } 166 protected virtual void Problem_VisualizerChanged(object sender, EventArgs e) { } 164 167 protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { } 165 168 #endregion -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r3104 r3107 86 86 <None Include="HeuristicLabOptimizationPlugin.cs.frame" /> 87 87 <Compile Include="Algorithm.cs" /> 88 <Compile Include="Interfaces\ISolutionVisualizer.cs" /> 88 <Compile Include="Interfaces\IMultiObjectiveSolutionsVisualizer.cs" /> 89 <Compile Include="Interfaces\ISingleObjectiveSolutionsVisualizer.cs" /> 90 <Compile Include="Interfaces\ISolutionsVisualizer.cs" /> 89 91 <Compile Include="Interfaces\IDiscreteDoubleValueModifier.cs" /> 90 92 <Compile Include="Interfaces\IExhaustiveMoveGenerator.cs" /> -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IProblem.cs
r2975 r3107 33 33 IParameter EvaluatorParameter { get; } 34 34 IEvaluator Evaluator { get; } 35 IParameter VisualizerParameter { get; } 36 ISolutionsVisualizer Visualizer { get; } 35 37 IEnumerable<IOperator> Operators { get; } 36 38 37 39 event EventHandler SolutionCreatorChanged; 38 40 event EventHandler EvaluatorChanged; 41 event EventHandler VisualizerChanged; 39 42 event EventHandler OperatorsChanged; 40 43 } -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISolutionsVisualizer.cs
r3106 r3107 26 26 /// An interface which represents an operator for visualizing solutions. 27 27 /// </summary> 28 public interface ISolution Visualizer : IOperator {29 ILookupParameter <IItem>VisualizationParameter { get; }28 public interface ISolutionsVisualizer : IOperator { 29 ILookupParameter VisualizationParameter { get; } 30 30 } 31 31 } -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Knapsack.cs
r3080 r3107 73 73 get { return EvaluatorParameter; } 74 74 } 75 IParameter IProblem.VisualizerParameter { 76 get { throw new NotImplementedException(); } 77 } 75 78 public OptionalValueParameter<DoubleValue> BestKnownQualityParameter { 76 79 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } … … 98 101 IEvaluator IProblem.Evaluator { 99 102 get { return EvaluatorParameter.Value; } 103 } 104 ISolutionsVisualizer IProblem.Visualizer { 105 get { throw new NotImplementedException(); } 100 106 } 101 107 public DoubleValue BestKnownQuality { … … 153 159 EvaluatorChanged(this, EventArgs.Empty); 154 160 } 161 public event EventHandler VisualizerChanged; 155 162 public event EventHandler OperatorsChanged; 156 163 private void OnOperatorsChanged() { -
trunk/sources/HeuristicLab.Problems.OneMax/3.3/Onemax.cs
r3080 r3107 64 64 get { return EvaluatorParameter; } 65 65 } 66 IParameter IProblem.VisualizerParameter { 67 get { throw new NotImplementedException(); } 68 } 66 69 public ValueParameter<DoubleValue> BestKnownQualityParameter { 67 70 get { return (ValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } … … 89 92 IEvaluator IProblem.Evaluator { 90 93 get { return EvaluatorParameter.Value; } 94 } 95 ISolutionsVisualizer IProblem.Visualizer { 96 get { throw new NotImplementedException(); } 91 97 } 92 98 public DoubleValue BestKnownQuality { … … 138 144 EvaluatorChanged(this, EventArgs.Empty); 139 145 } 146 public event EventHandler VisualizerChanged; 140 147 public event EventHandler OperatorsChanged; 141 148 private void OnOperatorsChanged() { -
trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/HeuristicLab.Problems.TSP.Views-3.3.csproj
r2900 r3107 85 85 </ItemGroup> 86 86 <ItemGroup> 87 <Compile Include="PathTSPTourView.cs"> 88 <SubType>UserControl</SubType> 89 </Compile> 90 <Compile Include="PathTSPTourView.Designer.cs"> 91 <DependentUpon>PathTSPTourView.cs</DependentUpon> 92 </Compile> 87 93 <Compile Include="HeuristicLabProblemsTSPViewsPlugin.cs" /> 88 94 <Compile Include="TSPView.cs"> … … 111 117 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> 112 118 <Name>HeuristicLab.Core-3.3</Name> 119 </ProjectReference> 120 <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj"> 121 <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project> 122 <Name>HeuristicLab.Data-3.3</Name> 123 </ProjectReference> 124 <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj"> 125 <Project>{DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA}</Project> 126 <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name> 113 127 </ProjectReference> 114 128 <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.2\HeuristicLab.MainForm.WindowsForms-3.2.csproj"> -
trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/HeuristicLabProblemsTSPViewsPlugin.cs.frame
r2883 r3107 31 31 [PluginDependency("HeuristicLab.Core", "3.3")] 32 32 [PluginDependency("HeuristicLab.Core.Views", "3.3")] 33 [PluginDependency("HeuristicLab.Data", "3.3")] 34 [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")] 33 35 [PluginDependency("HeuristicLab.MainForm", "3.2")] 34 36 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.2")] -
trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj
r3097 r3107 84 84 </ItemGroup> 85 85 <ItemGroup> 86 <Compile Include="Interfaces\IPathTSPTourVisualizer.cs" /> 87 <Compile Include="Interfaces\ITSPTourVisualizer.cs" /> 88 <Compile Include="TSPTour.cs" /> 89 <Compile Include="Visualizers\PathTSPTourVisualizer.cs" /> 86 <Compile Include="Interfaces\ICoordinatesTSPSolutionsVisualizer.cs" /> 87 <Compile Include="Interfaces\IPathCoordinatesTSPSolutionsVisualizer.cs" /> 88 <Compile Include="Interfaces\ITSPSolutionsVisualizer.cs" /> 89 <Compile Include="PathTSPTour.cs" /> 90 <Compile Include="Visualizers\BestPathTSPTourVisualizer.cs" /> 90 91 <Compile Include="Evaluators\TSPCoordinatesPathEvaluator.cs" /> 91 92 <Compile Include="Evaluators\TSPEvaluator.cs" /> -
trunk/sources/HeuristicLab.Problems.TSP/3.3/Interfaces/IPathCoordinatesTSPSolutionsVisualizer.cs
r3106 r3107 25 25 namespace HeuristicLab.Problems.TSP { 26 26 /// <summary> 27 /// An interface which represents an operator for visualizing tours of Traveling Salesman Problems given in path representation .27 /// An interface which represents an operator for visualizing tours of Traveling Salesman Problems given in path representation using city coordinates. 28 28 /// </summary> 29 public interface IPath TSPTourVisualizer : ITSPTourVisualizer {30 ILookupParameter< Permutation> PermutationParameter { get; }29 public interface IPathCoordinatesTSPSolutionsVisualizer : ICoordinatesTSPSolutionsVisualizer { 30 ILookupParameter<ItemArray<Permutation>> PermutationParameter { get; } 31 31 } 32 32 } -
trunk/sources/HeuristicLab.Problems.TSP/3.3/Interfaces/ITSPSolutionsVisualizer.cs
r3106 r3107 20 20 #endregion 21 21 22 using HeuristicLab.Core;23 using HeuristicLab.Data;24 22 using HeuristicLab.Optimization; 25 23 26 24 namespace HeuristicLab.Problems.TSP { 27 25 /// <summary> 28 /// An interface which represents an operator for visualizing tours of Traveling Salesman Problems.26 /// An interface which represents an operator for visualizing solutions of Traveling Salesman Problems. 29 27 /// </summary> 30 public interface ITSPTourVisualizer : ISolutionVisualizer { 31 ILookupParameter<DoubleMatrix> CoordinatesParameter { get; } 32 } 28 public interface ITSPSolutionsVisualizer : ISingleObjectiveSolutionsVisualizer { } 33 29 } -
trunk/sources/HeuristicLab.Problems.TSP/3.3/PathTSPTour.cs
r3104 r3107 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 28 29 namespace HeuristicLab.Problems.TSP { 29 30 /// <summary> 30 /// Represents a tour of a Traveling Salesman Problem which can be visualized in the GUI.31 /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI. 31 32 /// </summary> 32 [Item(" TSPTour", "Represents a tour of a Traveling Salesman Problemwhich can be visualized in the GUI.")]33 [Item("PathTSPTour", "Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.")] 33 34 [StorableClass] 34 public sealed class TSPTour : Item {35 public sealed class PathTSPTour : Item { 35 36 private DoubleMatrix coordinates; 36 37 [Storable] … … 40 41 if (value == null) throw new ArgumentNullException(); 41 42 if (coordinates != value) { 43 if (coordinates != null) DeregisterCoordinatesEvents(); 42 44 coordinates = value; 45 if (coordinates != null) RegisterCoordinatesEvents(); 43 46 OnCoordinatesChanged(); 44 47 } … … 52 55 if (value == null) throw new ArgumentNullException(); 53 56 if (permutation != value) { 57 if (permutation != null) DeregisterPermutationEvents(); 54 58 permutation = value; 59 if (permutation != null) RegisterCoordinatesEvents(); 55 60 OnPermutationChanged(); 56 61 } … … 58 63 } 59 64 60 private TSPTour() : base() { }61 public TSPTour(DoubleMatrix coordinates, Permutation permutation)65 private PathTSPTour() : base() { } 66 public PathTSPTour(DoubleMatrix coordinates, Permutation permutation) 62 67 : base() { 63 if ((coordinates == null) || (permutation == null)) throw new ArgumentNullException(); 64 this.coordinates = coordinates; 65 this.permutation = permutation; 68 Coordinates = coordinates; 69 Permutation = permutation; 66 70 } 67 71 68 72 public override IDeepCloneable Clone(Cloner cloner) { 69 TSPTour clone = new TSPTour((DoubleMatrix)cloner.Clone(coordinates), (Permutation)cloner.Clone(permutation));73 PathTSPTour clone = new PathTSPTour(); 70 74 cloner.RegisterClonedObject(this, clone); 75 clone.Coordinates = (DoubleMatrix)cloner.Clone(coordinates); 76 clone.Permutation = (Permutation)cloner.Clone(permutation); 71 77 return clone; 72 78 } 73 79 80 #region Events 74 81 public event EventHandler CoordinatesChanged; 75 82 private void OnCoordinatesChanged() { … … 82 89 PermutationChanged(this, EventArgs.Empty); 83 90 } 91 92 private void RegisterCoordinatesEvents() { 93 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 94 Coordinates.Reset += new EventHandler(Coordinates_Reset); 95 } 96 private void DeregisterCoordinatesEvents() { 97 Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 98 Coordinates.Reset -= new EventHandler(Coordinates_Reset); 99 } 100 private void RegisterPermutationEvents() { 101 Permutation.ItemChanged += new EventHandler<EventArgs<int>>(Permutation_ItemChanged); 102 Permutation.Reset += new EventHandler(Permutation_Reset); 103 } 104 private void DeregisterPermutationEvents() { 105 Permutation.ItemChanged -= new EventHandler<EventArgs<int>>(Permutation_ItemChanged); 106 Permutation.Reset -= new EventHandler(Permutation_Reset); 107 } 108 109 private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) { 110 OnCoordinatesChanged(); 111 } 112 private void Coordinates_Reset(object sender, EventArgs e) { 113 OnCoordinatesChanged(); 114 } 115 private void Permutation_ItemChanged(object sender, EventArgs<int> e) { 116 OnPermutationChanged(); 117 } 118 private void Permutation_Reset(object sender, EventArgs e) { 119 OnPermutationChanged(); 120 } 121 #endregion 84 122 } 85 123 } -
trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs
r3099 r3107 70 70 get { return EvaluatorParameter; } 71 71 } 72 public OptionalValueParameter<ITSPSolutionsVisualizer> VisualizerParameter { 73 get { return (OptionalValueParameter<ITSPSolutionsVisualizer>)Parameters["Visualizer"]; } 74 } 75 IParameter IProblem.VisualizerParameter { 76 get { return VisualizerParameter; } 77 } 72 78 public OptionalValueParameter<DoubleValue> BestKnownQualityParameter { 73 79 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } … … 108 114 get { return EvaluatorParameter.Value; } 109 115 } 116 public ITSPSolutionsVisualizer Visualizer { 117 get { return VisualizerParameter.Value; } 118 set { VisualizerParameter.Value = value; } 119 } 120 ISolutionsVisualizer IProblem.Visualizer { 121 get { return VisualizerParameter.Value; } 122 } 110 123 public DoubleValue BestKnownQuality { 111 124 get { return BestKnownQualityParameter.Value; } … … 122 135 RandomPermutationCreator creator = new RandomPermutationCreator(); 123 136 TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator(); 137 BestPathTSPTourVisualizer visualizer = new BestPathTSPTourVisualizer(); 124 138 125 139 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false))); … … 129 143 Parameters.Add(new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator)); 130 144 Parameters.Add(new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.", evaluator)); 145 Parameters.Add(new OptionalValueParameter<ITSPSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize TSP solutions.", visualizer)); 131 146 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance.")); 132 147 … … 135 150 ParameterizeSolutionCreator(); 136 151 ParameterizeEvaluator(); 152 ParameterizeVisualizer(); 137 153 138 154 Initialize(); … … 164 180 EvaluatorChanged(this, EventArgs.Empty); 165 181 } 182 public event EventHandler VisualizerChanged; 183 private void OnVisualizerChanged() { 184 if (VisualizerChanged != null) 185 VisualizerChanged(this, EventArgs.Empty); 186 } 166 187 public event EventHandler OperatorsChanged; 167 188 private void OnOperatorsChanged() { … … 187 208 ParameterizeSolutionCreator(); 188 209 ParameterizeEvaluator(); 210 ParameterizeVisualizer(); 189 211 ParameterizeOperators(); 190 212 OnSolutionCreatorChanged(); … … 192 214 private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) { 193 215 ParameterizeEvaluator(); 216 ParameterizeVisualizer(); 194 217 ParameterizeOperators(); 195 218 } 196 219 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 197 220 ParameterizeEvaluator(); 221 ParameterizeVisualizer(); 198 222 ClearDistanceMatrix(); 199 223 OnEvaluatorChanged(); 224 } 225 private void VisualizerParameter_ValueChanged(object sender, EventArgs e) { 226 ParameterizeVisualizer(); 227 OnVisualizerChanged(); 200 228 } 201 229 private void MoveGenerator_TwoOptMoveParameter_ActualNameChanged(object sender, EventArgs e) { … … 223 251 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 224 252 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 253 VisualizerParameter.ValueChanged += new EventHandler(VisualizerParameter_ValueChanged); 225 254 } 226 255 private void InitializeOperators() { … … 257 286 } 258 287 } 288 private void ParameterizeVisualizer() { 289 Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 290 if (Visualizer is ICoordinatesTSPSolutionsVisualizer) 291 ((ICoordinatesTSPSolutionsVisualizer)Visualizer).CoordinatesParameter.ActualName = CoordinatesParameter.Name; 292 if (Visualizer is IPathCoordinatesTSPSolutionsVisualizer) 293 ((IPathCoordinatesTSPSolutionsVisualizer)Visualizer).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 294 } 259 295 private void ParameterizeOperators() { 260 296 foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) { -
trunk/sources/HeuristicLab.Problems.TSP/3.3/Visualizers/BestPathTSPTourVisualizer.cs
r3106 r3107 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Encodings.PermutationEncoding; 25 26 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization; 26 28 using HeuristicLab.Parameters; 27 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 29 31 namespace HeuristicLab.Problems.TSP { 30 32 /// <summary> 31 /// An operator for visualizing t ours of Traveling Salesman Problems given in path representation.33 /// An operator for visualizing the best tour of Traveling Salesman Problems given in path representation using city coordinates. 32 34 /// </summary> 33 [Item(" PathTSPTourVisualizer", "An operator for visualizing tours of Traveling Salesman Problems given in path representation.")]35 [Item("BestPathTSPTourVisualizer", "An operator for visualizing the best tour of Traveling Salesman Problems given in path representation using city coordinates.")] 34 36 [StorableClass] 35 public sealed class PathTSPTourVisualizer : SingleSuccessorOperator, IPathTSPTourVisualizer {37 public sealed class BestPathTSPTourVisualizer : SingleSuccessorOperator, IPathCoordinatesTSPSolutionsVisualizer { 36 38 public ILookupParameter<DoubleMatrix> CoordinatesParameter { 37 39 get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 38 40 } 39 public ILookupParameter< Permutation> PermutationParameter {40 get { return (ILookupParameter< Permutation>)Parameters["Permutation"]; }41 public ILookupParameter<ItemArray<Permutation>> PermutationParameter { 42 get { return (ILookupParameter<ItemArray<Permutation>>)Parameters["Permutation"]; } 41 43 } 42 public ILookupParameter<IItem> VisualizationParameter { 43 get { return (ILookupParameter<IItem>)Parameters["Visualization"]; } 44 public ILookupParameter<ItemArray<DoubleValue>> QualityParameter { 45 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; } 46 } 47 public ILookupParameter<PathTSPTour> PathTSPTourParameter { 48 get { return (ILookupParameter<PathTSPTour>)Parameters["PathTSPTour"]; } 49 } 50 ILookupParameter ISolutionsVisualizer.VisualizationParameter { 51 get { return PathTSPTourParameter; } 44 52 } 45 53 46 public PathTSPTourVisualizer()54 public BestPathTSPTourVisualizer() 47 55 : base() { 48 56 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 49 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be visualized.")); 50 Parameters.Add(new LookupParameter<IItem>("Visualization", "An item which represents the visualization of the given TSP solution.")); 57 Parameters.Add(new SubScopesLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be visualized.")); 58 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be visualized.")); 59 Parameters.Add(new LookupParameter<PathTSPTour>("PathTSPTour", "The visual representation of the best TSP solution.")); 51 60 } 52 61 53 62 public override IOperation Apply() { 54 63 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 55 Permutation permutation = PermutationParameter.ActualValue; 56 TSPTour tour = new TSPTour(coordinates, permutation); 57 VisualizationParameter.ActualValue = tour; 64 ItemArray<Permutation> permutations = PermutationParameter.ActualValue; 65 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 66 67 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 68 69 PathTSPTour tour = PathTSPTourParameter.ActualValue; 70 if (tour == null) PathTSPTourParameter.ActualValue = new PathTSPTour(coordinates, permutations[i]); 71 else { 72 tour.Coordinates = coordinates; 73 tour.Permutation = permutations[i]; 74 } 58 75 return base.Apply(); 59 76 }
Note: See TracChangeset
for help on using the changeset viewer.