Changeset 5811 for branches/QAP/HeuristicLab.Optimization
- Timestamp:
- 03/23/11 09:28:34 (14 years ago)
- Location:
- branches/QAP/HeuristicLab.Optimization/3.3
- Files:
-
- 4 deleted
- 6 edited
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/QAP/HeuristicLab.Optimization/3.3
- Property svn:ignore
-
old new 3 3 obj 4 4 *.user 5 *.vs10x
-
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Optimization/3.3 merged: 5809
- Property svn:ignore
-
branches/QAP/HeuristicLab.Optimization/3.3/Algorithm.cs
r5445 r5811 224 224 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 225 225 values.Add("Execution Time", new TimeSpanValue(ExecutionTime)); 226 foreach (IResult result in Results) 227 values.Add(result.Name, result.Value); 226 CollectResultsRecursively("", Results, values); 227 } 228 229 private void CollectResultsRecursively(string path, ResultCollection results, IDictionary<string, IItem> values) { 230 foreach (IResult result in results) { 231 values.Add(path + result.Name, result.Value); 232 ResultCollection childCollection = result.Value as ResultCollection; 233 if (childCollection != null) { 234 CollectResultsRecursively(path + result.Name + ".", childCollection, values); 235 } 236 } 228 237 } 229 238 … … 283 292 284 293 protected virtual void DeregisterProblemEvents() { 285 problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged);286 problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged);287 294 problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged); 288 295 problem.Reset -= new EventHandler(Problem_Reset); 289 296 } 290 297 protected virtual void RegisterProblemEvents() { 291 problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged);292 problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged);293 298 problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged); 294 299 problem.Reset += new EventHandler(Problem_Reset); 295 300 } 296 protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { }297 protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { }298 301 protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { } 299 302 protected virtual void Problem_Reset(object sender, EventArgs e) { -
branches/QAP/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r5785 r5811 142 142 <Compile Include="BatchRun.cs" /> 143 143 <Compile Include="Interfaces\IDiscreteDoubleMatrixModifier.cs" /> 144 <Compile Include="HeuristicOptimizationEngineAlgorithm.cs" /> 144 145 <Compile Include="Interfaces\IGlobalParticleUpdater.cs" /> 145 146 <Compile Include="Interfaces\ILocalImprovementOperator.cs" /> 146 147 <Compile Include="Interfaces\ILocalParticleUpdater.cs" /> 148 <Compile Include="HeuristicOptimizationAlgorithm.cs" /> 149 <Compile Include="MultiObjectiveHeuristicOptimizationProblem.cs" /> 150 <Compile Include="HeuristicOptimizationProblem.cs" /> 151 <Compile Include="SingleObjectiveHeuristicOptimizationProblem.cs" /> 152 <Compile Include="Interfaces\IHeuristicOptimizationProblem.cs" /> 147 153 <Compile Include="Interfaces\IMultiAnalyzer.cs" /> 148 154 <Compile Include="Interfaces\IIterationBasedOperator.cs" /> … … 152 158 <Compile Include="Interfaces\ITopologyInitializer.cs" /> 153 159 <Compile Include="Interfaces\ITopologyUpdater.cs" /> 154 <Compile Include="MultiObjectiveProblem.cs" /> 160 <Compile Include="Interfaces\IMultiObjectiveHeuristicOptimizationProblem.cs" /> 161 <Compile Include="Interfaces\ISingleObjectiveHeuristicOptimizationProblem.cs" /> 155 162 <Compile Include="Problem.cs" /> 156 163 <Compile Include="RunCollectionConstraints\RunCollectionComparisonConstraint.cs" /> … … 188 195 <Compile Include="Interfaces\IReducer.cs" /> 189 196 <Compile Include="Interfaces\ISelector.cs" /> 190 <Compile Include="Interfaces\IMultiObjectiveProblem.cs" />191 197 <Compile Include="Interfaces\IMultiObjectiveEvaluator.cs" /> 192 198 <Compile Include="Interfaces\IAlgorithm.cs" /> … … 196 202 <Compile Include="Interfaces\IProblem.cs" /> 197 203 <Compile Include="Interfaces\ISingleObjectiveEvaluator.cs" /> 198 <Compile Include="Interfaces\ISingleObjectiveProblem.cs" />199 204 <Compile Include="Interfaces\ISolutionCreator.cs" /> 200 205 <Compile Include="Interfaces\IStochasticOperator.cs" /> … … 202 207 <Compile Include="Interfaces\ITabuMaker.cs" /> 203 208 <Compile Include="Result.cs" /> 204 <Compile Include="SingleObjectiveProblem.cs" />205 209 <Compile Include="UserDefinedAlgorithm.cs" /> 206 210 <Compile Include="EngineAlgorithm.cs" /> -
branches/QAP/HeuristicLab.Optimization/3.3/Interfaces/IProblem.cs
r5445 r5811 29 29 /// </summary> 30 30 public interface IProblem : IParameterizedNamedItem { 31 IParameter SolutionCreatorParameter { get; }32 ISolutionCreator SolutionCreator { get; }33 IParameter EvaluatorParameter { get; }34 IEvaluator Evaluator { get; }35 31 IEnumerable<IOperator> Operators { get; } 36 32 37 event EventHandler SolutionCreatorChanged;38 event EventHandler EvaluatorChanged;39 33 event EventHandler OperatorsChanged; 40 34 event EventHandler Reset; -
branches/QAP/HeuristicLab.Optimization/3.3/Problem.cs
r5445 r5811 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Parameters;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 … … 32 31 [Item("Problem", "Represents the base class for a problem.")] 33 32 [StorableClass] 34 public abstract class Problem<T, U> : ParameterizedNamedItem, IProblem 35 where T : class,IEvaluator 36 where U : class,ISolutionCreator { 37 private const string EvaluatorParameterName = "Evaluator"; 38 private const string SolutionCreateParameterName = "SolutionCreator"; 39 33 public abstract class Problem : ParameterizedNamedItem, IProblem { 40 34 public override Image ItemImage { 41 35 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } … … 44 38 [StorableConstructor] 45 39 protected Problem(bool deserializing) : base(deserializing) { } 46 protected Problem(Problem <T, U>original, Cloner cloner)40 protected Problem(Problem original, Cloner cloner) 47 41 : base(original, cloner) { 48 42 operators = cloner.Clone(original.operators); … … 53 47 : base() { 54 48 operators = new OperatorCollection(); 55 Parameters.Add(new ValueParameter<T>(EvaluatorParameterName, "The operator used to evaluate a solution."));56 Parameters.Add(new ValueParameter<U>(SolutionCreateParameterName, "The operator to create a solution."));57 49 RegisterEventHandlers(); 58 50 } … … 67 59 Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed); 68 60 Operators.CollectionReset += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed); 69 70 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);71 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);72 61 } 73 62 … … 83 72 } 84 73 IEnumerable<IOperator> IProblem.Operators { get { return operators; } } 85 86 public T Evaluator {87 get { return EvaluatorParameter.Value; }88 protected set { EvaluatorParameter.Value = value; }89 }90 public ValueParameter<T> EvaluatorParameter {91 get { return (ValueParameter<T>)Parameters[EvaluatorParameterName]; }92 }93 IEvaluator IProblem.Evaluator { get { return Evaluator; } }94 IParameter IProblem.EvaluatorParameter { get { return EvaluatorParameter; } }95 96 public U SolutionCreator {97 get { return SolutionCreatorParameter.Value; }98 protected set { SolutionCreatorParameter.Value = value; }99 }100 public ValueParameter<U> SolutionCreatorParameter {101 get { return (ValueParameter<U>)Parameters[SolutionCreateParameterName]; }102 }103 ISolutionCreator IProblem.SolutionCreator { get { return SolutionCreator; } }104 IParameter IProblem.SolutionCreatorParameter { get { return SolutionCreatorParameter; } }105 74 #endregion 106 75 107 76 #region events 108 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {109 OnEvaluatorChanged();110 }111 public event EventHandler EvaluatorChanged;112 protected virtual void OnEvaluatorChanged() {113 EventHandler handler = EvaluatorChanged;114 if (handler != null)115 handler(this, EventArgs.Empty);116 }117 118 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {119 OnSolutionCreatorChanged();120 }121 public event EventHandler SolutionCreatorChanged;122 protected virtual void OnSolutionCreatorChanged() {123 EventHandler handler = SolutionCreatorChanged;124 if (handler != null)125 handler(this, EventArgs.Empty);126 }127 128 77 private void Operators_Changed(object sender, EventArgs e) { 129 78 OnOperatorsChanged(); -
branches/QAP/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs
r5809 r5811 41 41 : base() { 42 42 Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue())); 43 Parameters.Add(new ValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue()));43 Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue())); 44 44 } 45 45 … … 47 47 : base(evaluator, solutionCreator) { 48 48 Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue())); 49 Parameters.Add(new ValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue()));49 Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue())); 50 50 } 51 51 52 public ValueParameter<BoolValue> MaximizationParameter { 53 get { return (ValueParameter<BoolValue>)Parameters[MaximizationParameterName]; } 52 [StorableHook(HookType.AfterDeserialization)] 53 protected virtual void AfterDeserialization() { 54 // BackwardsCompatibility3.3 55 #region Backwards compatible code (remove with 3.4) 56 if (BestKnownQualityParameter is ValueParameter<DoubleValue>) { 57 Parameters.Remove(BestKnownQualityParameterName); 58 Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.")); 59 } 60 #endregion 61 } 62 public IValueParameter<BoolValue> MaximizationParameter { 63 get { return (IValueParameter<BoolValue>)Parameters[MaximizationParameterName]; } 54 64 } 55 65 IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter { … … 61 71 } 62 72 63 public ValueParameter<DoubleValue> BestKnownQualityParameter {64 get { return ( ValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }73 public IValueParameter<DoubleValue> BestKnownQualityParameter { 74 get { return (IValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; } 65 75 } 66 76 IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter { -
branches/QAP/HeuristicLab.Optimization/3.3/UserDefinedProblem.cs
r5785 r5811 40 40 [Creatable("Problems")] 41 41 [StorableClass] 42 public sealed class UserDefinedProblem : ParameterizedNamedItem, ISingleObjective Problem, IStorableContent {42 public sealed class UserDefinedProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent { 43 43 public string Filename { get; set; } 44 44 … … 60 60 get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; } 61 61 } 62 IParameter ISingleObjective Problem.MaximizationParameter {62 IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter { 63 63 get { return MaximizationParameter; } 64 64 } … … 66 66 get { return (ValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; } 67 67 } 68 IParameter I Problem.SolutionCreatorParameter {68 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter { 69 69 get { return SolutionCreatorParameter; } 70 70 } 71 IParameter I Problem.EvaluatorParameter {71 IParameter IHeuristicOptimizationProblem.EvaluatorParameter { 72 72 get { return EvaluatorParameter; } 73 73 } … … 75 75 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 76 76 } 77 IParameter ISingleObjective Problem.BestKnownQualityParameter {77 IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter { 78 78 get { return BestKnownQualityParameter; } 79 79 } … … 95 95 set { SolutionCreatorParameter.Value = value; } 96 96 } 97 ISolutionCreator I Problem.SolutionCreator {97 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { 98 98 get { return SolutionCreatorParameter.Value; } 99 99 } … … 102 102 set { EvaluatorParameter.Value = value; } 103 103 } 104 ISingleObjectiveEvaluator ISingleObjective Problem.Evaluator {104 ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator { 105 105 get { return EvaluatorParameter.Value; } 106 106 } 107 IEvaluator I Problem.Evaluator {107 IEvaluator IHeuristicOptimizationProblem.Evaluator { 108 108 get { return EvaluatorParameter.Value; } 109 109 }
Note: See TracChangeset
for help on using the changeset viewer.