Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/07/14 15:05:58 (11 years ago)
Author:
svonolfe
Message:

Adapted all VRP related operators to subclass InstrumentedOperator (#2119)

Location:
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/BiasedMultiVRPSolutionCrossover.cs

    r10295 r10298  
    131131      }
    132132
    133       return base.InstrumentedApply();
     133      ////////////////
     134      IRandom random = RandomParameter.ActualValue;
     135      DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue;
     136      if (probabilities.Length != Operators.Count) {
     137        throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators");
     138      }
     139      var checkedOperators = Operators.CheckedItems;
     140      if (checkedOperators.Count() > 0) {
     141        // select a random operator from the checked operators
     142        double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum();
     143        if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
     144        double r = random.NextDouble() * sum;
     145        sum = 0;
     146        foreach (var indexedItem in checkedOperators) {
     147          sum += probabilities[indexedItem.Index];
     148          if (sum > r) {
     149            successor = indexedItem.Value;
     150            break;
     151          }
     152        }
     153      }
     154
     155      IOperation successorOp = null;
     156      if (Successor != null)
     157        successorOp = ExecutionContext.CreateOperation(Successor);
     158      OperationCollection next = new OperationCollection(successorOp);
     159      if (successor != null) {
     160        SelectedOperatorParameter.ActualValue = new StringValue(successor.Name);
     161
     162        if (CreateChildOperation)
     163          next.Insert(0, ExecutionContext.CreateChildOperation(successor));
     164        else next.Insert(0, ExecutionContext.CreateOperation(successor));
     165      } else {
     166        SelectedOperatorParameter.ActualValue = new StringValue("");
     167      }
     168
     169      return next;
    134170    }
    135171  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/RandomParentCloneCrossover.cs

    r9456 r10298  
    6565    }
    6666
    67     public override IOperation Apply() {
     67    public override IOperation InstrumentedApply() {
    6868      if (RandomParameter.ActualValue.Next() < 0.5)
    6969        ChildParameter.ActualValue = ParentsParameter.ActualValue[0].Clone() as IVRPEncoding;
     
    7171        ChildParameter.ActualValue = ParentsParameter.ActualValue[1].Clone() as IVRPEncoding;
    7272
    73       return base.Apply();
     73      return base.InstrumentedApply();
    7474    }
    7575  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/BiasedMultiVRPSolutionManipulator.cs

    r10295 r10298  
    131131      }
    132132
    133       return base.InstrumentedApply();
     133      ////////////////
     134      IRandom random = RandomParameter.ActualValue;
     135      DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue;
     136      if (probabilities.Length != Operators.Count) {
     137        throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators");
     138      }
     139      var checkedOperators = Operators.CheckedItems;
     140      if (checkedOperators.Count() > 0) {
     141        // select a random operator from the checked operators
     142        double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum();
     143        if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
     144        double r = random.NextDouble() * sum;
     145        sum = 0;
     146        foreach (var indexedItem in checkedOperators) {
     147          sum += probabilities[indexedItem.Index];
     148          if (sum > r) {
     149            successor = indexedItem.Value;
     150            break;
     151          }
     152        }
     153      }
     154
     155      IOperation successorOp = null;
     156      if (Successor != null)
     157        successorOp = ExecutionContext.CreateOperation(Successor);
     158      OperationCollection next = new OperationCollection(successorOp);
     159      if (successor != null) {
     160        SelectedOperatorParameter.ActualValue = new StringValue(successor.Name);
     161
     162        if (CreateChildOperation)
     163          next.Insert(0, ExecutionContext.CreateChildOperation(successor));
     164        else next.Insert(0, ExecutionContext.CreateOperation(successor));
     165      } else {
     166        SelectedOperatorParameter.ActualValue = new StringValue("");
     167      }
     168
     169      return next;
    134170    }
    135171  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/MultiVRPMoveOperator/MultiVRPMoveEvaluator.cs

    r9456 r10298  
    5353    protected override void EvaluateMove() { }
    5454
    55     public override IOperation Apply() {
     55    public override IOperation InstrumentedApply() {
    5656      IVRPMove move = VRPMoveParameter.ActualValue as IVRPMove;
    5757
     
    5959      moveEvaluator.VRPMoveParameter.ActualName = VRPMoveParameter.Name;
    6060
    61       OperationCollection next = new OperationCollection(base.Apply());
     61      OperationCollection next = new OperationCollection(base.InstrumentedApply());
    6262      next.Insert(0, ExecutionContext.CreateOperation(moveEvaluator));
    6363
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveEvaluator.cs

    r9456 r10298  
    7676    protected abstract void EvaluateMove();
    7777
    78     public override IOperation Apply() {
     78    public override IOperation InstrumentedApply() {
    7979      EvaluateMove();
    8080
    81       return base.Apply();
     81      return base.InstrumentedApply();
    8282    }
    8383  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveMaker.cs

    r9456 r10298  
    9999    }
    100100
    101     public override IOperation Apply() {
     101    public override IOperation InstrumentedApply() {
    102102      PerformMove();
    103103      UpdateMoveEvaluation();
    104104
    105       return base.Apply();
     105      return base.InstrumentedApply();
    106106    }
    107107  }
Note: See TracChangeset for help on using the changeset viewer.