Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/09 01:21:53 (15 years ago)
Author:
swagner
Message:

Refactoring of crossover operators (#470)

Location:
trunk/sources/HeuristicLab.SimOpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SimOpt/SimOptDiscreteMultiCrossover.cs

    r637 r1218  
    2929
    3030namespace HeuristicLab.SimOpt {
    31   public class SimOptDiscreteMultiCrossover : MultiCrossoverBase {
     31  public class SimOptDiscreteMultiCrossover : CrossoverBase {
    3232
    3333    public override string Description {
     
    4040    }
    4141
    42     protected override void Cross(IScope scope, IRandom random, IScope[] parents, IScope child) {
     42    protected override void Cross(IScope scope, IRandom random) {
    4343      ICollection<IConstraint> violated;
    4444
    45       ConstrainedItemList[] p = new ConstrainedItemList[parents.Length];
     45      ConstrainedItemList[] p = new ConstrainedItemList[scope.SubScopes.Count];
    4646      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);
    4848        if (i > 0 && p[i].Count != p[i-1].Count) throw new InvalidOperationException("ERROR: the lists do not contain the same number of items");
    4949      }
     
    5555          childList.BeginCombinedOperation();
    5656          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);
    5858            if (nextParent > 0) childList.TrySetAt(i, (IItem)p[nextParent].Clone(), out violated);
    5959          }
    6060        } while (!childList.EndCombinedOperation(out violated) && ++iter < 100);
    6161        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));
    6363        }
    6464      }
  • trunk/sources/HeuristicLab.SimOpt/SimOptSinglePointCrossover.cs

    r637 r1218  
    4040    }
    4141
    42     protected override void Cross(IScope scope, IRandom random, IScope parent1, IScope parent2, IScope child) {
     42    protected override void Cross(IScope scope, IRandom random) {
    4343      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);
    4646
    4747      if (p1.Count != p2.Count) throw new InvalidOperationException("ERROR: the lists do not contain the same number of items");
     
    5858        } while (!childList.EndCombinedOperation(out violated) && ++iter < 100);
    5959        if (violated.Count == 0) {
    60           child.AddVariable(new Variable(parent1.TranslateName("Item"), childList));
     60          scope.AddVariable(new Variable(scope.SubScopes[0].TranslateName("Item"), childList));
    6161        }
    6262      }
Note: See TracChangeset for help on using the changeset viewer.