- Timestamp:
- 03/17/10 13:24:11 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs
r3076 r3080 249 249 } 250 250 private void ParameterizeSGAMainLoop() { 251 SGAMainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 251 252 SGAMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 252 253 SGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; -
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAMainLoop.cs
r3048 r3080 36 36 [Creatable("Test")] 37 37 [StorableClass] 38 public class SGAMainLoop : AlgorithmOperator {38 public sealed class SGAMainLoop : AlgorithmOperator { 39 39 #region Parameter properties 40 40 public ValueLookupParameter<IRandom> RandomParameter { … … 47 47 get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } 48 48 } 49 public ValueLookupParameter<DoubleValue> BestKnownQualityParameter { 50 get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 51 } 49 52 public ValueLookupParameter<IOperator> SelectorParameter { 50 53 get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; } … … 80 83 #endregion 81 84 85 [StorableConstructor] 86 private SGAMainLoop(bool deserializing) : base() { } 82 87 public SGAMainLoop() 83 88 : base() { 89 Initialize(); 90 } 91 92 private void Initialize() { 84 93 #region Create parameters 85 94 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 86 95 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 87 96 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 97 Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); 88 98 Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction.")); 89 99 Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions.")); … … 97 107 #endregion 98 108 99 #region Create operator graph109 #region Create operators 100 110 VariableCreator variableCreator = new VariableCreator(); 111 BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer(); 112 BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator1 = new BestAverageWorstQualityCalculator(); 113 DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector(); 101 114 ResultsCollector resultsCollector = new ResultsCollector(); 102 115 SubScopesSorter subScopesSorter1 = new SubScopesSorter(); … … 117 130 IntCounter intCounter = new IntCounter(); 118 131 Comparator comparator = new Comparator(); 119 BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator(); 120 DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector(); 132 BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer(); 133 BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator2 = new BestAverageWorstQualityCalculator(); 134 DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector(); 121 135 ConditionalBranch conditionalBranch = new ConditionalBranch(); 122 136 123 OperatorGraph.InitialOperator = variableCreator;124 125 137 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 126 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Best Quality", new DoubleValue(0))); 127 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Average Quality", new DoubleValue(0))); 128 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Worst Quality", new DoubleValue(0))); 129 variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities"))); 130 variableCreator.Successor = resultsCollector; 138 139 bestQualityMemorizer1.BestQualityParameter.ActualName = "Best Quality"; 140 bestQualityMemorizer1.MaximizationParameter.ActualName = "Maximization"; 141 bestQualityMemorizer1.QualityParameter.ActualName = "Quality"; 142 143 bestAverageWorstQualityCalculator1.AverageQualityParameter.ActualName = "Current Average Quality"; 144 bestAverageWorstQualityCalculator1.BestQualityParameter.ActualName = "Current Best Quality"; 145 bestAverageWorstQualityCalculator1.MaximizationParameter.ActualName = "Maximization"; 146 bestAverageWorstQualityCalculator1.QualityParameter.ActualName = "Quality"; 147 bestAverageWorstQualityCalculator1.WorstQualityParameter.ActualName = "Current Worst Quality"; 148 149 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality")); 150 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality")); 151 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality")); 152 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality")); 153 dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality")); 154 dataTableValuesCollector1.DataTableParameter.ActualName = "Qualities"; 131 155 132 156 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 157 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality")); 158 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality")); 159 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality")); 133 160 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality")); 134 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Quality")); 135 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Worst Quality")); 161 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality")); 136 162 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities")); 137 163 resultsCollector.ResultsParameter.ActualName = "Results"; 138 resultsCollector.Successor = subScopesSorter1;139 164 140 165 subScopesSorter1.DescendingParameter.ActualName = "Maximization"; 141 166 subScopesSorter1.ValueParameter.ActualName = "Quality"; 142 subScopesSorter1.Successor = selector;143 167 144 168 selector.Name = "Selector"; 145 169 selector.OperatorParameter.ActualName = "Selector"; 146 selector.Successor = sequentialSubScopesProcessor1;147 148 sequentialSubScopesProcessor1.Operators.Add(new EmptyOperator());149 sequentialSubScopesProcessor1.Operators.Add(childrenCreator);150 sequentialSubScopesProcessor1.Successor = sequentialSubScopesProcessor2;151 170 152 171 childrenCreator.ParentsPerChild = new IntValue(2); 153 childrenCreator.Successor = uniformSequentialSubScopesProcessor;154 155 uniformSequentialSubScopesProcessor.Operator = crossover;156 uniformSequentialSubScopesProcessor.Successor = subScopesSorter2;157 172 158 173 crossover.Name = "Crossover"; 159 174 crossover.OperatorParameter.ActualName = "Crossover"; 160 crossover.Successor = stochasticBranch; 161 162 stochasticBranch.FirstBranch = mutator; 175 163 176 stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability"; 164 177 stochasticBranch.RandomParameter.ActualName = "Random"; 165 stochasticBranch.SecondBranch = null;166 stochasticBranch.Successor = evaluator;167 178 168 179 mutator.Name = "Mutator"; 169 180 mutator.OperatorParameter.ActualName = "Mutator"; 170 mutator.Successor = null;171 181 172 182 evaluator.Name = "Evaluator"; 173 183 evaluator.OperatorParameter.ActualName = "Evaluator"; 174 evaluator.Successor = subScopesRemover;175 184 176 185 subScopesRemover.RemoveAllSubScopes = true; 177 subScopesRemover.Successor = null;178 186 179 187 subScopesSorter2.DescendingParameter.ActualName = "Maximization"; 180 188 subScopesSorter2.ValueParameter.ActualName = "Quality"; 181 subScopesSorter2.Successor = null;182 183 sequentialSubScopesProcessor2.Operators.Add(leftSelector);184 sequentialSubScopesProcessor2.Operators.Add(new EmptyOperator());185 sequentialSubScopesProcessor2.Successor = mergingReducer;186 189 187 190 leftSelector.CopySelected = new BoolValue(false); 188 191 leftSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites"; 189 leftSelector.Successor = rightReducer;190 191 rightReducer.Successor = null;192 193 mergingReducer.Successor = intCounter;194 192 195 193 intCounter.Increment = new IntValue(1); 196 194 intCounter.ValueParameter.ActualName = "Generations"; 197 intCounter.Successor = comparator;198 195 199 196 comparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); … … 201 198 comparator.ResultParameter.ActualName = "Terminate"; 202 199 comparator.RightSideParameter.ActualName = "MaximumGenerations"; 203 comparator.Successor = bestAverageWorstQualityCalculator; 204 205 bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = "Average Quality"; 206 bestAverageWorstQualityCalculator.BestQualityParameter.ActualName = "Best Quality"; 207 bestAverageWorstQualityCalculator.MaximizationParameter.ActualName = "Maximization"; 208 bestAverageWorstQualityCalculator.QualityParameter.ActualName = "Quality"; 209 bestAverageWorstQualityCalculator.WorstQualityParameter.ActualName = "Worst Quality"; 210 bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector; 211 212 dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality")); 213 dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Quality")); 214 dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Worst Quality")); 215 dataTableValuesCollector.DataTableParameter.ActualName = "Qualities"; 216 dataTableValuesCollector.Successor = conditionalBranch; 200 201 bestQualityMemorizer2.BestQualityParameter.ActualName = "Best Quality"; 202 bestQualityMemorizer2.MaximizationParameter.ActualName = "Maximization"; 203 bestQualityMemorizer2.QualityParameter.ActualName = "Quality"; 204 205 bestAverageWorstQualityCalculator2.AverageQualityParameter.ActualName = "Current Average Quality"; 206 bestAverageWorstQualityCalculator2.BestQualityParameter.ActualName = "Current Best Quality"; 207 bestAverageWorstQualityCalculator2.MaximizationParameter.ActualName = "Maximization"; 208 bestAverageWorstQualityCalculator2.QualityParameter.ActualName = "Quality"; 209 bestAverageWorstQualityCalculator2.WorstQualityParameter.ActualName = "Current Worst Quality"; 210 211 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality")); 212 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality")); 213 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality")); 214 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality")); 215 dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality")); 216 dataTableValuesCollector2.DataTableParameter.ActualName = "Qualities"; 217 217 218 218 conditionalBranch.ConditionParameter.ActualName = "Terminate"; 219 #endregion 220 221 #region Create operator graph 222 OperatorGraph.InitialOperator = variableCreator; 223 variableCreator.Successor = bestQualityMemorizer1; 224 bestQualityMemorizer1.Successor = bestAverageWorstQualityCalculator1; 225 bestAverageWorstQualityCalculator1.Successor = dataTableValuesCollector1; 226 dataTableValuesCollector1.Successor = resultsCollector; 227 resultsCollector.Successor = subScopesSorter1; 228 subScopesSorter1.Successor = selector; 229 selector.Successor = sequentialSubScopesProcessor1; 230 sequentialSubScopesProcessor1.Operators.Add(new EmptyOperator()); 231 sequentialSubScopesProcessor1.Operators.Add(childrenCreator); 232 sequentialSubScopesProcessor1.Successor = sequentialSubScopesProcessor2; 233 childrenCreator.Successor = uniformSequentialSubScopesProcessor; 234 uniformSequentialSubScopesProcessor.Operator = crossover; 235 uniformSequentialSubScopesProcessor.Successor = subScopesSorter2; 236 crossover.Successor = stochasticBranch; 237 stochasticBranch.FirstBranch = mutator; 238 stochasticBranch.SecondBranch = null; 239 stochasticBranch.Successor = evaluator; 240 mutator.Successor = null; 241 evaluator.Successor = subScopesRemover; 242 subScopesRemover.Successor = null; 243 subScopesSorter2.Successor = null; 244 sequentialSubScopesProcessor2.Operators.Add(leftSelector); 245 sequentialSubScopesProcessor2.Operators.Add(new EmptyOperator()); 246 sequentialSubScopesProcessor2.Successor = mergingReducer; 247 leftSelector.Successor = rightReducer; 248 rightReducer.Successor = null; 249 mergingReducer.Successor = intCounter; 250 intCounter.Successor = comparator; 251 comparator.Successor = bestQualityMemorizer2; 252 bestQualityMemorizer2.Successor = bestAverageWorstQualityCalculator2; 253 bestAverageWorstQualityCalculator2.Successor = dataTableValuesCollector2; 254 dataTableValuesCollector2.Successor = conditionalBranch; 219 255 conditionalBranch.FalseBranch = subScopesSorter1; 220 256 conditionalBranch.TrueBranch = null; -
trunk/sources/HeuristicLab.Analysis.Views/3.3/DataTableView.cs
r2917 r3080 111 111 series.ChartType = SeriesChartType.FastLine; 112 112 series.ToolTip = "#VAL"; 113 for (int i = 0; i < row.Values.Count; i++) 114 series.Points.Add(row.Values[i]); 113 for (int i = 0; i < row.Values.Count; i++) { 114 if (double.IsNaN(row.Values[i])) { 115 DataPoint point = new DataPoint(); 116 point.IsEmpty = true; 117 series.Points.Add(point); 118 } else { 119 series.Points.Add(row.Values[i]); 120 } 121 } 115 122 chart.Series.Add(series); 116 123 } … … 208 215 else { 209 216 DataRow row = valuesRowsTable[(IObservableList<double>)sender]; 210 foreach (IndexedItem<double> item in e.Items) 211 chart.Series[row.Name].Points.InsertY(item.Index, item.Value); 217 foreach (IndexedItem<double> item in e.Items) { 218 if (double.IsNaN(item.Value)) { 219 DataPoint point = new DataPoint(); 220 point.IsEmpty = true; 221 chart.Series[row.Name].Points.Insert(item.Index, point); 222 } else { 223 chart.Series[row.Name].Points.InsertY(item.Index, item.Value); 224 } 225 } 212 226 } 213 227 } … … 229 243 else { 230 244 DataRow row = valuesRowsTable[(IObservableList<double>)sender]; 231 foreach (IndexedItem<double> item in e.Items) 232 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 245 foreach (IndexedItem<double> item in e.Items) { 246 if (double.IsNaN(item.Value)) 247 chart.Series[row.Name].Points[item.Index].IsEmpty = true; 248 else 249 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 250 } 233 251 } 234 252 } … … 238 256 else { 239 257 DataRow row = valuesRowsTable[(IObservableList<double>)sender]; 240 foreach (IndexedItem<double> item in e.Items) 241 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 258 foreach (IndexedItem<double> item in e.Items) { 259 if (double.IsNaN(item.Value)) 260 chart.Series[row.Name].Points[item.Index].IsEmpty = true; 261 else 262 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 263 } 242 264 } 243 265 } … … 248 270 DataRow row = valuesRowsTable[(IObservableList<double>)sender]; 249 271 chart.Series[row.Name].Points.Clear(); 250 foreach (IndexedItem<double> item in e.Items) 251 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 272 foreach (IndexedItem<double> item in e.Items) { 273 if (double.IsNaN(item.Value)) 274 chart.Series[row.Name].Points[item.Index].IsEmpty = true; 275 else 276 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 277 } 252 278 } 253 279 } -
trunk/sources/HeuristicLab.Analysis/3.3/BestQualityMemorizer.cs
r3048 r3080 55 55 DoubleValue best = BestQualityParameter.ActualValue; 56 56 double max = (best != null) ? (best.Value) : ((maximization) ? (double.MinValue) : (double.MaxValue)); 57 57 58 58 foreach (DoubleValue quality in qualities) 59 59 if (IsBetter(maximization, quality.Value, max)) max = quality.Value; -
trunk/sources/HeuristicLab.Analysis/3.3/DataTableValuesCollector.cs
r3048 r3080 53 53 foreach (IParameter param in CollectedValues) { 54 54 DoubleValue data = param.ActualValue as DoubleValue; 55 if (data == null) throw new InvalidOperationException("Only double data values can be collected by a DataTableValuesCollector.");55 if (data == null) data = new DoubleValue(double.NaN); 56 56 57 57 DataRow row; -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISingleObjectiveProblem.cs
r2975 r3080 28 28 public interface ISingleObjectiveProblem : IProblem { 29 29 IParameter MaximizationParameter { get; } 30 IParameter BestKnownQualityParameter { get; } 30 31 new ISingleObjectiveEvaluator Evaluator { get; } 31 32 } -
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r3077 r3080 57 57 public LookupParameter() 58 58 : base("Anonymous", typeof(T)) { 59 actualName = Name;59 this.actualName = Name; 60 60 } 61 61 public LookupParameter(string name) 62 62 : base(name, typeof(T)) { 63 actualName = Name;63 this.actualName = Name; 64 64 } 65 65 public LookupParameter(string name, string description) 66 66 : base(name, description, typeof(T)) { 67 actualName = Name; 67 this.actualName = Name; 68 } 69 public LookupParameter(string name, string description, string actualName) 70 : base(name, description, typeof(T)) { 71 this.actualName = actualName == null ? string.Empty : actualName; 68 72 } 69 73 -
trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs
r3017 r3080 75 75 Value = value; 76 76 } 77 public ValueLookupParameter(string name, string description, string actualName) 78 : base(name, description, actualName) { 79 } 77 80 78 81 public override IDeepCloneable Clone(Cloner cloner) { -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Knapsack.cs
r3071 r3080 76 76 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 77 77 } 78 IParameter ISingleObjectiveProblem.BestKnownQualityParameter { 79 get { return BestKnownQualityParameter; } 80 } 78 81 #endregion 79 82 -
trunk/sources/HeuristicLab.Problems.OneMax/3.3/Onemax.cs
r3067 r3080 64 64 get { return EvaluatorParameter; } 65 65 } 66 public ValueParameter<DoubleValue> BestKnownQualityParameter { 67 get { return (ValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 68 } 69 IParameter ISingleObjectiveProblem.BestKnownQualityParameter { 70 get { return BestKnownQualityParameter; } 71 } 66 72 #endregion 67 73 … … 84 90 get { return EvaluatorParameter.Value; } 85 91 } 92 public DoubleValue BestKnownQuality { 93 get { return BestKnownQualityParameter.Value; } 94 } 86 95 private List<IBinaryVectorOperator> operators; 87 96 public IEnumerable<IOperator> Operators { … … 99 108 Parameters.Add(new ValueParameter<IBinaryVectorCreator>("SolutionCreator", "The operator which should be used to create new OneMax solutions.", creator)); 100 109 Parameters.Add(new ValueParameter<IOneMaxEvaluator>("Evaluator", "The operator which should be used to evaluate OneMax solutions.", evaluator)); 110 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue(5))); 101 111 102 112 creator.BinaryVectorParameter.ActualName = "OneMaxSolution"; -
trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs
r3074 r3080 73 73 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 74 74 } 75 IParameter ISingleObjectiveProblem.BestKnownQualityParameter { 76 get { return BestKnownQualityParameter; } 77 } 75 78 #endregion 76 79
Note: See TracChangeset
for help on using the changeset viewer.