Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.