- Timestamp:
- 09/27/14 00:17:29 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r11393 r11395 147 147 148 148 if (solutionCreators.Count == 1) { 149 UpdateSingleVectorEncodingOperators(solutionCreators );149 UpdateSingleVectorEncodingOperators(solutionCreators, configuration); 150 150 } else { 151 151 UpdateMultiVectorEncodingOperators(solutionCreators, configuration); … … 229 229 } 230 230 231 protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators ) {231 protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) { 232 232 var newCreator = solutionCreators.Single(); 233 233 var binCreator = newCreator as IBinaryVectorCreator; … … 265 265 Operators.RemoveAll(x => x is ICrossover && !(x is IIntegerVectorCrossover) || x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName); 266 266 Operators.RemoveAll(x => x is IManipulator && !(x is IIntegerVectorManipulator) || x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName); 267 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IIntegerVectorStdDevStrategyParameterCreator) || x is IIntegerVectorStdDevStrategyParameterCreator && ((IIntegerVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 268 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IIntegerVectorStdDevStrategyParameterManipulator) || x is IIntegerVectorStdDevStrategyParameterManipulator && ((IIntegerVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 269 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IIntegerVectorStdDevStrategyParameterCrossover) || x is IIntegerVectorStdDevStrategyParameterCrossover && ((IIntegerVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 267 270 var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList(); 268 271 var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList(); 272 var strategyOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>().ToList(); 269 273 foreach (var xo in crossovers) { 270 274 xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; 271 275 xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; 272 276 } 273 foreach (var m in manipulators) 277 foreach (var m in manipulators) { 274 278 m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; 279 var sm = m as ISelfAdaptiveManipulator; 280 if (sm != null) { 281 var p = sm.StrategyParameterParameter as ILookupParameter; 282 if (p != null) p.ActualName = paramName + "Strategy"; 283 } 284 } 275 285 foreach (var bo in crossovers.OfType<IBoundedIntegerVectorOperator>() 276 286 .Concat(manipulators.OfType<IBoundedIntegerVectorOperator>()) … … 278 288 bo.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName; 279 289 } 290 if (!(configuration.Parameters.First().Value is IntegerParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with integervector creator that is not an integer-coded problem."); 291 var problemSize = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Length.Value; 292 var b = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Bounds; 293 var bounds = new DoubleMatrix(b.Rows, b.Columns); 294 for (var i = 0; i < bounds.Rows; i++) { 295 bounds[i, 1] = (int)Math.Ceiling(0.33 * (b[i, 1] - b[i, 0])); 296 bounds[i, 0] = 0; 297 if (bounds.Columns > 2) bounds[i, 2] = b[i, 2]; 298 } 299 foreach (var s in strategyOperators) { 300 var c = s as IIntegerVectorStdDevStrategyParameterCreator; 301 if (c != null) { 302 c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone(); 303 c.LengthParameter.ActualName = intCreator.LengthParameter.ActualName; 304 c.StrategyParameterParameter.ActualName = paramName + "Strategy"; 305 } 306 var m = s as IIntegerVectorStdDevStrategyParameterManipulator; 307 if (m != null) { 308 m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone(); 309 m.StrategyParameterParameter.ActualName = paramName + "Strategy"; 310 } 311 var mm = s as Encodings.IntegerVectorEncoding.StdDevStrategyVectorManipulator; 312 if (mm != null) { 313 mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * problemSize)); 314 mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(problemSize))); 315 } 316 var x = s as IIntegerVectorStdDevStrategyParameterCrossover; 317 if (x != null) { 318 x.ParentsParameter.ActualName = paramName + "Strategy"; 319 x.StrategyParameterParameter.ActualName = paramName + "Strategy"; 320 } 321 } 280 322 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 281 323 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 324 Operators.AddRange(strategyOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 282 325 } 283 326 var realCreator = newCreator as IRealVectorCreator; … … 293 336 Operators.RemoveAll(x => x is ICrossover && !(x is IRealVectorCrossover) || x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName); 294 337 Operators.RemoveAll(x => x is IManipulator && !(x is IRealVectorManipulator) || x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName); 338 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IRealVectorStdDevStrategyParameterCreator) || x is IRealVectorStdDevStrategyParameterCreator && ((IRealVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 339 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IRealVectorStdDevStrategyParameterManipulator) || x is IRealVectorStdDevStrategyParameterManipulator && ((IRealVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 340 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IRealVectorStdDevStrategyParameterCrossover) || x is IRealVectorStdDevStrategyParameterCrossover && ((IRealVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 295 341 var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList(); 296 342 var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList(); 343 var strategyOperators = ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>().ToList(); 297 344 foreach (var xo in crossovers) { 298 xo.ChildParameter.ActualName = realCreator.RealVectorParameter.ActualName;299 xo.ParentsParameter.ActualName = realCreator.RealVectorParameter.ActualName;345 xo.ChildParameter.ActualName = paramName; 346 xo.ParentsParameter.ActualName = paramName; 300 347 xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName; 301 348 } 302 349 foreach (var m in manipulators) { 303 m.RealVectorParameter.ActualName = realCreator.RealVectorParameter.ActualName;350 m.RealVectorParameter.ActualName = paramName; 304 351 m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName; 352 var sm = m as ISelfAdaptiveManipulator; 353 if (sm != null) { 354 var p = sm.StrategyParameterParameter as ILookupParameter; 355 if (p != null) p.ActualName = paramName + "Strategy"; 356 } 357 } 358 if (!(configuration.Parameters.First().Value is RealParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with realvector creator that is not a real-coded problem."); 359 var problemSize = ((RealParameterConfiguration)configuration.Parameters.First().Value).Length.Value; 360 var bounds = (DoubleMatrix)((RealParameterConfiguration)configuration.Parameters.First().Value).Bounds.Clone(); 361 for (var i = 0; i < bounds.Rows; i++) { 362 bounds[i, 1] = 0.1 * (bounds[i, 1] - bounds[i, 0]); 363 bounds[i, 0] = 0; 364 } 365 foreach (var s in strategyOperators) { 366 var c = s as IRealVectorStdDevStrategyParameterCreator; 367 if (c != null) { 368 c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone(); 369 c.LengthParameter.ActualName = realCreator.LengthParameter.ActualName; 370 c.StrategyParameterParameter.ActualName = paramName + "Strategy"; 371 } 372 var m = s as IRealVectorStdDevStrategyParameterManipulator; 373 if (m != null) { 374 m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone(); 375 m.StrategyParameterParameter.ActualName = paramName + "Strategy"; 376 } 377 var mm = s as Encodings.RealVectorEncoding.StdDevStrategyVectorManipulator; 378 if (mm != null) { 379 mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * problemSize)); 380 mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(problemSize))); 381 } 382 var x = s as IRealVectorStdDevStrategyParameterCrossover; 383 if (x != null) { 384 x.ParentsParameter.ActualName = paramName + "Strategy"; 385 x.StrategyParameterParameter.ActualName = paramName + "Strategy"; 386 } 305 387 } 306 388 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 307 389 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 390 Operators.AddRange(strategyOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 308 391 } 309 392 var permCreator = newCreator as IPermutationCreator;
Note: See TracChangeset
for help on using the changeset viewer.