Changeset 1218 for trunk/sources/HeuristicLab.SimOpt
- Timestamp:
- 02/16/09 01:21:53 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.SimOpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SimOpt/SimOptDiscreteMultiCrossover.cs
r637 r1218 29 29 30 30 namespace HeuristicLab.SimOpt { 31 public class SimOptDiscreteMultiCrossover : MultiCrossoverBase {31 public class SimOptDiscreteMultiCrossover : CrossoverBase { 32 32 33 33 public override string Description { … … 40 40 } 41 41 42 protected override void Cross(IScope scope, IRandom random , IScope[] parents, IScope child) {42 protected override void Cross(IScope scope, IRandom random) { 43 43 ICollection<IConstraint> violated; 44 44 45 ConstrainedItemList[] p = new ConstrainedItemList[ parents.Length];45 ConstrainedItemList[] p = new ConstrainedItemList[scope.SubScopes.Count]; 46 46 for (int i = 0; i < p.Length; i++) { 47 p[i] = parents[i].GetVariableValue<ConstrainedItemList>("Item", false);47 p[i] = scope.SubScopes[i].GetVariableValue<ConstrainedItemList>("Item", false); 48 48 if (i > 0 && p[i].Count != p[i-1].Count) throw new InvalidOperationException("ERROR: the lists do not contain the same number of items"); 49 49 } … … 55 55 childList.BeginCombinedOperation(); 56 56 for (int i = 0; i < childList.Count; i++) { 57 int nextParent = random.Next(0, parents.Length);57 int nextParent = random.Next(0, scope.SubScopes.Count); 58 58 if (nextParent > 0) childList.TrySetAt(i, (IItem)p[nextParent].Clone(), out violated); 59 59 } 60 60 } while (!childList.EndCombinedOperation(out violated) && ++iter < 100); 61 61 if (violated.Count == 0) { 62 child.AddVariable(new Variable(parents[0].TranslateName("Item"), childList));62 scope.AddVariable(new Variable(scope.SubScopes[0].TranslateName("Item"), childList)); 63 63 } 64 64 } -
trunk/sources/HeuristicLab.SimOpt/SimOptSinglePointCrossover.cs
r637 r1218 40 40 } 41 41 42 protected override void Cross(IScope scope, IRandom random , IScope parent1, IScope parent2, IScope child) {42 protected override void Cross(IScope scope, IRandom random) { 43 43 ICollection<IConstraint> violated; 44 ConstrainedItemList p1 = parent1.GetVariableValue<ConstrainedItemList>("Item", false);45 ConstrainedItemList p2 = parent2.GetVariableValue<ConstrainedItemList>("Item", false);44 ConstrainedItemList p1 = scope.SubScopes[0].GetVariableValue<ConstrainedItemList>("Item", false); 45 ConstrainedItemList p2 = scope.SubScopes[1].GetVariableValue<ConstrainedItemList>("Item", false); 46 46 47 47 if (p1.Count != p2.Count) throw new InvalidOperationException("ERROR: the lists do not contain the same number of items"); … … 58 58 } while (!childList.EndCombinedOperation(out violated) && ++iter < 100); 59 59 if (violated.Count == 0) { 60 child.AddVariable(new Variable(parent1.TranslateName("Item"), childList));60 scope.AddVariable(new Variable(scope.SubScopes[0].TranslateName("Item"), childList)); 61 61 } 62 62 }
Note: See TracChangeset
for help on using the changeset viewer.