protected QualityComparator(QualityComparator original, Cloner cloner) : base(original, cloner) { }
private void Initialize() { #region Create parameters Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); Parameters.Add(new LookupParameter<IntValue>("Iterations", "The iterations to count.")); Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution.")); Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions.")); Parameters.Add(new ValueLookupParameter<ILocalImprovementOperator>("LocalImprovement", "The local improvement operation.")); Parameters.Add(new ValueLookupParameter<IMultiNeighborhoodShakingOperator>("ShakingOperator", "The shaking operation.")); Parameters.Add(new LookupParameter<IntValue>("CurrentNeighborhoodIndex", "The index of the current shaking operation that should be applied.")); Parameters.Add(new LookupParameter<IntValue>("NeighborhoodCount", "The number of neighborhood operators used for shaking.")); #endregion #region Create operators VariableCreator variableCreator = new VariableCreator(); SubScopesProcessor subScopesProcessor0 = new SubScopesProcessor(); Assigner bestQualityInitializer = new Assigner(); Placeholder analyzer1 = new Placeholder(); ResultsCollector resultsCollector1 = new ResultsCollector(); CombinedOperator iteration = new CombinedOperator(); Assigner iterationInit = new Assigner(); SubScopesCloner createChild = new SubScopesCloner(); SubScopesProcessor childProcessor = new SubScopesProcessor(); Assigner qualityAssigner = new Assigner(); Placeholder shaking = new Placeholder(); Placeholder localImprovement = new Placeholder(); Placeholder evaluator = new Placeholder(); IntCounter evalCounter = new IntCounter(); QualityComparator qualityComparator = new QualityComparator(); ConditionalBranch improvesQualityBranch = new ConditionalBranch(); Assigner bestQualityUpdater = new Assigner(); BestSelector bestSelector = new BestSelector(); RightReducer rightReducer = new RightReducer(); IntCounter indexCounter = new IntCounter(); Assigner indexResetter = new Assigner(); Placeholder analyzer2 = new Placeholder(); Comparator indexComparator = new Comparator(); ConditionalBranch indexTermination = new ConditionalBranch(); IntCounter iterationsCounter = new IntCounter(); Comparator iterationsComparator = new Comparator(); ConditionalBranch iterationsTermination = new ConditionalBranch(); variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("IsBetter", new BoolValue(false))); variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0))); bestQualityInitializer.Name = "Initialize BestQuality"; bestQualityInitializer.LeftSideParameter.ActualName = "BestQuality"; bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name; analyzer1.Name = "Analyzer (placeholder)"; analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; resultsCollector1.CopyValue = new BoolValue(false); resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality")); resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; iteration.Name = "MainLoop Body"; iterationInit.Name = "Init k = 0"; iterationInit.LeftSideParameter.ActualName = CurrentNeighborhoodIndexParameter.Name; iterationInit.RightSideParameter.Value = new IntValue(0); createChild.Name = "Clone solution"; qualityAssigner.Name = "Assign quality"; qualityAssigner.LeftSideParameter.ActualName = "OriginalQuality"; qualityAssigner.RightSideParameter.ActualName = QualityParameter.Name; shaking.Name = "Shaking operator (placeholder)"; shaking.OperatorParameter.ActualName = ShakingOperatorParameter.Name; localImprovement.Name = "Local improvement operator (placeholder)"; localImprovement.OperatorParameter.ActualName = LocalImprovementParameter.Name; evaluator.Name = "Evaluation operator (placeholder)"; evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name; evalCounter.Name = "Count evaluations"; evalCounter.Increment.Value = 1; evalCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.ActualName; qualityComparator.LeftSideParameter.ActualName = QualityParameter.Name; qualityComparator.RightSideParameter.ActualName = "OriginalQuality"; qualityComparator.ResultParameter.ActualName = "IsBetter"; improvesQualityBranch.ConditionParameter.ActualName = "IsBetter"; bestQualityUpdater.Name = "Update BestQuality"; bestQualityUpdater.LeftSideParameter.ActualName = "BestQuality"; bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name; bestSelector.CopySelected = new BoolValue(false); bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; bestSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1); bestSelector.QualityParameter.ActualName = QualityParameter.Name; indexCounter.Name = "Count neighborhood index"; indexCounter.Increment.Value = 1; indexCounter.ValueParameter.ActualName = CurrentNeighborhoodIndexParameter.Name; indexResetter.Name = "Reset neighborhood index"; indexResetter.LeftSideParameter.ActualName = CurrentNeighborhoodIndexParameter.Name; indexResetter.RightSideParameter.Value = new IntValue(0); analyzer2.Name = "Analyzer (placeholder)"; analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name; iterationsCounter.Name = "Iterations Counter"; iterationsCounter.Increment = new IntValue(1); iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name; iterationsComparator.Name = "Iterations >= MaximumIterations"; iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); iterationsComparator.LeftSideParameter.ActualName = IterationsParameter.Name; iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name; iterationsComparator.ResultParameter.ActualName = "Terminate"; iterationsTermination.Name = "Iterations Termination Condition"; iterationsTermination.ConditionParameter.ActualName = "Terminate"; indexComparator.Name = "k < k_max (index condition)"; indexComparator.LeftSideParameter.ActualName = CurrentNeighborhoodIndexParameter.Name; indexComparator.RightSideParameter.ActualName = NeighborhoodCountParameter.Name; indexComparator.Comparison = new Comparison(ComparisonType.Less); indexComparator.ResultParameter.ActualName = "ContinueIteration"; indexTermination.Name = "Index Termination Condition"; indexTermination.ConditionParameter.ActualName = "ContinueIteration"; #endregion #region Create operator graph OperatorGraph.InitialOperator = variableCreator; variableCreator.Successor = subScopesProcessor0; subScopesProcessor0.Operators.Add(bestQualityInitializer); subScopesProcessor0.Successor = analyzer1; analyzer1.Successor = resultsCollector1; ///////// resultsCollector1.Successor = iteration; iteration.OperatorGraph.InitialOperator = iterationInit; iteration.Successor = iterationsCounter; iterationInit.Successor = createChild; createChild.Successor = childProcessor; childProcessor.Operators.Add(new EmptyOperator()); childProcessor.Operators.Add(qualityAssigner); childProcessor.Successor = bestSelector; ///////// qualityAssigner.Successor = shaking; shaking.Successor = evaluator; evaluator.Successor = evalCounter; evalCounter.Successor = localImprovement; localImprovement.Successor = qualityComparator; qualityComparator.Successor = improvesQualityBranch; improvesQualityBranch.TrueBranch = bestQualityUpdater; improvesQualityBranch.FalseBranch = indexCounter; bestQualityUpdater.Successor = indexResetter; indexResetter.Successor = null; indexCounter.Successor = null; ///////// bestSelector.Successor = rightReducer; rightReducer.Successor = analyzer2; analyzer2.Successor = indexComparator; indexComparator.Successor = indexTermination; indexTermination.TrueBranch = createChild; indexTermination.FalseBranch = null; iterationsCounter.Successor = iterationsComparator; iterationsComparator.Successor = iterationsTermination; iterationsTermination.TrueBranch = null; iterationsTermination.FalseBranch = iteration; #endregion }
private void Initialize() { #region Create parameters Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new LookupParameter<DoubleValue>("BestLocalQuality", "The value which represents the best quality found so far.")); Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far.")); Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move.")); Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations performed.")); Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves.")); Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality.")); Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move.")); Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution and moves.")); Parameters.Add(new LookupParameter<IntValue>("EvaluatedMoves", "The number of evaluated moves.")); #endregion #region Create operators SubScopesProcessor subScopesProcessor0 = new SubScopesProcessor(); Assigner bestQualityInitializer = new Assigner(); Placeholder analyzer1 = new Placeholder(); ResultsCollector resultsCollector1 = new ResultsCollector(); SubScopesProcessor mainProcessor = new SubScopesProcessor(); Placeholder moveGenerator = new Placeholder(); UniformSubScopesProcessor moveEvaluationProcessor = new UniformSubScopesProcessor(); Placeholder moveEvaluator = new Placeholder(); SubScopesCounter subScopesCounter = new SubScopesCounter(); BestSelector bestSelector = new BestSelector(); SubScopesProcessor moveMakingProcessor = new SubScopesProcessor(); UniformSubScopesProcessor selectedMoveMakingProcessor = new UniformSubScopesProcessor(); QualityComparator qualityComparator = new QualityComparator(); ConditionalBranch improvesQualityBranch = new ConditionalBranch(); Placeholder moveMaker = new Placeholder(); Assigner bestQualityUpdater = new Assigner(); ResultsCollector resultsCollector2 = new ResultsCollector(); MergingReducer mergingReducer = new MergingReducer(); Placeholder analyzer2 = new Placeholder(); SubScopesRemover subScopesRemover = new SubScopesRemover(); IntCounter iterationsCounter = new IntCounter(); Comparator iterationsComparator = new Comparator(); ConditionalBranch iterationsTermination = new ConditionalBranch(); bestQualityInitializer.Name = "Initialize BestQuality"; bestQualityInitializer.LeftSideParameter.ActualName = BestLocalQualityParameter.Name; bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name; analyzer1.Name = "Analyzer (placeholder)"; analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; resultsCollector1.CopyValue = new BoolValue(false); resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name)); resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name)); resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; moveGenerator.Name = "MoveGenerator (placeholder)"; moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name; moveEvaluationProcessor.Parallel = new BoolValue(true); moveEvaluator.Name = "MoveEvaluator (placeholder)"; moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name; subScopesCounter.Name = "Increment EvaluatedMoves"; subScopesCounter.ValueParameter.ActualName = EvaluatedMovesParameter.Name; bestSelector.CopySelected = new BoolValue(false); bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; bestSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1); bestSelector.QualityParameter.ActualName = MoveQualityParameter.Name; qualityComparator.LeftSideParameter.ActualName = MoveQualityParameter.Name; qualityComparator.RightSideParameter.ActualName = QualityParameter.Name; qualityComparator.ResultParameter.ActualName = "IsBetter"; improvesQualityBranch.ConditionParameter.ActualName = "IsBetter"; moveMaker.Name = "MoveMaker (placeholder)"; moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name; bestQualityUpdater.Name = "Update BestQuality"; bestQualityUpdater.LeftSideParameter.ActualName = BestLocalQualityParameter.Name; bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name; resultsCollector2.CopyValue = new BoolValue(false); resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name)); resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name; analyzer2.Name = "Analyzer (placeholder)"; analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name; subScopesRemover.RemoveAllSubScopes = true; iterationsCounter.Name = "Iterations Counter"; iterationsCounter.Increment = new IntValue(1); iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name; iterationsComparator.Name = "Iterations >= MaximumIterations"; iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); iterationsComparator.LeftSideParameter.ActualName = IterationsParameter.Name; iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name; iterationsComparator.ResultParameter.ActualName = "Terminate"; iterationsTermination.Name = "Iterations Termination Condition"; iterationsTermination.ConditionParameter.ActualName = "Terminate"; #endregion #region Create operator graph OperatorGraph.InitialOperator = subScopesProcessor0; // don't change this without adapting the constructor of LocalSearchImprovementOperator subScopesProcessor0.Operators.Add(bestQualityInitializer); subScopesProcessor0.Successor = resultsCollector1; bestQualityInitializer.Successor = analyzer1; analyzer1.Successor = null; resultsCollector1.Successor = mainProcessor; mainProcessor.Operators.Add(moveGenerator); mainProcessor.Successor = iterationsCounter; moveGenerator.Successor = moveEvaluationProcessor; moveEvaluationProcessor.Operator = moveEvaluator; moveEvaluationProcessor.Successor = subScopesCounter; moveEvaluator.Successor = null; subScopesCounter.Successor = bestSelector; bestSelector.Successor = moveMakingProcessor; moveMakingProcessor.Operators.Add(new EmptyOperator()); moveMakingProcessor.Operators.Add(selectedMoveMakingProcessor); moveMakingProcessor.Successor = mergingReducer; selectedMoveMakingProcessor.Operator = qualityComparator; qualityComparator.Successor = improvesQualityBranch; improvesQualityBranch.TrueBranch = moveMaker; improvesQualityBranch.FalseBranch = null; improvesQualityBranch.Successor = null; moveMaker.Successor = bestQualityUpdater; bestQualityUpdater.Successor = null; mergingReducer.Successor = analyzer2; analyzer2.Successor = subScopesRemover; subScopesRemover.Successor = null; iterationsCounter.Successor = iterationsComparator; iterationsComparator.Successor = iterationsTermination; iterationsTermination.TrueBranch = null; iterationsTermination.FalseBranch = mainProcessor; #endregion }