private void BuildOperatorGraph() { OperatorGraph.Operators.Clear(); SubScopesProcessor firstProcessor = new SubScopesProcessor(); EmptyOperator firstEmpty = new EmptyOperator(); RightChildReducer firstRightChildReducer = new RightChildReducer(); OperatorGraph.InitialOperator = firstProcessor; firstProcessor.Operators.Add(CheckedSelectors.FirstOrDefault()); firstProcessor.Operators.Add(firstEmpty); firstProcessor.Successor = firstRightChildReducer; SingleSuccessorOperator previous = firstRightChildReducer; foreach (var selector in CheckedSelectors.Skip(1)) { SubScopesProcessor selectionProcessor = new SubScopesProcessor(); EmptyOperator empty = new EmptyOperator(); RightChildReducer rightChildReducer = new RightChildReducer(); previous.Successor = selectionProcessor; selectionProcessor.Operators.Add(selector); selectionProcessor.Operators.Add(empty); selectionProcessor.Successor = rightChildReducer; previous = rightChildReducer; } }
/// <summary> /// Sets how many sub-scopes male and female selectors should select. /// </summary> /// <exception cref="InvalidOperationException">Thrown when <see cref="NumberOfSelectedSubScopesParameter"/> returns an odd number.</exception> /// <returns>Returns Apply of <see cref="AlgorithmOperator"/>.</returns> public override IOperation Apply() { #region set number of selected subscopes int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; int operators = CheckedSelectors.Count(); int numberOfSelected = count / operators; int remaining = count % operators; foreach (var selector in CheckedSelectors) { int numberOfSelectedSubScopes = numberOfSelected; if (remaining > 0) { numberOfSelectedSubScopes++; remaining--; } selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(numberOfSelectedSubScopes); } #endregion #region prepare subscopes as a selector would List <IScope> scopes = new List <IScope>(CurrentScope.SubScopes); CurrentScope.SubScopes.Clear(); IScope remainingScope = new Scope("Remaining"); remainingScope.SubScopes.AddRange(scopes); CurrentScope.SubScopes.Add(remainingScope); IScope selectedScope = new Scope("Selected"); selectedScope.SubScopes.AddRange(new IScope[0]); CurrentScope.SubScopes.Add(selectedScope); #endregion return(base.Apply()); }