- Timestamp:
- 01/13/17 18:18:37 (8 years ago)
- Location:
- branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/PermutationMemPR.cs
r14556 r14563 52 52 foreach (var trainer in ApplicationManager.Manager.GetInstances<ISolutionModelTrainer<PermutationMemPRPopulationContext>>()) 53 53 SolutionModelTrainerParameter.ValidValues.Add(trainer); 54 54 55 if (SolutionModelTrainerParameter.ValidValues.Count > 0) { 56 var unbiased = SolutionModelTrainerParameter.ValidValues.FirstOrDefault(x => !x.Bias); 57 if (unbiased != null) SolutionModelTrainerParameter.Value = unbiased; 58 } 59 55 60 foreach (var localSearch in ApplicationManager.Manager.GetInstances<ILocalSearch<PermutationMemPRSolutionContext>>()) { 56 61 LocalSearchParameter.ValidValues.Add(localSearch); … … 290 295 InversionMove bestOfTheRest = null; 291 296 var improved = false; 292 297 293 298 foreach (var opt in ExhaustiveInversionMoveGenerator.Generate(current).Shuffle(random)) { 294 299 var prev = opt.Index1 - 1; … … 395 400 cache.Add(p2.Solution); 396 401 397 var cacheHits = 0;402 var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } }; 398 403 var evaluations = 0; 399 404 ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null; … … 401 406 while (evaluations < p1.Solution.Length) { 402 407 Encodings.PermutationEncoding.Permutation c = null; 403 var xochoice = Context.Random.Next(3);408 var xochoice = cacheHits.SampleRandom(Context.Random).Key; 404 409 switch (xochoice) { 405 410 case 0: c = CyclicCrossover2.Apply(Context.Random, p1.Solution, p2.Solution); break; … … 408 413 } 409 414 if (cache.Contains(c)) { 410 cacheHits++; 411 if (cacheHits > 10) break; 415 cacheHits[xochoice]++; 416 if (cacheHits[xochoice] > 10) { 417 cacheHits.Remove(xochoice); 418 if (cacheHits.Count == 0) break; 419 } 412 420 continue; 413 421 } … … 431 439 cache.Add(p2.Solution); 432 440 433 var cacheHits = 0;441 var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } }; 434 442 var evaluations = 0; 435 443 ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null; … … 437 445 while (evaluations < p1.Solution.Length) { 438 446 Encodings.PermutationEncoding.Permutation c = null; 439 var xochoice = Context.Random.Next(3);447 var xochoice = cacheHits.SampleRandom(Context.Random).Key; 440 448 switch (xochoice) { 441 449 case 0: c = OrderCrossover2.Apply(Context.Random, p1.Solution, p2.Solution); break; … … 444 452 } 445 453 if (cache.Contains(c)) { 446 cacheHits++; 447 if (cacheHits > 10) break; 454 cacheHits[xochoice]++; 455 if (cacheHits[xochoice] > 10) { 456 cacheHits.Remove(xochoice); 457 if (cacheHits.Count == 0) break; 458 } 448 459 continue; 449 460 } … … 467 478 cache.Add(p2.Solution); 468 479 469 var cacheHits = 0;480 var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } }; 470 481 var evaluations = 0; 471 482 ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null; … … 473 484 while (evaluations <= p1.Solution.Length) { 474 485 Encodings.PermutationEncoding.Permutation c = null; 475 var xochoice = Context.Random.Next(3);486 var xochoice = cacheHits.SampleRandom(Context.Random).Key; 476 487 switch (xochoice) { 477 488 case 0: c = OrderCrossover2.Apply(Context.Random, p1.Solution, p2.Solution); break; … … 480 491 } 481 492 if (cache.Contains(c)) { 482 cacheHits++; 483 if (cacheHits > 10) break; 493 cacheHits[xochoice]++; 494 if (cacheHits[xochoice] > 10) { 495 cacheHits.Remove(xochoice); 496 if (cacheHits.Count == 0) break; 497 } 484 498 continue; 485 499 } -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/SolutionModel/Univariate/BiasedModelTrainer.cs
r14552 r14563 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.PermutationEncoding;28 27 using HeuristicLab.Optimization; 29 28 using HeuristicLab.Parameters; … … 36 35 where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation>, 37 36 ISolutionModelContext<Encodings.PermutationEncoding.Permutation>, IEvaluationServiceContext<Encodings.PermutationEncoding.Permutation> { 37 38 public bool Bias { get { return true; } } 38 39 39 40 [Storable] -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/SolutionModel/Univariate/UnbiasedModelTrainer.cs
r14552 r14563 21 21 22 22 using System.Linq; 23 using HeuristicLab.Algorithms.MemPR.Binary.SolutionModel.Univariate;24 23 using HeuristicLab.Algorithms.MemPR.Interfaces; 25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; 27 using HeuristicLab.Encodings.PermutationEncoding;28 26 using HeuristicLab.Optimization; 29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 35 33 where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation>, 36 34 ISolutionModelContext<Encodings.PermutationEncoding.Permutation> { 37 35 36 public bool Bias { get { return false; } } 37 38 38 [StorableConstructor] 39 39 protected UnbiasedModelTrainer(bool deserializing) : base(deserializing) { }
Note: See TracChangeset
for help on using the changeset viewer.