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; } }
public override IOperation Apply() { IScope currentScope = ExecutionContext.Scope; Scope localScope = new Scope(); Scope individual = new Scope(); foreach (IVariable var in currentScope.Variables) { individual.Variables.Add(var); // add reference to variable otherwise the analyzer fails (it's looking down the tree) } localScope.SubScopes.Add(individual); currentScope.SubScopes.Add(localScope); int index = currentScope.SubScopes.Count - 1; SubScopesProcessor processor = new SubScopesProcessor(); SubScopesRemover remover = new SubScopesRemover(); remover.RemoveAllSubScopes = false; remover.SubScopeIndexParameter.Value = new IntValue(index); if (index > 0) { EmptyOperator eo = new EmptyOperator(); for (int i = 0; i < index - 1; i++) { processor.Operators.Add(eo); } } VariableCreator variableCreator = new VariableCreator(); variableCreator.CollectedValues.Add(new ValueParameter <IntValue>(loop.IterationsParameter.ActualName, new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter <DoubleValue>(loop.BestLocalQualityParameter.ActualName, new DoubleValue(0))); variableCreator.Successor = loop; processor.Operators.Add(variableCreator); processor.Successor = remover; OperationCollection next = new OperationCollection(base.Apply()); next.Insert(0, ExecutionContext.CreateChildOperation(processor)); return(next); }
public GenderSpecificSelector() : base() { #region Create parameters Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The quality of the solutions.")); Parameters.Add(new ValueLookupParameter <IntValue>("NumberOfSelectedSubScopes", "The number of scopes that should be selected.")); Parameters.Add(new ValueLookupParameter <BoolValue>("CopySelected", "True if the scopes should be copied, false if they should be moved.", new BoolValue(true))); Parameters.Add(new LookupParameter <IRandom>("Random", "The random number generator to use.")); Parameters.Add(new ValueParameter <ISelector>("FemaleSelector", "The selection operator to select the first parent.")); Parameters.Add(new ValueParameter <ISelector>("MaleSelector", "The selection operator to select the second parent.")); CopySelectedParameter.Hidden = true; #endregion #region Create operators Placeholder femaleSelector = new Placeholder(); SubScopesProcessor maleSelection = new SubScopesProcessor(); Placeholder maleSelector = new Placeholder(); EmptyOperator empty = new EmptyOperator(); RightChildReducer rightChildReducer = new RightChildReducer(); SubScopesMixer subScopesMixer = new SubScopesMixer(); femaleSelector.OperatorParameter.ActualName = "FemaleSelector"; maleSelector.OperatorParameter.ActualName = "MaleSelector"; subScopesMixer.Partitions = new IntValue(2); #endregion #region Create operator graph OperatorGraph.InitialOperator = femaleSelector; femaleSelector.Successor = maleSelection; maleSelection.Operators.Add(maleSelector); maleSelection.Operators.Add(empty); maleSelection.Successor = rightChildReducer; rightChildReducer.Successor = subScopesMixer; #endregion Initialize(); }
private IOperation CreatePruningOperation() { var operations = new OperationCollection { Parallel = true }; var range = GetSliceBounds(); var qualities = Quality.Select(x => x.Value).ToArray(); var indices = Enumerable.Range(0, qualities.Length).ToArray(); indices.StableSort((a, b) => qualities[a].CompareTo(qualities[b])); if (!Maximization.Value) { Array.Reverse(indices); } var subscopes = ExecutionContext.Scope.SubScopes; var random = RandomParameter.ActualValue; var empty = new EmptyOperator(); for (int i = 0; i < indices.Length; ++i) { IOperator @operator; if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability) { @operator = PruningOperator; } else { @operator = empty; } var index = indices[i]; var subscope = subscopes[index]; operations.Add(ExecutionContext.CreateChildOperation(@operator, subscope)); } return(operations); }