- Timestamp:
- 01/05/17 00:32:43 (8 years ago)
- Location:
- branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageMemPR.cs
r14496 r14544 34 34 using HeuristicLab.Random; 35 35 36 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage{36 namespace HeuristicLab.Algorithms.MemPR.Grouping { 37 37 [Item("MemPR (linear linkage)", "MemPR implementation for linear linkage vectors.")] 38 38 [StorableClass] 39 39 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 999)] 40 public class LinearLinkageMemPR : MemPRAlgorithm<SingleObjectiveBasicProblem<LinearLinkageEncoding>, Encodings.LinearLinkageEncoding.LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext> { 41 private const double UncommonBitSubsetMutationProbabilityMagicConst = 0.05; 42 40 public class LinearLinkageMemPR : MemPRAlgorithm<SingleObjectiveBasicProblem<LinearLinkageEncoding>, LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext> { 43 41 [StorableConstructor] 44 42 protected LinearLinkageMemPR(bool deserializing) : base(deserializing) { } … … 57 55 } 58 56 59 protected override bool Eq(ISingleObjectiveSolutionScope< Encodings.LinearLinkageEncoding.LinearLinkage> a, ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> b) {57 protected override bool Eq(ISingleObjectiveSolutionScope<LinearLinkage> a, ISingleObjectiveSolutionScope<LinearLinkage> b) { 60 58 var s1 = a.Solution; 61 59 var s2 = b.Solution; … … 66 64 } 67 65 68 protected override double Dist(ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> a, ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> b) { 69 return 1.0 - HammingSimilarityCalculator.CalculateSimilarity(a.Solution, b.Solution); 70 } 71 72 protected override ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> ToScope(Encodings.LinearLinkageEncoding.LinearLinkage code, double fitness = double.NaN) { 66 protected override double Dist(ISingleObjectiveSolutionScope<LinearLinkage> a, ISingleObjectiveSolutionScope<LinearLinkage> b) { 67 return Dist(a.Solution, b.Solution); 68 } 69 70 private double Dist(LinearLinkage a, LinearLinkage b) { 71 return 1.0 - HammingSimilarityCalculator.CalculateSimilarity(a, b); 72 } 73 74 protected override ISingleObjectiveSolutionScope<LinearLinkage> ToScope(LinearLinkage code, double fitness = double.NaN) { 73 75 var creator = Problem.SolutionCreator as ILinearLinkageCreator; 74 76 if (creator == null) throw new InvalidOperationException("Can only solve linear linkage encoded problems with MemPR (linear linkage)"); 75 return new SingleObjectiveSolutionScope< Encodings.LinearLinkageEncoding.LinearLinkage>(code, creator.LLEParameter.ActualName, fitness, Problem.Evaluator.QualityParameter.ActualName) {77 return new SingleObjectiveSolutionScope<LinearLinkage>(code, creator.LLEParameter.ActualName, fitness, Problem.Evaluator.QualityParameter.ActualName) { 76 78 Parent = Context.Scope 77 79 }; 78 80 } 79 81 80 protected override ISolutionSubspace< Encodings.LinearLinkageEncoding.LinearLinkage> CalculateSubspace(IEnumerable<Encodings.LinearLinkageEncoding.LinearLinkage> solutions, bool inverse = false) {82 protected override ISolutionSubspace<LinearLinkage> CalculateSubspace(IEnumerable<LinearLinkage> solutions, bool inverse = false) { 81 83 var pop = solutions.ToList(); 82 84 var N = pop[0].Length; … … 92 94 } 93 95 94 protected override int TabuWalk(95 ISingleObjectiveSolutionScope< Encodings.LinearLinkageEncoding.LinearLinkage> scope,96 protected override void AdaptiveWalk( 97 ISingleObjectiveSolutionScope<LinearLinkage> scope, 96 98 int maxEvals, CancellationToken token, 97 ISolutionSubspace< Encodings.LinearLinkageEncoding.LinearLinkage> sub_space = null) {99 ISolutionSubspace<LinearLinkage> sub_space = null) { 98 100 var maximization = Context.Problem.Maximization; 99 101 var subspace = sub_space is LinearLinkageSolutionSubspace ? ((LinearLinkageSolutionSubspace)sub_space).Subspace : null; … … 104 106 quality = scope.Fitness; 105 107 evaluations++; 106 if (evaluations >= maxEvals) return evaluations;108 if (evaluations >= maxEvals) return; 107 109 } 108 110 var bestQuality = quality; 109 var currentScope = (ISingleObjectiveSolutionScope< Encodings.LinearLinkageEncoding.LinearLinkage>)scope.Clone();111 var currentScope = (ISingleObjectiveSolutionScope<LinearLinkage>)scope.Clone(); 110 112 var current = currentScope.Solution; 111 Encodings.LinearLinkageEncoding.LinearLinkage bestOfTheWalk = null;113 LinearLinkage bestOfTheWalk = null; 112 114 var bestOfTheWalkF = double.NaN; 113 115 … … 153 155 } 154 156 if (FitnessComparer.IsBetter(maximization, bestOfTheRestF, bestOfTheWalkF)) { 155 bestOfTheWalk = ( Encodings.LinearLinkageEncoding.LinearLinkage)current.Clone();157 bestOfTheWalk = (LinearLinkage)current.Clone(); 156 158 bestOfTheWalkF = bestOfTheRestF; 157 159 } … … 190 192 191 193 if (FitnessComparer.IsBetter(maximization, moveF, bestOfTheWalkF)) { 192 bestOfTheWalk = ( Encodings.LinearLinkageEncoding.LinearLinkage)current.Clone();194 bestOfTheWalk = (LinearLinkage)current.Clone(); 193 195 bestOfTheWalkF = moveF; 194 196 } … … 232 234 } 233 235 if (FitnessComparer.IsBetter(maximization, bestOfTheRestF, bestOfTheWalkF)) { 234 bestOfTheWalk = ( Encodings.LinearLinkageEncoding.LinearLinkage)current.Clone();236 bestOfTheWalk = (LinearLinkage)current.Clone(); 235 237 bestOfTheWalkF = bestOfTheRestF; 236 238 } … … 247 249 scope.Fitness = bestOfTheWalkF; 248 250 } 249 return evaluations; 250 } 251 252 protected override ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> Cross(ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> p1Scope, ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> p2Scope, CancellationToken token) { 253 var p1 = p1Scope.Solution; 254 var p2 = p2Scope.Solution; 255 return ToScope(GroupCrossover.Apply(Context.Random, p1, p2)); 256 } 257 258 protected override void Mutate(ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> offspring, CancellationToken token, ISolutionSubspace<Encodings.LinearLinkageEncoding.LinearLinkage> subspace = null) { 259 var lle = offspring.Solution; 260 var subset = subspace is LinearLinkageSolutionSubspace ? ((LinearLinkageSolutionSubspace)subspace).Subspace : null; 261 for (var i = 0; i < lle.Length - 1; i++) { 262 if (subset == null || subset[i]) continue; // mutation works against crossover so aims to mutate noTouch points 263 if (Context.Random.NextDouble() < UncommonBitSubsetMutationProbabilityMagicConst) { 264 subset[i] = true; 265 var index = Context.Random.Next(i, lle.Length); 266 for (var j = index - 1; j >= i; j--) { 267 if (lle[j] == index) index = j; 268 } 269 lle[i] = index; 270 index = i; 271 var idx2 = i; 272 for (var j = i - 1; j >= 0; j--) { 273 if (lle[j] == lle[index]) { 274 lle[j] = idx2; 275 index = idx2 = j; 276 } else if (lle[j] == idx2) idx2 = j; 277 } 278 } 279 } 280 } 281 282 protected override ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> Relink(ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> a, ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage> b, CancellationToken token) { 283 var maximization = Context.Problem.Maximization; 251 } 252 253 protected override ISingleObjectiveSolutionScope<LinearLinkage> Breed(ISingleObjectiveSolutionScope<LinearLinkage> p1Scope, ISingleObjectiveSolutionScope<LinearLinkage> p2Scope, CancellationToken token) { 254 var cache = new HashSet<LinearLinkage>(new LinearLinkageEqualityComparer()); 255 var cachehits = 0; 256 var evaluations = 1; 257 ISingleObjectiveSolutionScope<LinearLinkage> offspring = null; 258 for (; evaluations < Context.LocalSearchEvaluations; evaluations++) { 259 var code = GroupCrossover.Apply(Context.Random, p1Scope.Solution, p2Scope.Solution); 260 if (cache.Contains(code)) { 261 cachehits++; 262 if (cachehits > 10) break; 263 continue; 264 } 265 var probe = ToScope(code); 266 Evaluate(probe, token); 267 cache.Add(code); 268 if (offspring == null || Context.IsBetter(probe, offspring)) { 269 offspring = probe; 270 if (Context.IsBetter(offspring, p1Scope) && Context.IsBetter(offspring, p2Scope)) 271 break; 272 } 273 } 274 Context.IncrementEvaluatedSolutions(evaluations-1); 275 return offspring; 276 } 277 278 protected override ISingleObjectiveSolutionScope<LinearLinkage> Link(ISingleObjectiveSolutionScope<LinearLinkage> a, ISingleObjectiveSolutionScope<LinearLinkage> b, CancellationToken token, bool delink = false) { 279 var evaluations = 0; 284 280 if (double.IsNaN(a.Fitness)) { 285 281 Evaluate(a, token); 286 Context.IncrementEvaluatedSolutions(1);282 evaluations++; 287 283 } 288 284 if (double.IsNaN(b.Fitness)) { 289 285 Evaluate(b, token); 290 Context.IncrementEvaluatedSolutions(1); 291 } 292 var child = (ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage>)a.Clone(); 293 var cgroups = child.Solution.GetGroups().Select(x => new HashSet<int>(x)).ToList(); 294 var g2 = b.Solution.GetGroups().ToList(); 295 var order = Enumerable.Range(0, g2.Count).Shuffle(Context.Random).ToList(); 296 ISingleObjectiveSolutionScope <Encodings.LinearLinkageEncoding.LinearLinkage> bestChild = null; 297 for (var j = 0; j < g2.Count; j++) { 298 var g = g2[order[j]]; 299 var changed = false; 300 for (var k = j; k < cgroups.Count; k++) { 301 foreach (var f in g) if (cgroups[k].Remove(f)) changed = true; 302 if (cgroups[k].Count == 0) { 303 cgroups.RemoveAt(k); 304 k--; 305 } 306 } 307 cgroups.Insert(0, new HashSet<int>(g)); 308 child.Solution.SetGroups(cgroups); 309 if (changed) { 310 Evaluate(child, token); 311 if (bestChild == null || FitnessComparer.IsBetter(maximization, child.Fitness, bestChild.Fitness)) { 312 bestChild = (ISingleObjectiveSolutionScope<Encodings.LinearLinkageEncoding.LinearLinkage>)child.Clone(); 313 } 314 } 315 }; 316 return bestChild; 286 evaluations++; 287 } 288 289 var probe = (ISingleObjectiveSolutionScope<LinearLinkage>)a.Clone(); 290 ISingleObjectiveSolutionScope<LinearLinkage> best = null; 291 while (true) { 292 Move bestMove = null; 293 var bestMoveQ = double.NaN; 294 // this approach may not fully relink the two solutions 295 foreach (var m in MoveGenerator.Generate(probe.Solution)) { 296 var distBefore = Dist(probe, b); 297 m.Apply(probe.Solution); 298 var distAfter = Dist(probe, b); 299 if (delink && distAfter > distBefore || !delink && distAfter < distBefore) { 300 var beforeQ = probe.Fitness; 301 Evaluate(probe, token); 302 evaluations++; 303 var q = probe.Fitness; 304 m.Undo(probe.Solution); 305 probe.Fitness = beforeQ; 306 307 if (Context.IsBetter(q, bestMoveQ)) { 308 bestMove = m; 309 bestMoveQ = q; 310 } 311 if (Context.IsBetter(q, beforeQ)) break; 312 } else m.Undo(probe.Solution); 313 } 314 if (bestMove == null) break; 315 bestMove.Apply(probe.Solution); 316 probe.Fitness = bestMoveQ; 317 if (best == null || Context.IsBetter(probe, best)) 318 best = (ISingleObjectiveSolutionScope<LinearLinkage>)probe.Clone(); 319 } 320 Context.IncrementEvaluatedSolutions(evaluations); 321 322 return best ?? probe; 317 323 } 318 324 } -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageMemPRContext.cs
r14466 r14544 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage{30 namespace HeuristicLab.Algorithms.MemPR.Grouping { 31 31 [Item("MemPR Population Context (linear linkage)", "MemPR population context for linear linkage encoded problems.")] 32 32 [StorableClass] 33 public sealed class LinearLinkageMemPRPopulationContext : MemPRPopulationContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, Encodings.LinearLinkageEncoding.LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext> {33 public sealed class LinearLinkageMemPRPopulationContext : MemPRPopulationContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext> { 34 34 35 35 [StorableConstructor] … … 44 44 } 45 45 46 public override LinearLinkageMemPRSolutionContext CreateSingleSolutionContext(ISingleObjectiveSolutionScope< Encodings.LinearLinkageEncoding.LinearLinkage> solution) {46 public override LinearLinkageMemPRSolutionContext CreateSingleSolutionContext(ISingleObjectiveSolutionScope<LinearLinkage> solution) { 47 47 return new LinearLinkageMemPRSolutionContext(this, solution); 48 48 } … … 51 51 [Item("MemPR Solution Context (linear linkage)", "MemPR solution context for linear linkage encoded problems.")] 52 52 [StorableClass] 53 public sealed class LinearLinkageMemPRSolutionContext : MemPRSolutionContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, Encodings.LinearLinkageEncoding.LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext>, ILinearLinkageSubspaceContext {53 public sealed class LinearLinkageMemPRSolutionContext : MemPRSolutionContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, LinearLinkage, LinearLinkageMemPRPopulationContext, LinearLinkageMemPRSolutionContext>, ILinearLinkageSubspaceContext { 54 54 55 55 [Storable] … … 58 58 get { return subspace.Value; } 59 59 } 60 ISolutionSubspace< Encodings.LinearLinkageEncoding.LinearLinkage> ISolutionSubspaceContext<Encodings.LinearLinkageEncoding.LinearLinkage>.Subspace {60 ISolutionSubspace<LinearLinkage> ISolutionSubspaceContext<LinearLinkage>.Subspace { 61 61 get { return Subspace; } 62 62 } … … 68 68 69 69 } 70 public LinearLinkageMemPRSolutionContext(LinearLinkageMemPRPopulationContext baseContext, ISingleObjectiveSolutionScope< Encodings.LinearLinkageEncoding.LinearLinkage> solution)70 public LinearLinkageMemPRSolutionContext(LinearLinkageMemPRPopulationContext baseContext, ISingleObjectiveSolutionScope<LinearLinkage> solution) 71 71 : base(baseContext, solution) { 72 72 -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageSolutionSubspace.cs
r14466 r14544 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.LinearLinkageEncoding; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage{28 namespace HeuristicLab.Algorithms.MemPR.Grouping { 28 29 [Item("Solution subspace (linear linkage)", "")] 29 30 [StorableClass] 30 public sealed class LinearLinkageSolutionSubspace : Item, ISolutionSubspace< Encodings.LinearLinkageEncoding.LinearLinkage> {31 public sealed class LinearLinkageSolutionSubspace : Item, ISolutionSubspace<LinearLinkage> { 31 32 32 33 [Storable] -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LocalSearch/ExhaustiveSubspace.cs
r14466 r14544 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage.LocalSearch {31 namespace HeuristicLab.Algorithms.MemPR.Grouping.LocalSearch { 32 32 [Item("Exhaustive Local (Subspace) Search (linear linkage)", "", ExcludeGenericTypeInfo = true)] 33 33 [StorableClass] 34 34 public class ExhaustiveSubspace<TContext> : NamedItem, ILocalSearch<TContext> 35 where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, Encodings.LinearLinkageEncoding.LinearLinkage>, ILinearLinkageSubspaceContext {35 where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, LinearLinkage>, ILinearLinkageSubspaceContext { 36 36 37 37 [StorableConstructor] … … 48 48 49 49 public void Optimize(TContext context) { 50 var evalWrapper = new EvaluationWrapper< Encodings.LinearLinkageEncoding.LinearLinkage>(context.Problem, context.Solution);50 var evalWrapper = new EvaluationWrapper<LinearLinkage>(context.Problem, context.Solution); 51 51 var quality = context.Solution.Fitness; 52 52 try { -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LocalSearch/StaticAPI/ExhaustiveLocalSearch.cs
r14477 r14544 26 26 using HeuristicLab.Collections; 27 27 using HeuristicLab.Core; 28 29 namespace HeuristicLab.Algorithms.MemPR.LinearLinkage.LocalSearch { 28 using HeuristicLab.Encodings.LinearLinkageEncoding; 29 30 namespace HeuristicLab.Algorithms.MemPR.Grouping.LocalSearch { 30 31 public static class ExhaustiveLocalSearch { 31 public static Tuple<int, int> Optimize(IRandom random, Encodings.LinearLinkageEncoding.LinearLinkage solution, ref double quality, bool maximization, Func<Encodings.LinearLinkageEncoding.LinearLinkage, IRandom, double> eval, CancellationToken token, bool[] subspace = null) {32 public static Tuple<int, int> Optimize(IRandom random, LinearLinkage solution, ref double quality, bool maximization, Func<LinearLinkage, IRandom, double> eval, CancellationToken token, bool[] subspace = null) { 32 33 var evaluations = 0; 33 34 var current = solution; … … 153 154 } 154 155 155 public static Tuple<int, int> OptimizeSwapOnly(IRandom random, Encodings.LinearLinkageEncoding.LinearLinkage solution, ref double quality, bool maximization, Func<Encodings.LinearLinkageEncoding.LinearLinkage, IRandom, double> eval, CancellationToken token) {156 public static Tuple<int, int> OptimizeSwapOnly(IRandom random, LinearLinkage solution, ref double quality, bool maximization, Func<LinearLinkage, IRandom, double> eval, CancellationToken token) { 156 157 var evaluations = 0; 157 158 var current = solution; -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/SolutionModel/Univariate/StaticAPI/Trainer.cs
r14466 r14544 23 23 using HeuristicLab.Algorithms.MemPR.Interfaces; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.LinearLinkageEncoding; 25 26 26 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage.SolutionModel.Univariate {27 namespace HeuristicLab.Algorithms.MemPR.Grouping.SolutionModel.Univariate { 27 28 public static class Trainer { 28 29 29 public static ISolutionModel< Encodings.LinearLinkageEncoding.LinearLinkage> Train(IRandom random,30 IEnumerable< Encodings.LinearLinkageEncoding.LinearLinkage> pop) {30 public static ISolutionModel<LinearLinkage> Train(IRandom random, 31 IEnumerable<LinearLinkage> pop) { 31 32 return UnivariateModel.Create(random, pop); 32 33 } -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/SolutionModel/Univariate/UnbiasedModelTrainer.cs
r14466 r14544 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.LinearLinkageEncoding; 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 29 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage.SolutionModel.Univariate {30 namespace HeuristicLab.Algorithms.MemPR.Grouping.SolutionModel.Univariate { 30 31 [Item("Unbiased Univariate Model Trainer (linear linkage)", "", ExcludeGenericTypeInfo = true)] 31 32 [StorableClass] 32 33 public class UniasedModelTrainer<TContext> : NamedItem, ISolutionModelTrainer<TContext> 33 where TContext : IPopulationBasedHeuristicAlgorithmContext<SingleObjectiveBasicProblem< Encodings.LinearLinkageEncoding.LinearLinkageEncoding>, Encodings.LinearLinkageEncoding.LinearLinkage>, ISolutionModelContext<Encodings.LinearLinkageEncoding.LinearLinkage> {34 where TContext : IPopulationBasedHeuristicAlgorithmContext<SingleObjectiveBasicProblem<LinearLinkageEncoding>, LinearLinkage>, ISolutionModelContext<LinearLinkage> { 34 35 35 36 [StorableConstructor] -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/SolutionModel/Univariate/UnivariateSolutionModel.cs
r14487 r14544 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.LinearLinkageEncoding; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 30 namespace HeuristicLab.Algorithms.MemPR. LinearLinkage.SolutionModel.Univariate {31 namespace HeuristicLab.Algorithms.MemPR.Grouping.SolutionModel.Univariate { 31 32 [Item("Univariate solution model (linear linkage)", "")] 32 33 [StorableClass] 33 public sealed class UnivariateModel : Item, ISolutionModel< Encodings.LinearLinkageEncoding.LinearLinkage> {34 public sealed class UnivariateModel : Item, ISolutionModel<LinearLinkage> { 34 35 [Storable] 35 36 public IntMatrix Frequencies { get; set; } … … 61 62 } 62 63 63 public Encodings.LinearLinkageEncoding.LinearLinkage Sample() {64 public LinearLinkage Sample() { 64 65 var N = Frequencies.Rows; 65 var centroid = Encodings.LinearLinkageEncoding.LinearLinkage.SingleElementGroups(N);66 var centroid = LinearLinkage.SingleElementGroups(N); 66 67 var dict = new Dictionary<int, int>(); 67 68 for (var i = N - 1; i >= 0; i--) { … … 87 88 } 88 89 89 public static ISolutionModel< Encodings.LinearLinkageEncoding.LinearLinkage> Create(IRandom random, IEnumerable<Encodings.LinearLinkageEncoding.LinearLinkage> population) {90 public static ISolutionModel<LinearLinkage> Create(IRandom random, IEnumerable<LinearLinkage> population) { 90 91 var iter = population.GetEnumerator(); 91 92 if (!iter.MoveNext()) throw new ArgumentException("Cannot create solution model from empty population.");
Note: See TracChangeset
for help on using the changeset viewer.