- Timestamp:
- 09/28/14 12:39:33 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r11396 r11398 165 165 166 166 if (solutionCreators.Count == 1) { 167 Operators.RemoveAll(x => x is ParameterVectorCrossover 168 || x is ParameterVectorManipulator); 167 169 UpdateSingleVectorEncodingOperators(solutionCreators, configuration); 168 170 } else { … … 179 181 var solutionCreators = new List<ISolutionCreator>(); 180 182 foreach (var param in configuration.Parameters) { 181 /* 182 * Binary Vectors 183 */ 183 #region Configure BinaryVector Creator 184 184 var binConfig = param.Value as BinaryParameterConfiguration; 185 185 if (binConfig != null) { … … 192 192 solutionCreators.Add(creator); 193 193 } 194 /* 195 * Integer Vectors 196 */ 194 #endregion 195 #region Configure IntegerVector Creator 197 196 var intConfig = param.Value as IntegerParameterConfiguration; 198 197 if (intConfig != null) { … … 208 207 solutionCreators.Add(creator); 209 208 } 210 /* 211 * Real Vectors 212 */ 209 #endregion 210 #region Configure RealVector Creator 213 211 var realConfig = param.Value as RealParameterConfiguration; 214 212 if (realConfig != null) { … … 224 222 solutionCreators.Add(creator); 225 223 } 226 /* 227 * Permutations 228 */ 224 #endregion 225 #region Configure Permutation Creator 229 226 var permConfig = param.Value as PermutationParameterConfiguration; 230 227 if (permConfig != null) { … … 238 235 solutionCreators.Add(creator); 239 236 } 237 #endregion 240 238 } 241 239 … … 249 247 protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) { 250 248 var newCreator = solutionCreators.Single(); 249 #region Configure Operators for BinaryVectorEncoding 251 250 var binCreator = newCreator as IBinaryVectorCreator; 252 251 if (binCreator != null) { … … 258 257 Operators.Add(SolutionCreator); 259 258 } 260 Operators.RemoveAll(x => x is ICrossover && !(x is IBinaryVectorCrossover) || x is IBinaryVectorCrossover && ((IBinaryVectorCrossover)x).ChildParameter.ActualName != paramName); 261 Operators.RemoveAll(x => x is IManipulator && !(x is IBinaryVectorManipulator) || x is IBinaryVectorManipulator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName); 259 260 #region Wire BinaryVector Crossovers 261 Operators.RemoveAll(x => x is IBinaryVectorCrossover && ((IBinaryVectorCrossover)x).ChildParameter.ActualName != paramName); 262 262 var crossovers = ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>().ToList(); 263 var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList();264 263 foreach (var xo in crossovers) { 265 264 xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; 265 xo.ChildParameter.Hidden = true; 266 266 xo.ParentsParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; 267 } 268 foreach (var m in manipulators) 267 xo.ParentsParameter.Hidden = true; 268 } 269 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 270 #endregion 271 #region Wire BinaryVector Manipulators 272 Operators.RemoveAll(x => x is IBinaryVectorManipulator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName); 273 var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList(); 274 foreach (var m in manipulators) { 269 275 m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; 270 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 276 m.BinaryVectorParameter.Hidden = true; 277 } 271 278 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 272 } 279 #endregion 280 #region Wire BinaryVector ShakingOperators 281 Operators.RemoveAll(x => x is IBinaryVectorMultiNeighborhoodShakingOperator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName); 282 var shakingOperators = ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>().ToList(); 283 foreach (var so in shakingOperators) { 284 so.BinaryVectorParameter.ActualName = paramName; 285 so.BinaryVectorParameter.Hidden = true; 286 } 287 Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 288 #endregion 289 } else { 290 Operators.RemoveAll(x => x is IBinaryVectorCrossover 291 || x is IBinaryVectorManipulator 292 || x is IBinaryVectorMultiNeighborhoodShakingOperator); 293 } 294 #endregion 295 #region Configure Operators for IntegerVectorEncoding 273 296 var intCreator = newCreator as IIntegerVectorCreator; 274 297 if (intCreator != null) { … … 281 304 Operators.Add(SolutionCreator); 282 305 } 283 Operators.RemoveAll(x => x is ICrossover && !(x is IIntegerVectorCrossover) || x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName); 284 Operators.RemoveAll(x => x is IManipulator && !(x is IIntegerVectorManipulator) || x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName); 306 307 #region Wire IntegerVector Crossovers 308 Operators.RemoveAll(x => x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName); 309 var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList(); 310 foreach (var xo in crossovers) { 311 xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; 312 xo.ChildParameter.Hidden = true; 313 xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; 314 xo.ParentsParameter.Hidden = true; 315 var bx = xo as IBoundedIntegerVectorOperator; 316 if (bx != null) { 317 bx.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName; 318 bx.BoundsParameter.Hidden = true; 319 } 320 } 321 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 322 #endregion 323 #region Wire IntegerVector Manipulators 324 Operators.RemoveAll(x => x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName); 325 var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList(); 326 foreach (var m in manipulators) { 327 m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; 328 m.IntegerVectorParameter.Hidden = true; 329 var sm = m as ISelfAdaptiveManipulator; 330 if (sm != null) { 331 var p = sm.StrategyParameterParameter as ILookupParameter; 332 if (p != null) { 333 p.ActualName = paramName + "Strategy"; 334 p.Hidden = true; 335 } 336 } 337 var bm = m as IBoundedIntegerVectorOperator; 338 if (bm != null) { 339 bm.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName; 340 bm.BoundsParameter.Hidden = true; 341 } 342 } 343 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 344 #region Wire IntegerVector StrategyParameters for SelfAdaptiveManipulators 285 345 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IIntegerVectorStdDevStrategyParameterCreator) || x is IIntegerVectorStdDevStrategyParameterCreator && ((IIntegerVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 286 346 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IIntegerVectorStdDevStrategyParameterManipulator) || x is IIntegerVectorStdDevStrategyParameterManipulator && ((IIntegerVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 287 347 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IIntegerVectorStdDevStrategyParameterCrossover) || x is IIntegerVectorStdDevStrategyParameterCrossover && ((IIntegerVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 288 var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList();289 var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList();290 348 var strategyOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>().ToList(); 291 foreach (var xo in crossovers) {292 xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;293 xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;294 }295 foreach (var m in manipulators) {296 m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;297 var sm = m as ISelfAdaptiveManipulator;298 if (sm != null) {299 var p = sm.StrategyParameterParameter as ILookupParameter;300 if (p != null) p.ActualName = paramName + "Strategy";301 }302 }303 foreach (var bo in crossovers.OfType<IBoundedIntegerVectorOperator>()304 .Concat(manipulators.OfType<IBoundedIntegerVectorOperator>())305 .ToList()) {306 bo.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;307 }308 349 if (!(configuration.Parameters.First().Value is IntegerParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with integervector creator that is not an integer-coded problem."); 309 350 var problemSize = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Length.Value; … … 338 379 } 339 380 } 340 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));341 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));342 381 Operators.AddRange(strategyOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 343 } 382 #endregion 383 #endregion 384 #region Wire IntegerVector ShakingOperators 385 Operators.RemoveAll(x => x is IIntegerVectorMultiNeighborhoodShakingOperator && ((IIntegerVectorMultiNeighborhoodShakingOperator)x).IntegerVectorParameter.ActualName != paramName); 386 var shakingOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>().ToList(); 387 foreach (var so in shakingOperators) { 388 so.IntegerVectorParameter.ActualName = paramName; 389 so.IntegerVectorParameter.Hidden = true; 390 } 391 Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 392 #endregion 393 } else { 394 Operators.RemoveAll(x => x is IIntegerVectorCrossover 395 || x is IIntegerVectorManipulator 396 || x is IIntegerVectorStdDevStrategyParameterOperator 397 || x is IIntegerVectorMultiNeighborhoodShakingOperator); 398 } 399 #endregion 400 #region Configure Operators for RealVectorEncoding 344 401 var realCreator = newCreator as IRealVectorCreator; 345 402 if (realCreator != null) { … … 352 409 Operators.Add(SolutionCreator); 353 410 } 354 Operators.RemoveAll(x => x is ICrossover && !(x is IRealVectorCrossover) || x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName); 355 Operators.RemoveAll(x => x is IManipulator && !(x is IRealVectorManipulator) || x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName); 411 412 #region Wire RealVector Crossovers 413 Operators.RemoveAll(x => x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName); 414 var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList(); 415 foreach (var xo in crossovers) { 416 xo.ChildParameter.ActualName = paramName; 417 xo.ChildParameter.Hidden = true; 418 xo.ParentsParameter.ActualName = paramName; 419 xo.ParentsParameter.Hidden = true; 420 xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName; 421 xo.BoundsParameter.Hidden = true; 422 } 423 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 424 #endregion 425 #region Wire RealVector Manipulators 426 Operators.RemoveAll(x => x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName); 427 var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList(); 428 foreach (var m in manipulators) { 429 m.RealVectorParameter.ActualName = paramName; 430 m.RealVectorParameter.Hidden = true; 431 m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName; 432 m.BoundsParameter.Hidden = true; 433 var sm = m as ISelfAdaptiveManipulator; 434 if (sm != null) { 435 var p = sm.StrategyParameterParameter as ILookupParameter; 436 if (p != null) { 437 p.ActualName = paramName + "Strategy"; 438 p.Hidden = true; 439 } 440 } 441 } 442 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 443 #region Wire RealVector Strategy Parameters for SelfAdaptiveManipulators 444 356 445 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IRealVectorStdDevStrategyParameterCreator) || x is IRealVectorStdDevStrategyParameterCreator && ((IRealVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 357 446 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IRealVectorStdDevStrategyParameterManipulator) || x is IRealVectorStdDevStrategyParameterManipulator && ((IRealVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 358 447 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IRealVectorStdDevStrategyParameterCrossover) || x is IRealVectorStdDevStrategyParameterCrossover && ((IRealVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 359 var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList();360 var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList();361 448 var strategyOperators = ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>().ToList(); 362 foreach (var xo in crossovers) {363 xo.ChildParameter.ActualName = paramName;364 xo.ParentsParameter.ActualName = paramName;365 xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;366 }367 foreach (var m in manipulators) {368 m.RealVectorParameter.ActualName = paramName;369 m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;370 var sm = m as ISelfAdaptiveManipulator;371 if (sm != null) {372 var p = sm.StrategyParameterParameter as ILookupParameter;373 if (p != null) p.ActualName = paramName + "Strategy";374 }375 }376 449 if (!(configuration.Parameters.First().Value is RealParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with realvector creator that is not a real-coded problem."); 377 450 var problemSize = ((RealParameterConfiguration)configuration.Parameters.First().Value).Length.Value; … … 404 477 } 405 478 } 406 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));407 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));408 479 Operators.AddRange(strategyOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 409 } 480 #endregion 481 #endregion 482 #region Wire RealVector ParticleCreators 483 Operators.RemoveAll(x => x is IRealVectorParticleCreator && ((IRealVectorParticleCreator)x).RealVectorParameter.ActualName != paramName); 484 var particleCreators = ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>().ToList(); 485 foreach (var pc in particleCreators) { 486 pc.RealVectorParameter.ActualName = paramName; 487 pc.RealVectorParameter.Hidden = true; 488 pc.BoundsParameter.ActualName = realCreator.BoundsParameter.Name; 489 pc.BoundsParameter.Hidden = true; 490 pc.ProblemSizeParameter.ActualName = paramName + "Length"; 491 pc.ProblemSizeParameter.Hidden = true; 492 } 493 Operators.AddRange(particleCreators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 494 #endregion 495 #region Wire RealVector ParticleUpdaters 496 Operators.RemoveAll(x => x is IRealVectorParticleUpdater && ((IRealVectorParticleUpdater)x).RealVectorParameter.ActualName != paramName); 497 var particleUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>().ToList(); 498 foreach (var pu in particleUpdaters) { 499 pu.RealVectorParameter.ActualName = paramName; 500 pu.RealVectorParameter.Hidden = true; 501 pu.BoundsParameter.ActualName = realCreator.BoundsParameter.Name; 502 pu.BoundsParameter.Hidden = true; 503 } 504 Operators.AddRange(particleUpdaters.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 505 #endregion 506 #region Wire RealVector SwarmUpdaters 507 Operators.RemoveAll(x => x is IRealVectorSwarmUpdater && ((IRealVectorSwarmUpdater)x).RealVectorParameter.ActualName != paramName); 508 var swarmUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>().ToList(); 509 foreach (var su in swarmUpdaters) { 510 su.RealVectorParameter.ActualName = paramName; 511 su.RealVectorParameter.Hidden = true; 512 su.MaximizationParameter.ActualName = MaximizationParameter.Name; 513 su.MaximizationParameter.Hidden = true; 514 } 515 Operators.AddRange(swarmUpdaters.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 516 #endregion 517 #region Wire RealVector ShakingOperators 518 Operators.RemoveAll(x => x is IRealVectorMultiNeighborhoodShakingOperator && ((IRealVectorMultiNeighborhoodShakingOperator)x).RealVectorParameter.ActualName != paramName); 519 var shakingOperators = ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>().ToList(); 520 foreach (var so in shakingOperators) { 521 so.RealVectorParameter.ActualName = paramName; 522 so.RealVectorParameter.Hidden = true; 523 } 524 Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 525 #endregion 526 } else { 527 Operators.RemoveAll(x => x is IRealVectorCrossover 528 || x is IRealVectorManipulator 529 || x is IRealVectorStdDevStrategyParameterOperator 530 || x is IRealVectorParticleCreator 531 || x is IRealVectorParticleUpdater 532 || x is IRealVectorSwarmUpdater 533 || x is IRealVectorMultiNeighborhoodShakingOperator); 534 } 535 #endregion 536 #region Configure Operators for PermutationEncoding 410 537 var permCreator = newCreator as IPermutationCreator; 411 538 if (permCreator != null) { … … 418 545 Operators.Add(SolutionCreator); 419 546 } 420 Operators.RemoveAll(x => x is ICrossover && !(x is IPermutationCrossover) || x is IPermutationCrossover && ((IPermutationCrossover)x).ChildParameter.ActualName != paramName); 421 Operators.RemoveAll(x => x is IManipulator && !(x is IPermutationManipulator) || x is IPermutationManipulator && ((IPermutationManipulator)x).PermutationParameter.ActualName != paramName); 547 548 #region Wire Permutation Crossovers 549 Operators.RemoveAll(x => x is IPermutationCrossover && ((IPermutationCrossover)x).ChildParameter.ActualName != paramName); 422 550 var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList(); 423 var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList();424 551 foreach (var xo in crossovers) { 425 552 xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName; 553 xo.ChildParameter.Hidden = true; 426 554 xo.ParentsParameter.ActualName = permCreator.PermutationParameter.ActualName; 427 } 428 foreach (var m in manipulators) 555 xo.ParentsParameter.Hidden = true; 556 } 557 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 558 #endregion 559 #region Wire Permutation Manipulators 560 Operators.RemoveAll(x => x is IPermutationManipulator && ((IPermutationManipulator)x).PermutationParameter.ActualName != paramName); 561 var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList(); 562 foreach (var m in manipulators) { 429 563 m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName; 430 Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 564 m.PermutationParameter.Hidden = true; 565 } 431 566 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 432 } 567 #endregion 568 #region Wire ShakingOperators 569 Operators.RemoveAll(x => x is IPermutationMultiNeighborhoodShakingOperator && ((IPermutationMultiNeighborhoodShakingOperator)x).PermutationParameter.ActualName != paramName); 570 var shakingOperators = ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>().ToList(); 571 foreach (var op in shakingOperators) { 572 op.PermutationParameter.ActualName = paramName; 573 op.PermutationParameter.Hidden = true; 574 } 575 Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 576 #endregion 577 } else { 578 Operators.RemoveAll(x => x is IPermutationCrossover 579 || x is IPermutationManipulator 580 || x is IPermutationMultiNeighborhoodShakingOperator); 581 } 582 #endregion 433 583 } 434 584 … … 437 587 var newCreator = new ParameterVectorCreater(); 438 588 439 /* 440 * Binary Vectors 441 */ 589 #region Configure BinaryVector Creator 442 590 var newBinParams = new HashSet<string>(solutionCreators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 443 591 if (oldCreator != null) { … … 463 611 } 464 612 } 465 466 /* 467 * Integer Vectors 468 */ 613 #endregion 614 #region Configure IntegerVector Creator 469 615 var newIntParams = new HashSet<string>(solutionCreators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 470 616 if (oldCreator != null) { … … 491 637 } 492 638 } 493 494 /* 495 * Real Vectors 496 */ 639 #endregion 640 #region Configure RealVector Creator 497 641 var newRealParams = new HashSet<string>(solutionCreators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 498 642 if (oldCreator != null) { … … 519 663 } 520 664 } 521 522 /* 523 * Permutations 524 */ 665 #endregion 666 #region Configure Permutation Creator 525 667 var newPermParams = new HashSet<string>(solutionCreators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 526 668 if (oldCreator != null) { … … 556 698 } 557 699 } 700 #endregion 558 701 559 702 if (oldCreator == null) SolutionCreator = newCreator; … … 562 705 // the condition checks if a multi-vector encoding is to be updated (there already exists ParameterVectorCrossover and ParameterVectorManipulator) 563 706 if (Operators.OfType<ParameterVectorCrossover>().Any() && Operators.OfType<ParameterVectorManipulator>().Any()) { 564 // Update the crossovers 707 #region Update existing multi-vector encoding 708 #region Update ParameterVector Crossover ... 565 709 foreach (var oldXo in Operators.OfType<ParameterVectorCrossover>()) { 566 /* 567 * Binary Vectors 568 */ 710 #region ... for binary parameters 569 711 var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>() 570 712 .Select(x => x.ChildParameter.ActualName)); … … 576 718 if (op != null) oldXo.Operators.Remove(op); 577 719 } 578 579 /* 580 * Integer Vectors 581 */ 720 #endregion 721 #region ... for integer parameters 582 722 var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>() 583 723 .Select(x => x.ChildParameter.ActualName)); … … 590 730 if (op != null) oldXo.Operators.Remove(op); 591 731 } 592 593 /* 594 * Real Vectors 595 */ 732 #endregion 733 #region ... for real parameters 596 734 var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>() 597 735 .Select(x => x.ChildParameter.ActualName)); … … 603 741 if (op != null) oldXo.Operators.Remove(op); 604 742 } 605 606 /* 607 * Permutations 608 */ 743 #endregion 744 #region ... for permutation parameters 609 745 var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>() 610 746 .Select(x => x.ChildParameter.ActualName)); … … 616 752 if (op != null) oldXo.Operators.Remove(op); 617 753 } 618 } 619 // Update the manipulators 754 #endregion 755 } 756 #endregion 757 #region Update ParameterVector Manipulator ... 620 758 foreach (var oldM in Operators.OfType<ParameterVectorManipulator>()) { 621 /* 622 * Binary Vectors 623 */ 759 #region ... for binary parameters 624 760 var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>() 625 761 .Select(x => x.BinaryVectorParameter.ActualName)); … … 632 768 if (op != null) oldM.Operators.Remove(op); 633 769 } 634 635 /* 636 * Integer Vectors 637 */ 770 #endregion 771 #region ... for integer parameters 638 772 var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>() 639 773 .Select(x => x.IntegerVectorParameter.ActualName)); … … 646 780 if (op != null) oldM.Operators.Remove(op); 647 781 } 648 649 /* 650 * Real Vectors 651 */ 782 #endregion 783 #region ... for real parameters 652 784 var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>() 653 785 .Select(x => x.RealVectorParameter.ActualName)); … … 660 792 if (op != null) oldM.Operators.Remove(op); 661 793 } 662 663 /* 664 * Permutations 665 */ 794 #endregion 795 #region ... for permutation parameters 666 796 var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>() 667 797 .Select(x => x.PermutationParameter.ActualName)); … … 674 804 if (op != null) oldM.Operators.Remove(op); 675 805 } 676 } 806 #endregion 807 } 808 #endregion 809 #endregion 677 810 } else { 678 // change from single-vector encodingto multi-vector encoding811 #region Handle transition from single-vector to multi-vector encoding 679 812 Operators.RemoveAll(x => x is ICrossover); 680 813 Operators.RemoveAll(x => x is IManipulator); 814 Operators.RemoveAll(x => x is IStrategyParameterCreator || x is IStrategyParameterManipulator || x is IStrategyParameterCrossover); 815 Operators.RemoveAll(x => x is IParticleCreator); 816 Operators.RemoveAll(x => x is IParticleUpdater); 817 Operators.RemoveAll(x => x is ISwarmUpdater); 818 Operators.RemoveAll(x => x is IMultiNeighborhoodShakingOperator); 819 681 820 var crossover = new ParameterVectorCrossover(); 682 821 var manipulator = new ParameterVectorManipulator(); … … 709 848 Operators.Add(crossover); 710 849 Operators.Add(manipulator); 850 #endregion 711 851 } 712 852 } … … 731 871 } 732 872 873 #region GetDefaultOperators for Crossovers and Manipulators 733 874 // ReSharper disable RedundantNameQualifier 734 875 protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configuration config) { … … 797 938 } 798 939 // ReSharper restore RedundantNameQualifier 940 #endregion 799 941 } 800 942 }
Note: See TracChangeset
for help on using the changeset viewer.