public QualityAnalyzer()
      : base() {
      #region Create parameters
      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
      Parameters.Add(new ScopeTreeLookupParameter<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<DoubleValue>("BestQuality", "The best quality value found in the current run."));
      Parameters.Add(new ValueLookupParameter<DataTable>("Qualities", "The data table to store the current best, current average, current worst, best and best known quality value."));
      Parameters.Add(new ValueLookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value."));
      Parameters.Add(new ValueLookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", "The relative difference of the best known quality value to the best quality value."));
      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
      #endregion

      #region Create operators
      BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();
      BestQualityMemorizer bestKnownQualityMemorizer = new BestQualityMemorizer();
      DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
      QualityDifferenceCalculator qualityDifferenceCalculator = new QualityDifferenceCalculator();
      ResultsCollector resultsCollector = new ResultsCollector();

      bestQualityMemorizer.BestQualityParameter.ActualName = BestQualityParameter.Name;
      bestQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;
      bestQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
      bestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;

      bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
      bestKnownQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;
      bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
      bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;

      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality", null, BestQualityParameter.Name));
      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestKnownQuality", null, BestKnownQualityParameter.Name));
      dataTableValuesCollector.CollectedValues.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", null, QualityParameter.Name));
      ((ScopeTreeLookupParameter<DoubleValue>)dataTableValuesCollector.CollectedValues["Quality"]).Depth = QualityParameter.Depth;
      dataTableValuesCollector.DataTableParameter.ActualName = QualitiesParameter.Name;

      qualityDifferenceCalculator.AbsoluteDifferenceParameter.ActualName = AbsoluteDifferenceBestKnownToBestParameter.Name;
      qualityDifferenceCalculator.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
      qualityDifferenceCalculator.RelativeDifferenceParameter.ActualName = RelativeDifferenceBestKnownToBestParameter.Name;
      qualityDifferenceCalculator.SecondQualityParameter.ActualName = BestQualityParameter.Name;

      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality", null, BestQualityParameter.Name));
      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestKnownQuality", null, BestKnownQualityParameter.Name));
      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", null, QualityParameter.Name));
      ((ScopeTreeLookupParameter<DoubleValue>)resultsCollector.CollectedValues["Quality"]).Depth = QualityParameter.Depth;
      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", null, AbsoluteDifferenceBestKnownToBestParameter.Name));
      resultsCollector.CollectedValues.Add(new LookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", null, RelativeDifferenceBestKnownToBestParameter.Name));
      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(QualitiesParameter.Name));
      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
      #endregion

      #region Create operator graph
      OperatorGraph.InitialOperator = bestQualityMemorizer;
      bestQualityMemorizer.Successor = bestKnownQualityMemorizer;
      bestKnownQualityMemorizer.Successor = dataTableValuesCollector;
      dataTableValuesCollector.Successor = qualityDifferenceCalculator;
      qualityDifferenceCalculator.Successor = resultsCollector;
      resultsCollector.Successor = null;
      #endregion

      Initialize();
    }
Exemple #2
0
 protected BestQualityMemorizer(BestQualityMemorizer original, Cloner cloner) : base(original, cloner)
 {
 }
        public QualityAnalyzer()
            : base()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <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 <DoubleValue>("BestQuality", "The best quality value found in the current run."));
            Parameters.Add(new ValueLookupParameter <DataTable>("Qualities", "The data table to store the current best, current average, current worst, best and best known quality value."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("RelativeDifferenceBestKnownToBest", "The relative difference of the best known quality value to the best quality value."));
            Parameters.Add(new ValueLookupParameter <VariableCollection>("Results", "The results collection where the analysis values should be stored."));
            #endregion

            #region Create operators
            BestQualityMemorizer        bestQualityMemorizer        = new BestQualityMemorizer();
            BestQualityMemorizer        bestKnownQualityMemorizer   = new BestQualityMemorizer();
            DataTableValuesCollector    dataTableValuesCollector    = new DataTableValuesCollector();
            QualityDifferenceCalculator qualityDifferenceCalculator = new QualityDifferenceCalculator();
            ResultsCollector            resultsCollector            = new ResultsCollector();

            bestQualityMemorizer.BestQualityParameter.ActualName  = BestQualityParameter.Name;
            bestQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestQualityMemorizer.QualityParameter.ActualName      = QualityParameter.Name;
            bestQualityMemorizer.QualityParameter.Depth           = QualityParameter.Depth;

            bestKnownQualityMemorizer.BestQualityParameter.ActualName  = BestKnownQualityParameter.Name;
            bestKnownQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestKnownQualityMemorizer.QualityParameter.ActualName      = QualityParameter.Name;
            bestKnownQualityMemorizer.QualityParameter.Depth           = QualityParameter.Depth;

            dataTableValuesCollector.CollectedValues.Add(new LookupParameter <DoubleValue>("BestQuality", null, BestQualityParameter.Name));
            dataTableValuesCollector.CollectedValues.Add(new LookupParameter <DoubleValue>("BestKnownQuality", null, BestKnownQualityParameter.Name));
            dataTableValuesCollector.CollectedValues.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", null, QualityParameter.Name));
            ((ScopeTreeLookupParameter <DoubleValue>)dataTableValuesCollector.CollectedValues["Quality"]).Depth = QualityParameter.Depth;
            dataTableValuesCollector.DataTableParameter.ActualName = QualitiesParameter.Name;

            qualityDifferenceCalculator.AbsoluteDifferenceParameter.ActualName = AbsoluteDifferenceBestKnownToBestParameter.Name;
            qualityDifferenceCalculator.FirstQualityParameter.ActualName       = BestKnownQualityParameter.Name;
            qualityDifferenceCalculator.RelativeDifferenceParameter.ActualName = RelativeDifferenceBestKnownToBestParameter.Name;
            qualityDifferenceCalculator.SecondQualityParameter.ActualName      = BestQualityParameter.Name;

            resultsCollector.CollectedValues.Add(new LookupParameter <DoubleValue>("BestQuality", null, BestQualityParameter.Name));
            resultsCollector.CollectedValues.Add(new LookupParameter <DoubleValue>("BestKnownQuality", null, BestKnownQualityParameter.Name));
            resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", null, QualityParameter.Name));
            ((ScopeTreeLookupParameter <DoubleValue>)resultsCollector.CollectedValues["Quality"]).Depth = QualityParameter.Depth;
            resultsCollector.CollectedValues.Add(new LookupParameter <DoubleValue>("AbsoluteDifferenceBestKnownToBest", null, AbsoluteDifferenceBestKnownToBestParameter.Name));
            resultsCollector.CollectedValues.Add(new LookupParameter <PercentValue>("RelativeDifferenceBestKnownToBest", null, RelativeDifferenceBestKnownToBestParameter.Name));
            resultsCollector.CollectedValues.Add(new LookupParameter <DataTable>(QualitiesParameter.Name));
            resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator         = bestQualityMemorizer;
            bestQualityMemorizer.Successor        = bestKnownQualityMemorizer;
            bestKnownQualityMemorizer.Successor   = dataTableValuesCollector;
            dataTableValuesCollector.Successor    = qualityDifferenceCalculator;
            qualityDifferenceCalculator.Successor = resultsCollector;
            resultsCollector.Successor            = null;
            #endregion

            Initialize();
        }
 protected BestQualityMemorizer(BestQualityMemorizer 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 LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The value that indicates if a move is tabu or not."));
      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));

      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>("TabuChecker", "The operator that checks whether a move is tabu."));
      Parameters.Add(new ValueLookupParameter<IOperator>("TabuMaker", "The operator that declares a move tabu."));

      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution and moves."));
      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
      Parameters.Add(new LookupParameter<IntValue>("EvaluatedMoves", "The number of evaluated moves."));
      #endregion

      #region Create operators
      VariableCreator variableCreator = new VariableCreator();
      SubScopesProcessor subScopesProcessor0 = new SubScopesProcessor();
      Assigner bestQualityInitializer = new Assigner();
      Placeholder analyzer1 = new Placeholder();
      ResultsCollector resultsCollector1 = new ResultsCollector();
      SubScopesProcessor solutionProcessor = new SubScopesProcessor();
      Placeholder moveGenerator = new Placeholder();
      UniformSubScopesProcessor moveEvaluationProcessor = new UniformSubScopesProcessor();
      Placeholder moveEvaluator = new Placeholder();
      Placeholder tabuChecker = new Placeholder();
      SubScopesCounter subScopesCounter = new SubScopesCounter();
      SubScopesSorter moveQualitySorter = new SubScopesSorter();
      TabuSelector tabuSelector = new TabuSelector();
      ConditionalBranch emptyNeighborhoodBranch1 = new ConditionalBranch();
      SubScopesProcessor moveMakingProcessor = new SubScopesProcessor();
      UniformSubScopesProcessor selectedMoveMakingProcesor = new UniformSubScopesProcessor();
      Placeholder tabuMaker = new Placeholder();
      Placeholder moveMaker = new Placeholder();
      MergingReducer mergingReducer = new MergingReducer();
      Placeholder analyzer2 = new Placeholder();
      SubScopesRemover subScopesRemover = new SubScopesRemover();
      ConditionalBranch emptyNeighborhoodBranch2 = new ConditionalBranch();
      BestQualityMemorizer bestQualityUpdater = new BestQualityMemorizer();
      IntCounter iterationsCounter = new IntCounter();
      Comparator iterationsComparator = new Comparator();
      ConditionalBranch iterationsTermination = new ConditionalBranch();

      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); // Class TabuSearch expects this to be called Iterations
      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("EmptyNeighborhood", new BoolValue(false)));
      variableCreator.CollectedValues.Add(new ValueParameter<ItemList<IItem>>("TabuList", new ItemList<IItem>()));
      variableCreator.CollectedValues.Add(new ValueParameter<VariableCollection>("Memories", new VariableCollection()));
      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<IntValue>("Iterations"));
      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
      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;

      tabuChecker.Name = "TabuChecker (placeholder)";
      tabuChecker.OperatorParameter.ActualName = TabuCheckerParameter.Name;

      subScopesCounter.Name = "Increment EvaluatedMoves";
      subScopesCounter.ValueParameter.ActualName = EvaluatedMovesParameter.Name;

      moveQualitySorter.DescendingParameter.ActualName = MaximizationParameter.Name;
      moveQualitySorter.ValueParameter.ActualName = MoveQualityParameter.Name;

      tabuSelector.AspirationParameter.Value = new BoolValue(true);
      tabuSelector.BestQualityParameter.ActualName = "BestQuality";
      tabuSelector.CopySelected = new BoolValue(false);
      tabuSelector.EmptyNeighborhoodParameter.ActualName = "EmptyNeighborhood";
      tabuSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
      tabuSelector.MoveQualityParameter.ActualName = MoveQualityParameter.Name;
      tabuSelector.MoveTabuParameter.ActualName = MoveTabuParameter.Name;

      moveMakingProcessor.Name = "MoveMaking processor (UniformSubScopesProcessor)";

      emptyNeighborhoodBranch1.Name = "Neighborhood empty?";
      emptyNeighborhoodBranch1.ConditionParameter.ActualName = "EmptyNeighborhood";

      tabuMaker.Name = "TabuMaker (placeholder)";
      tabuMaker.OperatorParameter.ActualName = TabuMakerParameter.Name;

      moveMaker.Name = "MoveMaker (placeholder)";
      moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name;

      analyzer2.Name = "Analyzer (placeholder)";
      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

      subScopesRemover.RemoveAllSubScopes = true;

      bestQualityUpdater.Name = "Update BestQuality";
      bestQualityUpdater.MaximizationParameter.ActualName = MaximizationParameter.Name;
      bestQualityUpdater.QualityParameter.ActualName = QualityParameter.Name;
      bestQualityUpdater.BestQualityParameter.ActualName = "BestQuality";

      iterationsCounter.Name = "Iterations Counter";
      iterationsCounter.Increment = new IntValue(1);
      iterationsCounter.ValueParameter.ActualName = "Iterations";

      iterationsComparator.Name = "Iterations >= MaximumIterations";
      iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
      iterationsComparator.ResultParameter.ActualName = "Terminate";

      emptyNeighborhoodBranch2.Name = "Neighborhood empty?";
      emptyNeighborhoodBranch2.ConditionParameter.ActualName = "EmptyNeighborhood";

      iterationsTermination.Name = "Iterations Termination Condition";
      iterationsTermination.ConditionParameter.ActualName = "Terminate";
      #endregion

      #region Create operator graph
      OperatorGraph.InitialOperator = variableCreator;
      variableCreator.Successor = subScopesProcessor0;
      subScopesProcessor0.Operators.Add(bestQualityInitializer);
      subScopesProcessor0.Successor = resultsCollector1;
      bestQualityInitializer.Successor = analyzer1;
      analyzer1.Successor = null;
      resultsCollector1.Successor = solutionProcessor;
      solutionProcessor.Operators.Add(moveGenerator);
      solutionProcessor.Successor = iterationsCounter;
      moveGenerator.Successor = moveEvaluationProcessor;
      moveEvaluationProcessor.Operator = moveEvaluator;
      moveEvaluationProcessor.Successor = subScopesCounter;
      moveEvaluator.Successor = tabuChecker;
      tabuChecker.Successor = null;
      subScopesCounter.Successor = moveQualitySorter;
      moveQualitySorter.Successor = tabuSelector;
      tabuSelector.Successor = emptyNeighborhoodBranch1;
      emptyNeighborhoodBranch1.FalseBranch = moveMakingProcessor;
      emptyNeighborhoodBranch1.TrueBranch = null;
      emptyNeighborhoodBranch1.Successor = subScopesRemover;
      moveMakingProcessor.Operators.Add(new EmptyOperator());
      moveMakingProcessor.Operators.Add(selectedMoveMakingProcesor);
      moveMakingProcessor.Successor = mergingReducer;
      selectedMoveMakingProcesor.Operator = tabuMaker;
      selectedMoveMakingProcesor.Successor = null;
      tabuMaker.Successor = moveMaker;
      moveMaker.Successor = null;
      mergingReducer.Successor = analyzer2;
      analyzer2.Successor = null;
      subScopesRemover.Successor = null;
      iterationsCounter.Successor = iterationsComparator;
      iterationsComparator.Successor = emptyNeighborhoodBranch2;
      emptyNeighborhoodBranch2.TrueBranch = null;
      emptyNeighborhoodBranch2.FalseBranch = iterationsTermination;
      emptyNeighborhoodBranch2.Successor = null;
      iterationsTermination.TrueBranch = null;
      iterationsTermination.FalseBranch = solutionProcessor;
      #endregion
    }