Changeset 3861
- Timestamp:
- 05/27/10 09:14:49 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluationProblem.cs
r3860 r3861 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Drawing; 25 using System.Linq; 26 using HeuristicLab.Collections; 22 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 23 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 using HeuristicLab.Parameters;25 using System.Drawing;26 using HeuristicLab.Optimization;27 using HeuristicLab.Data;28 using HeuristicLab.Operators;29 32 30 33 namespace HeuristicLab.Problems.ExternalEvaluation { … … 35 38 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; } 36 39 } 40 public new ParameterCollection Parameters { 41 get { return base.Parameters; } 42 } 43 IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters { 44 get { return Parameters; } 45 } 37 46 38 47 #region Parameters … … 49 58 get { return MaximizationParameter; } 50 59 } 51 public ValueParameter<I Operator> SolutionCreatorParameter {52 get { return (ValueParameter<I Operator>)Parameters["SolutionCreator"]; }60 public ValueParameter<ISolutionCreator> SolutionCreatorParameter { 61 get { return (ValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; } 53 62 } 54 63 IParameter IProblem.SolutionCreatorParameter { … … 66 75 public OptionalValueParameter<IScope> BestKnownSolutionParameter { 67 76 get { return (OptionalValueParameter<IScope>)Parameters["BestKnownSolution"]; } 77 } 78 public ValueParameter<ItemList<IOperator>> OperatorsParameter { 79 get { return (ValueParameter<ItemList<IOperator>>)Parameters["Operators"]; } 68 80 } 69 81 #endregion … … 74 86 set { MaximizationParameter.Value = value; } 75 87 } 76 public I Operator SolutionCreator {88 public ISolutionCreator SolutionCreator { 77 89 get { return SolutionCreatorParameter.Value; } 78 90 set { SolutionCreatorParameter.Value = value; } … … 81 93 get { return SolutionCreatorParameter.Value; } 82 94 } 83 public I SingleObjectiveTestFunctionProblemEvaluator Evaluator {95 public IExternalEvaluationProblemEvaluator Evaluator { 84 96 get { return EvaluatorParameter.Value; } 85 97 set { EvaluatorParameter.Value = value; } … … 95 107 set { BestKnownQualityParameter.Value = value; } 96 108 } 97 private List<IOperator> operators;98 109 public IEnumerable<IOperator> Operators { 99 get { return operators; } 100 } 101 private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer { 102 get { return operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); } 103 } 104 #endregion 105 110 get { return OperatorsParameter.Value; } 111 } 112 private BestExternalEvaluationSolutionAnalyzer BestExternalEvaluationSolutionAnalyzer { 113 get { return OperatorsParameter.Value.OfType<BestExternalEvaluationSolutionAnalyzer>().FirstOrDefault(); } 114 } 115 #endregion 116 117 [StorableConstructor] 118 protected ExternalEvaluationProblem(bool deserializing) : base(deserializing) { } 106 119 public ExternalEvaluationProblem() 107 120 : base() { 108 121 ExternalEvaluator evaluator = new ExternalEvaluator(); 109 E mptyOperator solutionCreator = new EmptyOperator();122 ExternalEvaluationSolutionCreator solutionCreator = new ExternalEvaluationSolutionCreator(); 110 123 111 124 Parameters.Add(new ValueParameter<IExternalEvaluationDriver>("Driver", "The communication driver that is used to exchange data with the external process.")); 112 125 Parameters.Add(new ValueParameter<IExternalEvaluationProblemEvaluator>("Evaluator", "The evaluator that collects the values to exchange.", evaluator)); 113 126 Parameters.Add(new ValueParameter<IOperator>("SolutionCreator", "An operator to create the solution components.", solutionCreator)); 114 } 127 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as most test functions are minimization problems.", new BoolValue(false))); 128 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); 129 Parameters.Add(new OptionalValueParameter<IScope>("BestKnownSolution", "The best known solution for this external evaluation problem.")); 130 Parameters.Add(new ValueParameter<ItemList<IOperator>>("Operators", "The operators that are passed to the algorithm.", new ItemList<IOperator>())); 131 132 InitializeOperators(); 133 AttachEventHandlers(); 134 } 135 136 #region Events 137 public event EventHandler SolutionCreatorChanged; 138 private void OnSolutionCreatorChanged() { 139 EventHandler handler = SolutionCreatorChanged; 140 if (handler != null) handler(this, EventArgs.Empty); 141 } 142 public event EventHandler EvaluatorChanged; 143 private void OnEvaluatorChanged() { 144 EventHandler handler = EvaluatorChanged; 145 if (handler != null) handler(this, EventArgs.Empty); 146 } 147 public event EventHandler OperatorsChanged; 148 private void OnOperatorsChanged() { 149 EventHandler handler = OperatorsChanged; 150 if (handler != null) handler(this, EventArgs.Empty); 151 } 152 public event EventHandler Reset; 153 private void OnReset() { 154 EventHandler handler = Reset; 155 if (handler != null) handler(this, EventArgs.Empty); 156 } 157 158 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 159 OnSolutionCreatorChanged(); 160 } 161 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 162 OnEvaluatorChanged(); 163 } 164 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 165 // TODO: Following code is not yet approved behavior, but it's the best effort I can make here regarding wiring 166 string qualityName = Evaluator.QualityParameter.ActualName; 167 foreach (IOperator op in OperatorsParameter.Value) { 168 foreach (ILookupParameter<DoubleValue> param in op.Parameters.OfType<ILookupParameter<DoubleValue>>()) { 169 if (param.Name.Equals("Quality")) param.ActualName = qualityName; 170 } 171 foreach (IScopeTreeLookupParameter<DoubleValue> param in op.Parameters.OfType<IScopeTreeLookupParameter<DoubleValue>>()) { 172 if (param.Name.Equals("Quality")) param.ActualName = qualityName; 173 } 174 } 175 } 176 private void OperatorsParameter_ValueChanged(object sender, EventArgs e) { 177 OnOperatorsChanged(); 178 } 179 private void OperatorsParameter_Value_ItemsAdded(object sender, EventArgs e) { 180 OnOperatorsChanged(); 181 } 182 private void OperatorsParameter_Value_ItemsRemoved(object sender, EventArgs e) { 183 OnOperatorsChanged(); 184 } 185 private void OperatorsParameter_Value_CollectionReset(object sender, EventArgs e) { 186 OnOperatorsChanged(); 187 } 188 #endregion 189 190 #region Helpers 191 private void InitializeOperators() { 192 ItemList<IOperator> operators = OperatorsParameter.Value; 193 operators.Add(new BestExternalEvaluationSolutionAnalyzer()); 194 ParameterizeAnalyzers(); 195 } 196 [StorableHook(HookType.AfterDeserialization)] 197 private void AttachEventHandlers() { 198 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 199 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 200 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 201 OperatorsParameter.ValueChanged += new System.EventHandler(OperatorsParameter_ValueChanged); 202 OperatorsParameter.Value.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(OperatorsParameter_Value_ItemsAdded); 203 OperatorsParameter.Value.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(OperatorsParameter_Value_ItemsRemoved); 204 OperatorsParameter.Value.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(OperatorsParameter_Value_CollectionReset); 205 } 206 private void ParameterizeAnalyzers() { 207 BestExternalEvaluationSolutionAnalyzer.ResultsParameter.ActualName = "Results"; 208 BestExternalEvaluationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 209 BestExternalEvaluationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 210 BestExternalEvaluationSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 211 BestExternalEvaluationSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 212 } 213 private void ParameterizeEvaluator() { 214 Evaluator.DriverParameter.ActualName = DriverParameter.Name; 215 } 216 #endregion 115 217 } 116 218 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluationSolutionCreator.cs
r3859 r3861 33 33 [StorableClass] 34 34 public class ExternalEvaluationSolutionCreator : CheckedMultiOperator<IOperator>, ISolutionCreator { 35 public override IOperation Apply() { 36 OperationCollection result = new OperationCollection(); 37 foreach (IOperator op in Operators.CheckedItems.OrderBy(x => x.Index).Select(x => x.Value)) { 38 result.Add(ExecutionContext.CreateOperation(op)); 39 } 40 result.Add(base.Apply()); 41 return result; 42 } 35 43 } 36 44 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLab.Problems.ExternalEvaluation-3.3.csproj
r3860 r3861 79 79 </ItemGroup> 80 80 <ItemGroup> 81 <Compile Include="Analyzers\BestExternalEvaluationSolutionAnalyzer.cs" /> 81 82 <Compile Include="Drivers\ExternalEvaluationDriver.cs" /> 82 83 <Compile Include="Drivers\ExternalEvaluationProcessDriver.cs" /> -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IExternalEvaluationProblemEvaluator.cs
r3859 r3861 25 25 using System.Text; 26 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 27 29 28 30 namespace HeuristicLab.Problems.ExternalEvaluation { 29 31 public interface IExternalEvaluationProblemEvaluator : ISingleObjectiveEvaluator { 32 IValueLookupParameter<IExternalEvaluationDriver> DriverParameter { get; } 30 33 } 31 34 }
Note: See TracChangeset
for help on using the changeset viewer.