Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3094


Ignore:
Timestamp:
03/18/10 02:03:30 (15 years ago)
Author:
abeham
Message:

Completed main loop of simulated annealing
Added a ProbabilisticQualityComparator (derived from QualityComparator)
Added an exception in ExponentialDiscreteDoubleValueModifier when startValue, endValue, or both are <= 0.
#923

Location:
trunk/sources
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3/Files.txt

    r3081 r3094  
    88HeuristicLab.Algorithms.TS\3.3:HeuristicLab.Algorithms.TS-3.3.dll
    99HeuristicLab.Algorithms.LS\3.3:HeuristicLab.Algorithms.LS-3.3.dll
     10HeuristicLab.Algorithms.SimulatedAnnealing\3.3:HeuristicLab.Algorithms.SimulatedAnnealing-3.3.dll
    1011HeuristicLab.Analysis\3.3:HeuristicLab.Analysis-3.3.dll
    1112HeuristicLab.Analysis.Views\3.3:HeuristicLab.Analysis.Views-3.3.dll
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs

    r3093 r3094  
    9595      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    9696      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    97       Parameters.Add(new LookupParameter<DoubleValue>("StartTemperature", "The initial temperature."));
    98       Parameters.Add(new LookupParameter<DoubleValue>("EndTemperature", "The end temperature."));
     97      Parameters.Add(new ValueLookupParameter<DoubleValue>("StartTemperature", "The initial temperature."));
     98      Parameters.Add(new ValueLookupParameter<DoubleValue>("EndTemperature", "The end temperature."));
    9999      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed."));
    100100      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     
    109109
    110110      #region Create operators
     111      VariableCreator variableCreator = new VariableCreator();
     112      BestQualityMemorizer initializeBestQuality = new BestQualityMemorizer();
     113      SequentialSubScopesProcessor sssp = new SequentialSubScopesProcessor();
     114      ResultsCollector resultsCollector = new ResultsCollector();
     115      BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();
     116      Placeholder annealingOperator = new Placeholder();
     117      UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor();
     118      Placeholder moveGenerator = new Placeholder();
     119      SequentialSubScopesProcessor moveEvaluationProcessor = new SequentialSubScopesProcessor();
     120      Placeholder moveEvaluator = new Placeholder();
     121      ProbabilisticQualityComparator qualityComparator = new ProbabilisticQualityComparator();
     122      ConditionalBranch improvesQualityBranch = new ConditionalBranch();
     123      Placeholder moveMaker = new Placeholder();
     124      SubScopesRemover subScopesRemover = new SubScopesRemover();
     125      DataTableValuesCollector valuesCollector = new DataTableValuesCollector();
     126      IntCounter iterationsCounter = new IntCounter();
     127      Comparator iterationsComparator = new Comparator();
     128      ConditionalBranch iterationsTermination = new ConditionalBranch();
     129      EmptyOperator finished = new EmptyOperator();
     130
     131      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
     132      variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));
     133      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Temperature", new DoubleValue(double.MaxValue)));
     134
     135      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
     136      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));
     137      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality") { ActualName = "BestQuality" });
     138      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
     139      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Temperature"));
     140
     141      annealingOperator.Name = "Annealing operator (placeholder)";
     142      annealingOperator.OperatorParameter.ActualName = "AnnealingOperator";
     143
     144      moveGenerator.Name = "Move generator (placeholder)";
     145      moveGenerator.OperatorParameter.ActualName = "MoveGenerator";
     146
     147      moveEvaluator.Name = "Move evaluator (placeholder)";
     148      moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator";
     149
     150      qualityComparator.LeftSideParameter.ActualName = "MoveQuality";
     151      qualityComparator.RightSideParameter.ActualName = "Quality";
     152      qualityComparator.ResultParameter.ActualName = "IsBetter";
     153      qualityComparator.DampeningParameter.ActualName = "Temperature";
     154
     155      improvesQualityBranch.ConditionParameter.ActualName = "IsBetter";
     156
     157      moveMaker.Name = "Move maker (placeholder)";
     158      moveMaker.OperatorParameter.ActualName = "MoveMaker";
     159
     160      subScopesRemover.RemoveAllSubScopes = true;
     161
     162      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));
     163      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
     164      valuesCollector.DataTableParameter.ActualName = "Qualities";
     165
     166      iterationsCounter.Name = "Increment Iterations";
     167      iterationsCounter.Increment = new IntValue(1);
     168      iterationsCounter.ValueParameter.ActualName = "Iterations";
     169
     170      iterationsComparator.Name = "Iterations >= MaximumIterations";
     171      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
     172      iterationsComparator.RightSideParameter.ActualName = "MaximumIterations";
     173      iterationsComparator.ResultParameter.ActualName = "IterationsCondition";
     174      iterationsComparator.Comparison.Value = ComparisonType.GreaterOrEqual;
     175
     176      iterationsTermination.Name = "Iterations termination condition";
     177      iterationsTermination.ConditionParameter.ActualName = "IterationsCondition";
     178
     179      finished.Name = "Finished";
    111180      #endregion
    112181
    113182      #region Create operator graph
     183      OperatorGraph.InitialOperator = variableCreator;
     184      variableCreator.Successor = initializeBestQuality;
     185      initializeBestQuality.Successor = sssp;
     186      sssp.Operators.Add(resultsCollector);
     187      sssp.Successor = bestQualityMemorizer;
     188      bestQualityMemorizer.Successor = annealingOperator;
     189      annealingOperator.Successor = mainProcessor;
     190      mainProcessor.Operator = moveGenerator;
     191      mainProcessor.Successor = valuesCollector;
     192      moveGenerator.Successor = moveEvaluationProcessor;
     193      moveEvaluationProcessor.Operators.Add(moveEvaluator);
     194      moveEvaluationProcessor.Successor = subScopesRemover;
     195      moveEvaluator.Successor = qualityComparator;
     196      qualityComparator.Successor = improvesQualityBranch;
     197      improvesQualityBranch.TrueBranch = moveMaker;
     198      valuesCollector.Successor = iterationsCounter;
     199      iterationsCounter.Successor = iterationsComparator;
     200      iterationsComparator.Successor = iterationsTermination;
     201      iterationsTermination.TrueBranch = finished;
     202      iterationsTermination.FalseBranch = bestQualityMemorizer;
    114203      #endregion
    115204    }
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/ExponentialDiscreteDoubleValueModifier.cs

    r3093 r3094  
    3131  [StorableClass]
    3232  public class ExponentialDiscreteDoubleValueModifier : DiscreteDoubleValueModifier {
     33    /// <summary>
     34    /// Calculates a new value based on exponential decay or growth.
     35    /// </summary>
     36    /// <exception cref="ArgumentException">Thrown when endValue or startValue or both are 0.</exception>
     37    /// <param name="value">The last value.</param>
     38    /// <param name="startValue">The start value.</param>
     39    /// <param name="endValue">The end value.</param>
     40    /// <param name="index">The current index.</param>
     41    /// <param name="startIndex">The start index.</param>
     42    /// <param name="endIndex">The end index.</param>
     43    /// <returns>The new value.</returns>
    3344    protected override double Modify(double value, double startValue, double endValue, int index, int startIndex, int endIndex) {
     45      if (endValue <= 0 || startValue <= 0) throw new ArgumentException("ExponentialDiscreteDoubleValueModifier: startValue and endValue must be greater than 0.");
    3446      double b = Math.Pow(endValue / startValue, 1.0 / (endIndex - startIndex));
    3547      return startValue * Math.Pow(b, index - startIndex);
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj

    r3093 r3094  
    8181  </ItemGroup>
    8282  <ItemGroup>
     83    <Compile Include="ProbabilisticQualityComparator.cs" />
    8384    <Compile Include="SquareRootDiscreteDoubleValueModifier.cs" />
    8485    <Compile Include="DiscreteDoubleValueModifier.cs" />
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/QualityComparator.cs

    r3078 r3094  
    5656      DoubleValue right = RightSideParameter.ActualValue;
    5757      BoolValue maximization = MaximizationParameter.ActualValue;
    58       bool better = maximization.Value && left.Value > right.Value
    59         || !maximization.Value && left.Value < right.Value;
     58      bool better = Compare(maximization.Value, left.Value, right.Value);
    6059      if (ResultParameter.ActualValue == null)
    6160        ResultParameter.ActualValue = new BoolValue(better);
     
    6362      return base.Apply();
    6463    }
     64
     65    protected virtual bool Compare(bool maximization, double left, double right) {
     66      return maximization && left > right || !maximization && left < right;
     67    }
    6568  }
    6669}
Note: See TracChangeset for help on using the changeset viewer.