Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3568 for trunk


Ignore:
Timestamp:
04/30/10 10:28:32 (15 years ago)
Author:
gkronber
Message:

Changed MultiOperator and MultiOperatorView to hold the list of operators in a CheckedItemList and display the list in a CheckedItemListView. #992

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Views/3.3/MultiOperatorView.Designer.cs

    r3407 r3568  
    4747      this.tabControl = new System.Windows.Forms.TabControl();
    4848      this.operatorsTabPage = new System.Windows.Forms.TabPage();
    49       this.operatorListView = new HeuristicLab.Core.Views.ItemListView<T>();
     49      this.operatorListView = new HeuristicLab.Core.Views.CheckedItemListView<T>();
    5050      this.parametersTabPage = new System.Windows.Forms.TabPage();
    5151      this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
     
    178178    protected System.Windows.Forms.TabPage parametersTabPage;
    179179    protected HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView;
    180     protected HeuristicLab.Core.Views.ItemListView<T> operatorListView;
     180    protected HeuristicLab.Core.Views.CheckedItemListView<T> operatorListView;
    181181    protected System.Windows.Forms.CheckBox breakpointCheckBox;
    182182    protected System.Windows.Forms.Label breakpointLabel;
  • trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs

    r3445 r3568  
    3939
    4040    [Storable]
    41     private ItemList<T> operators;
    42     public ItemList<T> Operators {
     41    private CheckedItemList<T> operators;
     42    public CheckedItemList<T> Operators {
    4343      get { return operators; }
    4444    }
     
    4646    public MultiOperator()
    4747      : base() {
    48       operators = new ItemList<T>();
     48      operators = new CheckedItemList<T>();
    4949      Initialize();
    5050    }
     
    6565    public override IDeepCloneable Clone(Cloner cloner) {
    6666      MultiOperator<T> clone = (MultiOperator<T>)base.Clone(cloner);
    67       clone.operators = (ItemList<T>)cloner.Clone(operators);
     67      clone.operators = (CheckedItemList<T>)cloner.Clone(operators);
    6868      clone.Initialize();
    6969      return clone;
  • trunk/sources/HeuristicLab.Operators/3.3/StochasticMultiOperator.cs

    r3527 r3568  
    113113    /// </summary>
    114114    /// <exception cref="InvalidOperationException">Thrown when the list of probabilites does not
    115     /// match the number of operators.</exception>
     115    /// match the number of operators, the list of selected operators is empty,
     116    /// or all selected operators have zero probabitlity.</exception>
    116117    /// <returns>A new operation with the operator that was selected followed by the current operator's successor.</returns>
    117118    public override IOperation Apply() {
    118119      IRandom random = RandomParameter.ActualValue;
    119120      DoubleArray probabilities = ProbabilitiesParameter.ActualValue;
    120       if(probabilities.Length != Operators.Count) {
     121      if (probabilities.Length != Operators.Count) {
    121122        throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators");
    122123      }
    123       double sum = 0;
    124       for (int i = 0; i < Operators.Count; i++) {
    125         sum += probabilities[i];
     124      var checkedOperators = Operators.CheckedItems;
     125      if (checkedOperators.Count() == 0) {
     126        throw new InvalidOperationException(Name + ": At least one operator must be checked.");
    126127      }
     128      double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum();
     129      if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
    127130      double r = random.NextDouble() * sum;
    128131      sum = 0;
    129132      IOperator successor = null;
    130       for(int i = 0; i < Operators.Count; i++) {
    131         sum += probabilities[i];
    132         if(sum > r) {
    133           successor = Operators[i];
     133      foreach (var indexedItem in checkedOperators) {
     134        sum += probabilities[indexedItem.Index];
     135        if (sum > r) {
     136          successor = indexedItem.Value;
    134137          break;
    135138        }
Note: See TracChangeset for help on using the changeset viewer.