- Timestamp:
- 01/13/17 18:18:37 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/BinaryMemPR.cs
r14557 r14563 45 45 foreach (var trainer in ApplicationManager.Manager.GetInstances<ISolutionModelTrainer<BinaryMemPRPopulationContext>>()) 46 46 SolutionModelTrainerParameter.ValidValues.Add(trainer); 47 47 48 if (SolutionModelTrainerParameter.ValidValues.Count > 0) { 49 var unbiased = SolutionModelTrainerParameter.ValidValues.FirstOrDefault(x => !x.Bias); 50 if (unbiased != null) SolutionModelTrainerParameter.Value = unbiased; 51 } 52 48 53 foreach (var localSearch in ApplicationManager.Manager.GetInstances<ILocalSearch<BinaryMemPRSolutionContext>>()) { 49 54 LocalSearchParameter.ValidValues.Add(localSearch); … … 156 161 cache.Add(p2.Solution); 157 162 158 var cacheHits = 0;163 var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } }; 159 164 ISingleObjectiveSolutionScope<BinaryVector> offspring = null; 165 160 166 while (evaluations < N) { 161 167 BinaryVector c = null; 162 var xochoice = Context.Random.Next(3);168 var xochoice = cacheHits.SampleRandom(Context.Random).Key; 163 169 switch (xochoice) { 164 170 case 0: c = NPointCrossover.Apply(Context.Random, p1.Solution, p2.Solution, new IntValue(1)); break; … … 167 173 } 168 174 if (cache.Contains(c)) { 169 cacheHits++; 170 if (cacheHits > 50) break; 175 cacheHits[xochoice]++; 176 if (cacheHits[xochoice] > 10) { 177 cacheHits.Remove(xochoice); 178 if (cacheHits.Count == 0) break; 179 } 171 180 continue; 172 181 }
Note: See TracChangeset
for help on using the changeset viewer.