Changeset 8319 for branches/ScatterSearch (trunk integration)
- Timestamp:
- 07/24/12 15:04:37 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 7 added
- 2 deleted
- 32 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/HeuristicLab.Algorithms.ScatterSearch-3.3.csproj
r8306 r8319 85 85 </ItemGroup> 86 86 <ItemGroup> 87 <Compile Include="IScatterSearchOperator.cs" />88 87 <Compile Include="OffspringProcessor.cs" /> 89 88 <None Include="HeuristicLab.snk" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/OffspringProcessor.cs
r8086 r8319 32 32 [Item("OffspringProcessor", "An operator that creates a subscope with subscopes for every variable in the current scope.")] 33 33 [StorableClass] 34 public sealed class OffspringProcessor : SingleSuccessorOperator , IScatterSearchOperator{34 public sealed class OffspringProcessor : SingleSuccessorOperator { 35 35 #region Parameter properties 36 36 public ScopeParameter CurrentScopeParameter { 37 37 get { return (ScopeParameter)Parameters["CurrentScope"]; } 38 }39 public IValueLookupParameter<IItem> TargetParameter {40 get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }41 38 } 42 39 #endregion … … 45 42 private IScope CurrentScope { 46 43 get { return CurrentScopeParameter.ActualValue; } 47 }48 private IItem Target {49 get { return TargetParameter.ActualValue; }50 44 } 51 45 #endregion … … 58 52 #region Create parameters 59 53 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the offspring as variables.")); 60 Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));61 54 #endregion 62 55 } … … 67 60 68 61 public override IOperation Apply() { 69 VariableCollection offspringSolutions = CurrentScope.Variables; 70 IScope offspringScope = new Scope("Offspring"); 71 foreach (var solution in offspringSolutions) { 72 IScope scope = new Scope(); 73 scope.Variables.Add(new Variable(TargetParameter.ActualName, solution.Value)); 74 offspringScope.SubScopes.Add(scope); 75 } 62 var child = new Scope(); 63 child.Variables.AddRange(CurrentScope.Variables); 64 var offspringScope = new Scope(); 65 offspringScope.SubScopes.Add(child); 66 var parents = CurrentScope.SubScopes.ToArray(); 67 CurrentScope.Variables.Clear(); 68 CurrentScope.SubScopes.Clear(); 69 CurrentScope.SubScopes.AddRange(parents); 76 70 CurrentScope.SubScopes.Add(offspringScope); 77 CurrentScope.Variables.Clear();78 71 return base.Apply(); 79 72 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs
r8086 r8319 34 34 [Item("PopulationRebuildMethod", "An operator that updates the reference set and rebuilds the population.")] 35 35 [StorableClass] 36 public sealed class PopulationRebuildMethod : SingleSuccessorOperator , IScatterSearchOperator{36 public sealed class PopulationRebuildMethod : SingleSuccessorOperator { 37 37 #region Parameter properties 38 38 public ScopeParameter CurrentScopeParameter { -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r8304 r8319 39 39 public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator { 40 40 #region ISimilarityBasedOperator Members 41 public IS imilarityCalculator SimilarityCalculator { get; set; }41 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 42 42 #endregion 43 43 … … 76 76 77 77 public override IOperation Apply() { 78 IDictionary<IScope, double> population = new Dictionary<IScope, double>(); 79 foreach (var pScope in CurrentScope.SubScopes[0].SubScopes) { 80 double similarity = 0; 81 foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) { 82 similarity += SimilarityCalculator.CalculateIndividualSimilarity(pScope, rScope); 83 } 84 population[pScope] = similarity; 78 var populationSimilarity = new Dictionary<IScope, double>(); 79 var populationScope = CurrentScope.SubScopes[0]; 80 var refSetScope = CurrentScope.SubScopes[1]; 81 var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(populationScope, refSetScope); 82 for (int i = 0; i < populationScope.SubScopes.Count; i++) { 83 populationSimilarity[populationScope.SubScopes[i]] = similarityMatrix[i].Sum(); 85 84 } 86 85 int numberOfHighQualitySolutions = CurrentScope.SubScopes[1].SubScopes.Count; 87 foreach (var entry in population .OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) {86 foreach (var entry in populationSimilarity.OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) { 88 87 CurrentScope.SubScopes[1].SubScopes.Add(entry.Key); 89 88 CurrentScope.SubScopes[0].SubScopes.Remove(entry.Key); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs
r8299 r8319 22 22 using System; 23 23 using System.Linq; 24 using System.Reflection;25 24 using HeuristicLab.Analysis; 26 25 using HeuristicLab.Common; … … 89 88 get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; } 90 89 } 91 public ConstrainedValueParameter<IS imilarityCalculator> SimilarityCalculatorParameter {92 get { return (ConstrainedValueParameter<IS imilarityCalculator>)Parameters["SimilarityCalculator"]; }90 public ConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 91 get { return (ConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 93 92 } 94 93 #endregion … … 139 138 set { SetSeedRandomlyParameter.Value = value; } 140 139 } 141 private IS imilarityCalculator SimilarityCalculator {140 private ISolutionSimilarityCalculator SimilarityCalculator { 142 141 get { return SimilarityCalculatorParameter.Value; } 143 142 set { SimilarityCalculatorParameter.Value = value; } … … 185 184 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 186 185 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 187 Parameters.Add(new ConstrainedValueParameter<IS imilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));186 Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.")); 188 187 #endregion 189 188 … … 382 381 } 383 382 private void UpdateSimilarityCalculators() { 384 IS imilarityCalculator oldDiversityCalculator = SimilarityCalculatorParameter.Value;383 ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value; 385 384 SimilarityCalculatorParameter.ValidValues.Clear(); 386 IS imilarityCalculator defaultDiversityCalculator = Problem.Operators.OfType<ISimilarityCalculator>().FirstOrDefault();387 388 foreach (IS imilarityCalculator diversityCalculator in Problem.Operators.OfType<ISimilarityCalculator>())389 SimilarityCalculatorParameter.ValidValues.Add( diversityCalculator);390 391 if (old DiversityCalculator != null) {392 IS imilarityCalculator diversityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDiversityCalculator.GetType());393 if ( diversityCalculator != null) SimilarityCalculatorParameter.Value = diversityCalculator;394 else old DiversityCalculator = null;395 } 396 if (old DiversityCalculator == null && defaultDiversityCalculator != null)397 SimilarityCalculatorParameter.Value = default DiversityCalculator;385 ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault(); 386 387 foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>()) 388 SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator); 389 390 if (oldSimilarityCalculator != null) { 391 ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType()); 392 if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator; 393 else oldSimilarityCalculator = null; 394 } 395 if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null) 396 SimilarityCalculatorParameter.Value = defaultSimilarityCalculator; 398 397 } 399 398 private void ParameterizeBestSelector() { … … 410 409 MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 411 410 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 412 MainLoop.TargetParameter.ActualName = Improver.TargetParameter.ActualName; 413 foreach (var op in MainLoop.OperatorGraph.Operators.OfType<IScatterSearchOperator>()) { 414 // parameter should be accessed direclty (using an interface definition) 415 PropertyInfo propInfo = op.GetType().GetProperty(MainLoop.TargetParameter.Name + "Parameter"); 416 if (propInfo != null && propInfo.CanRead) 417 (propInfo.GetValue(op, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.TargetParameter.ActualName; 418 propInfo = op.GetType().GetProperty(MainLoop.QualityParameter.Name + "Parameter"); 419 if (propInfo != null && propInfo.CanRead) 420 (propInfo.GetValue(op, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.QualityParameter.ActualName; 421 } 411 MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 412 MainLoop.OperatorGraph.Operators.OfType<SolutionPoolUpdateMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 422 413 foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>()) 423 414 op.SimilarityCalculator = SimilarityCalculator; -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs
r8086 r8319 89 89 get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; } 90 90 } 91 public IValueLookupParameter<ISimilarityCalculator> SimilarityCalculatorParameter { 92 get { return (IValueLookupParameter<ISimilarityCalculator>)Parameters["SimilarityCalculator"]; } 93 } 94 public IValueLookupParameter<IItem> TargetParameter { 95 get { return (IValueLookupParameter<IItem>)Parameters["Target"]; } 91 public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 92 get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 96 93 } 97 94 #endregion … … 166 163 set { ResultsParameter.ActualValue = value; } 167 164 } 168 private IS imilarityCalculator SimilarityCalculator {165 private ISolutionSimilarityCalculator SimilarityCalculator { 169 166 get { return SimilarityCalculatorParameter.ActualValue; } 170 167 set { SimilarityCalculatorParameter.ActualValue = value; } 171 }172 private IItem Target {173 get { return TargetParameter.ActualValue; }174 set { TargetParameter.ActualValue = value; }175 168 } 176 169 #endregion … … 204 197 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 205 198 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 206 Parameters.Add(new ValueLookupParameter<ISimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.")); 207 Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only.")); 199 Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.")); 208 200 #endregion 209 201 … … 298 290 pathRelinker.Name = "PathRelinker"; 299 291 pathRelinker.OperatorParameter.ActualName = PathRelinkerParameter.Name; 300 pathRelinker.Successor = offspringProcessor;292 pathRelinker.Successor = rightSelector; 301 293 302 294 crossover.Name = "Crossover"; … … 304 296 crossover.Successor = offspringProcessor; 305 297 306 offspringProcessor.TargetParameter.ActualName = TargetParameter.ActualName;307 298 offspringProcessor.Successor = rightSelector; 308 299 -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r8304 r8319 28 28 using HeuristicLab.Operators; 29 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Optimization.Operators;31 30 using HeuristicLab.Parameters; 32 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 38 37 [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")] 39 38 [StorableClass] 40 public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, IS catterSearchOperator, ISimilarityBasedOperator {39 public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator { 41 40 #region ISimilarityBasedOperator Members 42 public IS imilarityCalculator SimilarityCalculator { get; set; }41 public ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 43 42 #endregion 44 43 … … 130 129 if (orderedOffspring.Any(hasBetterQuality)) { 131 130 // produce the set union 132 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.Calculate IndividualSimilarity));131 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.CalculateSolutionSimilarity)); 133 132 if (union.Count() > orderedParents.Count()) { 134 133 var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) : … … 142 141 } 143 142 143 // derive SingleObjectiveSolutionSimilarityCalculator from EqualityComparer 144 // delete this ... 144 145 public class SolutionEqualityComparer<T> : EqualityComparer<T> { 145 146 private readonly Func<T, T, double> similarityCalculator; -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj
r8086 r8319 109 109 </ItemGroup> 110 110 <ItemGroup> 111 <Compile Include="SingleObjectiveSolutionSimilarityCalculator.cs" /> 111 112 <Compile Include="GeneralizedExponentialDiscreteDoubleValueModifier.cs" /> 112 113 <Compile Include="MultiObjective\CrowdedComparisonSorter.cs" /> … … 115 116 <Compile Include="MultiObjective\FastNonDominatedSort.cs" /> 116 117 <Compile Include="MultiObjective\RankAndCrowdingSorter.cs" /> 117 <Compile Include=" PathRelinker.cs" />118 <Compile Include="SingleObjectivePathRelinker.cs" /> 118 119 <Compile Include="Plugin.cs" /> 119 120 <Compile Include="ShakingOperator.cs" /> 120 <Compile Include="S imilarityCalculator.cs" />121 <Compile Include="SolutionSimilarityCalculator.cs" /> 121 122 <Compile Include="UserDefinedCrossover.cs" /> 122 123 <Compile Include="UserDefinedEvaluator.cs" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs
r8316 r8319 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Common; … … 32 33 [Item("SimilarityCalculator", "A base class for items that perform similarity calculation between two solutions.")] 33 34 [StorableClass] 34 public abstract class SimilarityCalculator : Item, ISimilarityCalculator { 35 #region Properties 36 [Storable] 37 private string target; 38 public string Target { 39 get { return target; } 40 set { target = value; } 41 } 42 #endregion 35 public abstract class SolutionSimilarityCalculator : Item, ISolutionSimilarityCalculator, IEqualityComparer<IScope> { 36 [StorableConstructor] 37 protected SolutionSimilarityCalculator(bool deserializing) : base(deserializing) { } 38 protected SolutionSimilarityCalculator(SolutionSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 39 protected SolutionSimilarityCalculator() : base() { } 43 40 44 [StorableConstructor] 45 protected SimilarityCalculator(bool deserializing) : base(deserializing) { } 46 protected SimilarityCalculator(SimilarityCalculator original, Cloner cloner) 47 : base(original, cloner) { 48 if (original.Target != null) 49 this.target = (string)original.Target.Clone(); 50 } 51 protected SimilarityCalculator() : base() { } 52 53 public double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd) { 54 if (leftCrowd == null || rightCrowd == null) 41 public double[][] CalculateSolutionCrowdSimilarity(IScope leftSolutionCrowd, IScope rightSolutionCrowd) { 42 if (leftSolutionCrowd == null || rightSolutionCrowd == null) 55 43 throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are null."); 56 44 57 var leftIndividuals = left Crowd.SubScopes;58 var rightIndividuals = right Crowd.SubScopes;45 var leftIndividuals = leftSolutionCrowd.SubScopes; 46 var rightIndividuals = rightSolutionCrowd.SubScopes; 59 47 60 48 if (!leftIndividuals.Any() || !rightIndividuals.Any()) … … 65 53 similarityMatrix[i] = new double[rightIndividuals.Count]; 66 54 for (int j = 0; j < rightIndividuals.Count; j++) { 67 similarityMatrix[i][j] = Calculate IndividualSimilarity(leftIndividuals[i], rightIndividuals[j]);55 similarityMatrix[i][j] = CalculateSolutionSimilarity(leftIndividuals[i], rightIndividuals[j]); 68 56 } 69 57 } … … 72 60 } 73 61 74 public abstract double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual); 62 public double[][] CalculateSolutionCrowdSimilarity(IScope solutionCrowd) { 63 if (solutionCrowd == null) 64 throw new ArgumentException("Cannot calculate similarity because the provided crowd is null."); 65 66 var individuals = solutionCrowd.SubScopes; 67 68 if (!individuals.Any()) 69 throw new ArgumentException("Cannot calculate similarity because the provided crowd is empty."); 70 71 var similarityMatrix = new double[individuals.Count][]; 72 for (int i = 0; i < individuals.Count; i++) { 73 similarityMatrix[i] = new double[individuals.Count]; 74 for (int j = i; j < individuals.Count; j++) { 75 similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 76 } 77 } 78 79 return similarityMatrix; 80 } 81 82 public bool Equals(IScope x, IScope y) { 83 if (object.ReferenceEquals(x, y)) return true; 84 if (x == null || y == null) return false; 85 return CalculateSolutionSimilarity(x, y) == 1.0; 86 } 87 88 public abstract double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution); 89 public abstract int GetHashCode(IScope obj); 75 90 } 76 91 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj
r8086 r8319 142 142 <DependentUpon>ExperimentListView.cs</DependentUpon> 143 143 </Compile> 144 <Compile Include="ISimilarityCalculatorView.cs"> 145 <SubType>UserControl</SubType> 146 </Compile> 147 <Compile Include="ISimilarityCalculatorView.Designer.cs"> 148 <DependentUpon>ISimilarityCalculatorView.cs</DependentUpon> 149 </Compile> 144 150 <Compile Include="Plugin.cs" /> 145 151 <Compile Include="ProblemView.cs"> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r8086 r8319 114 114 </ItemGroup> 115 115 <ItemGroup> 116 <Compile Include="Interfaces\ISingleObjectivePathRelinker.cs" /> 117 <Compile Include="Interfaces\ISingleObjectiveImprovementOperator.cs" /> 118 <Compile Include="Interfaces\ISingleObjectiveSolutionSimilarityCalculator.cs" /> 116 119 <Compile Include="Interfaces\IImprovementOperator.cs" /> 117 120 <Compile Include="Interfaces\IPathRelinker.cs" /> 118 121 <Compile Include="Interfaces\ISimilarityBasedOperator.cs" /> 119 <Compile Include="Interfaces\IS imilarityCalculator.cs" />122 <Compile Include="Interfaces\ISolutionSimilarityCalculator.cs" /> 120 123 <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" /> 121 124 <Compile Include="Plugin.cs" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/IImprovementOperator.cs
r8086 r8319 27 27 /// </summary> 28 28 public interface IImprovementOperator : IOperator { 29 IValueLookupParameter<IItem> TargetParameter { get; }30 29 } 31 30 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/IPathRelinker.cs
r8086 r8319 27 27 /// </summary> 28 28 public interface IPathRelinker : IOperator { 29 ILookupParameter<ItemArray<IItem>> ParentsParameter { get; }30 29 } 31 30 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityBasedOperator.cs
r8171 r8319 24 24 namespace HeuristicLab.Optimization { 25 25 public interface ISimilarityBasedOperator : IOperator { 26 IS imilarityCalculator SimilarityCalculator { get; set; }26 ISolutionSimilarityCalculator SimilarityCalculator { get; set; } 27 27 } 28 28 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/ISolutionSimilarityCalculator.cs
r8316 r8319 26 26 /// An interface which represents an operator for similarity calculation. 27 27 /// </summary> 28 public interface ISimilarityCalculator : IItem { 29 string Target { get; set; } 28 public interface ISolutionSimilarityCalculator : IItem { 29 /// <summary> 30 /// Calculates the similarity of two solutions. 31 /// </summary> 32 /// <param name="leftSolution">The first scope that contains a solution.</param> 33 /// <param name="rightSolution">The second scope that contains a solution.</param> 34 /// <returns>A double between zero and one. Zero means the two solutions differ in every aspect, one indicates that the two solutions are the same.</returns> 35 double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution); 30 36 31 double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual); 32 double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd); 37 /// <summary> 38 /// Calculates the similarity of solutions in one scope. 39 /// </summary> 40 /// <param name="solutionCrowd">The scope that contains solutions.</param> 41 /// <returns>A similarity matrix. Zero means the two solutions differ in every aspect, one indicates that the two solutions are the same.</returns> 42 double[][] CalculateSolutionCrowdSimilarity(IScope solutionCrowd); 43 44 /// <summary> 45 /// Calculates the similarity of solutions in two scopes. 46 /// </summary> 47 /// <param name="leftSolutionCrowd">The first scope that contains solutions.</param> 48 /// <param name="rightSolutionCrowd">The second scope that contains solutions.</param> 49 /// <returns>A similarity matrix. Zero means the two solutions differ in every aspect, one indicates that the two solutions are the same.</returns> 50 double[][] CalculateSolutionCrowdSimilarity(IScope leftSolutionCrowd, IScope rightSolutionCrowd); 33 51 } 34 52 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/Improvers/KnapsackImprovementOperator.cs
r8086 r8319 35 35 /// An operator that improves knapsack solutions. 36 36 /// </summary> 37 /// <remarks> 38 /// It is implemented as described in Laguna, M. and Martí, R. (2003). Scatter Search: Methodology and Implementations in C. Operations Research/Computer Science Interfaces Series, Vol. 24. Springer.<br /> 39 /// The operator first orders the elements of the knapsack according to their value-to-weight ratio, then, if the solution is not feasible, removes the element with the lowest ratio until the solution is feasible and tries to add new elements with the best ratio that are not already included yet until the knapsack is full. 40 /// </remarks> 37 41 [Item("KnapsackImprovementOperator", "An operator that improves knapsack solutions.")] 38 42 [StorableClass] 39 public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, I ImprovementOperator {43 public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator { 40 44 #region Parameter properties 41 45 public ScopeParameter CurrentScopeParameter { … … 48 52 get { return (ILookupParameter<DoubleValue>)Parameters["Penalty"]; } 49 53 } 50 public IValueLookupParameter<IItem> TargetParameter {51 get { return (IValueLookupParameter<IItem>)Parameters[" Target"]; }54 public IValueLookupParameter<IItem> SolutionParameter { 55 get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; } 52 56 } 53 57 public ILookupParameter<IntArray> ValuesParameter { … … 90 94 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); 91 95 Parameters.Add(new LookupParameter<DoubleValue>("Penalty", "The penalty value for each unit of overweight.")); 92 Parameters.Add(new ValueLookupParameter<IItem>(" Target", "This parameter is used for name translation only."));96 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 93 97 Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items.")); 94 98 Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items.")); … … 101 105 102 106 public override IOperation Apply() { 103 BinaryVector sol = CurrentScope.Variables[ TargetParameter.ActualName].Value as BinaryVector;107 BinaryVector sol = CurrentScope.Variables[SolutionParameter.ActualName].Value as BinaryVector; 104 108 if (sol == null) 105 109 throw new ArgumentException("Cannot improve solution because it has the wrong type."); … … 143 147 } 144 148 145 CurrentScope.Variables[ TargetParameter.ActualName].Value = sol;149 CurrentScope.Variables[SolutionParameter.ActualName].Value = sol; 146 150 CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions))); 147 151 -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r8086 r8319 291 291 op.ValuesParameter.Hidden = true; 292 292 } 293 foreach ( var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) {293 foreach (IBinaryVectorMultiNeighborhoodShakingOperator op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) { 294 294 op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 295 295 op.BinaryVectorParameter.Hidden = true; 296 296 } 297 foreach (I ImprovementOperator op in Operators.OfType<IImprovementOperator>()) {298 op. TargetParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;299 op. TargetParameter.Hidden = true;300 } 301 foreach (I PathRelinker op in Operators.OfType<IPathRelinker>()) {297 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) { 298 op.SolutionParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 299 op.SolutionParameter.Hidden = true; 300 } 301 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) { 302 302 op.ParentsParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 303 303 op.ParentsParameter.Hidden = true; 304 304 } 305 foreach ( ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {306 op. Target= SolutionCreator.BinaryVectorParameter.ActualName;305 foreach (KnapsackSimilarityCalculator op in Operators.OfType<KnapsackSimilarityCalculator>()) { 306 op.SolutionVariableName = SolutionCreator.BinaryVectorParameter.ActualName; 307 307 } 308 308 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/PathRelinkers/KnapsackPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between knapsack solutions. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution by adding and removing elements as needed. 38 /// </remarks> 36 39 [Item("KnapsackPathRelinker", "An operator that relinks paths between knapsack solutions.")] 37 40 [StorableClass] 38 public sealed class KnapsackPathRelinker : PathRelinker {41 public sealed class KnapsackPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private KnapsackPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/PathRelinkers/KnapsackSimultaneousPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between knapsack solutions starting from both ends. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution and vice versa by adding and removing elements as needed. 38 /// </remarks> 36 39 [Item("KnapsackSimultaneousPathRelinker", "An operator that relinks paths between knapsack solutions starting from both ends.")] 37 40 [StorableClass] 38 public sealed class KnapsackSimultaneousPathRelinker : PathRelinker {41 public sealed class KnapsackSimultaneousPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private KnapsackSimultaneousPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs
r8304 r8319 30 30 /// An operator that performs similarity calculation between two knapsack solutions. 31 31 /// </summary> 32 /// <remarks> 33 /// The operator calculates the similarity based on the number of elements the two solutions have in common. 34 /// </remarks> 32 35 [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions.")] 33 public sealed class KnapsackSimilarityCalculator : Si milarityCalculator {36 public sealed class KnapsackSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 34 37 private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { } 35 38 private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 43 46 if (left == null || right == null) 44 47 throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes is null."); 48 if (left.Length != right.Length) 49 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths."); 45 50 if (left == right) return 1.0; 46 51 … … 51 56 } 52 57 53 public override double Calculate IndividualSimilarity(IScope left, IScope right) {54 var sol1 = left .Variables[Target].Value as BinaryVector;55 var sol2 = right .Variables[Target].Value as BinaryVector;58 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 59 var sol1 = leftSolution.Variables[SolutionVariableName].Value as BinaryVector; 60 var sol2 = rightSolution.Variables[SolutionVariableName].Value as BinaryVector; 56 61 57 62 return CalculateSimilarity(sol1, sol2); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/Improvers/SingleObjectiveTestFunctionImprovementOperator.cs
r8086 r8319 35 35 /// An operator that improves test functions solutions. 36 36 /// </summary> 37 /// <remarks> 38 /// It is implemented as described in Gao, F. and Han, L. (2010). Implementing the Nelder-Mead simplex algorithm with adaptive parameters. Computational Optimization and Applications, Vol. 51. Springer.<br /> 39 /// The operator is an implementation of the Nelder-Mead method and conducts relection, expansion, contraction and reduction on the test functions solution. 40 /// </remarks> 37 41 [Item("SingleObjectiveTestFunctionImprovementOperator", "An operator that improves test functions solutions.")] 38 42 [StorableClass] 39 public sealed class SingleObjectiveTestFunctionImprovementOperator : SingleSuccessorOperator, I ImprovementOperator {43 public sealed class SingleObjectiveTestFunctionImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator { 40 44 #region Parameter properties 41 45 public IValueParameter<DoubleValue> AlphaParameter { … … 63 67 get { return (IValueLookupParameter<IntValue>)Parameters["ImprovementAttempts"]; } 64 68 } 65 public IValueLookupParameter<IItem> TargetParameter {66 get { return (IValueLookupParameter<IItem>)Parameters[" Target"]; }69 public IValueLookupParameter<IItem> SolutionParameter { 70 get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; } 67 71 } 68 72 #endregion … … 109 113 Parameters.Add(new ValueParameter<DoubleValue>("Gamma", new DoubleValue(0.5))); 110 114 Parameters.Add(new ValueLookupParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100))); 111 Parameters.Add(new ValueLookupParameter<IItem>(" Target", "This parameter is used for name translation only."));115 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 112 116 #endregion 113 117 } … … 118 122 119 123 public override IOperation Apply() { 120 RealVector bestSol = CurrentScope.Variables[ TargetParameter.ActualName].Value as RealVector;124 RealVector bestSol = CurrentScope.Variables[SolutionParameter.ActualName].Value as RealVector; 121 125 if (bestSol == null) 122 126 throw new ArgumentException("Cannot improve solution because it has the wrong type."); … … 196 200 } 197 201 198 CurrentScope.Variables[ TargetParameter.ActualName].Value = simplex[0];202 CurrentScope.Variables[SolutionParameter.ActualName].Value = simplex[0]; 199 203 CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", ImprovementAttempts)); 200 204 -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/PathRelinkers/SingleObjectiveTestFunctionPathRelinker.cs
r8086 r8319 35 35 /// An operator that relinks paths between test functions solutions. 36 36 /// </summary> 37 /// <remarks> 38 /// TODO: add reference and remarks 39 /// </remarks> 37 40 [Item("SingleObjectiveTestFunctionPathRelinker", "An operator that relinks paths between test functions solutions.")] 38 41 [StorableClass] 39 public sealed class SingleObjectiveTestFunctionPathRelinker : PathRelinker {42 public sealed class SingleObjectiveTestFunctionPathRelinker : SingleObjectivePathRelinker { 40 43 #region Parameter properties 41 44 public IValueParameter<IntValue> RelinkingIntensityParameter { -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs
r8304 r8319 32 32 /// An operator that performs similarity calculation between two test functions solutions. 33 33 /// </summary> 34 /// <remarks> 35 /// The operator calculates the similarity based on the euclidean distance of the two solutions in n-dimensional space. 36 /// </remarks> 34 37 [Item("SingleObjectiveTestFunctionSimilarityCalculator", "An operator that performs similarity calculation between two test functions solutions.")] 35 38 [StorableClass] 36 public sealed class SingleObjectiveTestFunctionSimilarityCalculator : Si milarityCalculator {39 public sealed class SingleObjectiveTestFunctionSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 37 40 #region Properties 38 41 [Storable] … … 57 60 if (bounds == null) 58 61 throw new ArgumentException("Cannot calculate similarity because no bounds were provided."); 62 if (left.Length != right.Length) 63 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths."); 59 64 if (left == right) return 1.0; 60 65 … … 72 77 } 73 78 74 public override double Calculate IndividualSimilarity(IScope left, IScope right) {75 var sol1 = left .Variables[Target].Value as RealVector;76 var sol2 = right .Variables[Target].Value as RealVector;79 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 80 var sol1 = leftSolution.Variables[SolutionVariableName].Value as RealVector; 81 var sol2 = rightSolution.Variables[SolutionVariableName].Value as RealVector; 77 82 78 83 return CalculateSimilarity(sol1, sol2, Bounds); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r8086 r8319 363 363 op.MaximizationParameter.Hidden = true; 364 364 } 365 foreach ( var op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) {366 op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 367 op.RealVectorParameter.Hidden = true; 368 } 369 foreach (I ImprovementOperator op in Operators.OfType<IImprovementOperator>()) {370 op. TargetParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;371 op. TargetParameter.Hidden = true;372 } 373 foreach (I PathRelinker op in Operators.OfType<IPathRelinker>()) {365 foreach (IRealVectorMultiNeighborhoodShakingOperator op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) { 366 op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 367 op.RealVectorParameter.Hidden = true; 368 } 369 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) { 370 op.SolutionParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 371 op.SolutionParameter.Hidden = true; 372 } 373 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) { 374 374 op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 375 375 op.ParentsParameter.Hidden = true; 376 376 } 377 foreach (SingleObjectiveTestFunctionSimilarityCalculator op in Operators.OfType< ISimilarityCalculator>()) {378 op. Target= SolutionCreator.RealVectorParameter.ActualName;377 foreach (SingleObjectiveTestFunctionSimilarityCalculator op in Operators.OfType<SingleObjectiveTestFunctionSimilarityCalculator>()) { 378 op.SolutionVariableName = SolutionCreator.RealVectorParameter.ActualName; 379 379 op.Bounds = Bounds; 380 380 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/Improvers/TSPImprovementOperator.cs
r8086 r8319 34 34 /// An operator that improves traveling salesman solutions. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator tries to improve the traveling salesman solution by swapping two randomly chosen edges for a certain number of times. 38 /// </remarks> 36 39 [Item("TSPImprovementOperator", "An operator that improves traveling salesman solutions.")] 37 40 [StorableClass] 38 public sealed class TSPImprovementOperator : SingleSuccessorOperator, I ImprovementOperator {41 public sealed class TSPImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator { 39 42 #region Parameter properties 40 43 public ScopeParameter CurrentScopeParameter { … … 50 53 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 51 54 } 52 public IValueLookupParameter<IItem> TargetParameter {53 get { return (IValueLookupParameter<IItem>)Parameters[" Target"]; }55 public IValueLookupParameter<IItem> SolutionParameter { 56 get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; } 54 57 } 55 58 #endregion … … 83 86 Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100))); 84 87 Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator.")); 85 Parameters.Add(new ValueLookupParameter<IItem>(" Target", "This parameter is used for name translation only."));88 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 86 89 #endregion 87 90 } … … 92 95 93 96 public override IOperation Apply() { 94 Permutation currSol = CurrentScope.Variables[ TargetParameter.ActualName].Value as Permutation;97 Permutation currSol = CurrentScope.Variables[SolutionParameter.ActualName].Value as Permutation; 95 98 if (currSol == null) 96 99 throw new ArgumentException("Cannot improve solution because it has the wrong type."); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs
r8086 r8319 35 35 /// An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy. 36 36 /// </summary> 37 /// <remarks> 38 /// The operator incrementally changes the initiating solution towards the guiding solution by correcting edges as needed. For each city it choses the best edge from all guiding solutions. 39 /// </remarks> 37 40 [Item("TSPMultipleGuidesPathRelinker", "An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy.")] 38 41 [StorableClass] 39 public sealed class TSPMultipleGuidesPathRelinker : PathRelinker {42 public sealed class TSPMultipleGuidesPathRelinker : SingleObjectivePathRelinker { 40 43 #region Parameter properties 41 44 public ILookupParameter<DistanceMatrix> DistanceMatrixParameter { … … 93 96 } 94 97 }); 95 Invert(v1, i, bestCityIndex);98 Invert(v1, currCityIndex + 1, bestCityIndex); 96 99 solutions.Add(v1.Clone() as Permutation); 97 100 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between traveling salesman solutions. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution by correcting edges as needed. 38 /// </remarks> 36 39 [Item("TSPPathRelinker", "An operator that relinks paths between traveling salesman solutions.")] 37 40 [StorableClass] 38 public sealed class TSPPathRelinker : PathRelinker {41 public sealed class TSPPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private TSPPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPSimultaneousPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between traveling salesman solutions starting from both ends. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution and vice versa by correcting edges as needed. 38 /// </remarks> 36 39 [Item("TSPSimultaneousPathRelinker", "An operator that relinks paths between traveling salesman solutions starting from both ends.")] 37 40 [StorableClass] 38 public sealed class TSPSimultaneousPathRelinker : PathRelinker {41 public sealed class TSPSimultaneousPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private TSPSimultaneousPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs
r8304 r8319 30 30 /// An operator that performs similarity calculation between two traveling salesman solutions. 31 31 /// </summary> 32 /// <remarks> 33 /// The operator calculates the similarity based on the number of edges the two solutions have in common. 34 /// </remarks> 32 35 [Item("TSPSimilarityCalculator", "An operator that performs similarity calculation between two traveling salesman solutions.")] 33 public sealed class TSPSimilarityCalculator : Si milarityCalculator {36 public sealed class TSPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 34 37 private TSPSimilarityCalculator(bool deserializing) : base(deserializing) { } 35 38 private TSPSimilarityCalculator(TSPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 43 46 if (left == null || right == null) 44 47 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 45 if (left == right) return 1.0; 48 if (left.PermutationType != right.PermutationType) 49 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different types."); 50 if (left.Length != right.Length) 51 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths."); 52 var comparer = new PermutationEqualityComparer(); 53 if (object.ReferenceEquals(left, right) || comparer.Equals(left, right)) return 1.0; 46 54 55 switch (left.PermutationType) { 56 case PermutationTypes.Absolute: 57 return CalculateAbsolute(left, right); 58 case PermutationTypes.RelativeDirected: 59 return CalculateRelativeDirected(left, right); 60 case PermutationTypes.RelativeUndirected: 61 return CalculateRelativeUndirected(left, right); 62 default: 63 throw new InvalidOperationException("unknown permutation type"); 64 } 65 } 66 67 private static double CalculateAbsolute(Permutation left, Permutation right) { 68 double similarity = 0.0; 69 for (int i = 0; i < left.Length && left[i] == right[i]; similarity = ++i) ; 70 return similarity / left.Length; 71 } 72 73 private static double CalculateRelativeDirected(Permutation left, Permutation right) { 74 throw new NotImplementedException(); 75 } 76 77 private static double CalculateRelativeUndirected(Permutation left, Permutation right) { 47 78 int[,] edges = new int[right.Length, 2]; 48 79 for (int i = 0; i < right.Length; i++) { … … 61 92 } 62 93 63 public override double Calculate IndividualSimilarity(IScope left, IScope right) {64 var sol1 = left .Variables[Target].Value as Permutation;65 var sol2 = right .Variables[Target].Value as Permutation;94 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 95 var sol1 = leftSolution.Variables[SolutionVariableName].Value as Permutation; 96 var sol2 = rightSolution.Variables[SolutionVariableName].Value as Permutation; 66 97 67 98 return CalculateSimilarity(sol1, sol2); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r8086 r8319 342 342 op.PermutationParameter.Hidden = true; 343 343 } 344 foreach (I ImprovementOperator op in Operators.OfType<IImprovementOperator>()) {345 op. TargetParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;346 op. TargetParameter.Hidden = true;347 } 348 foreach (I PathRelinker op in Operators.OfType<IPathRelinker>()) {344 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) { 345 op.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 346 op.SolutionParameter.Hidden = true; 347 } 348 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) { 349 349 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 350 350 op.ParentsParameter.Hidden = true; 351 351 } 352 foreach ( ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {353 op. Target= SolutionCreator.PermutationParameter.ActualName;352 foreach (TSPSimilarityCalculator op in Operators.OfType<TSPSimilarityCalculator>()) { 353 op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName; 354 354 } 355 355 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Improvers/VRPImprovementOperator.cs
r8086 r8319 37 37 [Item("VRPImprovementOperator", "An operator that improves vehicle routing solutions.")] 38 38 [StorableClass] 39 public sealed class VRPImprovementOperator : SingleSuccessorOperator, I ImprovementOperator {39 public sealed class VRPImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator { 40 40 #region Parameter properties 41 41 public ILookupParameter<DoubleValue> CapacityParameter { … … 90 90 get { return (ILookupParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; } 91 91 } 92 public IValueLookupParameter<IItem> TargetParameter {93 get { return (IValueLookupParameter<IItem>)Parameters[" Target"]; }92 public IValueLookupParameter<IItem> SolutionParameter { 93 get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; } 94 94 } 95 95 public ILookupParameter<DoubleValue> EvalTimeFactorParameter { … … 127 127 Parameters.Add(new LookupParameter<DoubleArray>("ServiceTime", "The service time of each customer.")); 128 128 Parameters.Add(new LookupParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.")); 129 Parameters.Add(new ValueLookupParameter<IItem>(" Target", "This parameter is used for name translation only."));129 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 130 130 Parameters.Add(new LookupParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.")); 131 131 Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false")); … … 139 139 140 140 public override IOperation Apply() { 141 AlbaEncoding solution = TargetParameter.ActualValue is AlbaEncoding ?142 TargetParameter.ActualValue as AlbaEncoding :143 AlbaEncoding.ConvertFrom( TargetParameter.ActualValue as IVRPEncoding, VehiclesParameter.ActualValue.Value, DistanceMatrixParameter);141 AlbaEncoding solution = SolutionParameter.ActualValue is AlbaEncoding ? 142 SolutionParameter.ActualValue as AlbaEncoding : 143 AlbaEncoding.ConvertFrom(SolutionParameter.ActualValue as IVRPEncoding, VehiclesParameter.ActualValue.Value, DistanceMatrixParameter); 144 144 145 145 if (solution == null) … … 156 156 EvalTardinessPenaltyParameter.ActualValue, UseDistanceMatrixParameter.ActualValue); 157 157 158 TargetParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, DistanceMatrixParameter);158 SolutionParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, DistanceMatrixParameter); 159 159 CurrentScopeParameter.ActualValue.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions))); 160 160 -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/PathRelinkers/VRPPathRelinker.cs
r8086 r8319 39 39 [Item("VRPPathRelinker", "An operator that relinks paths between vehicle routing solutions.")] 40 40 [StorableClass] 41 public sealed class VRPPathRelinker : PathRelinker, IStochasticOperator {41 public sealed class VRPPathRelinker : SingleObjectivePathRelinker, IStochasticOperator { 42 42 #region Parameters 43 43 public ILookupParameter<DoubleMatrix> CoordinatesParameter { -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/SimilarityCalculators/VRPSimilarityCalculator.cs
r8304 r8319 33 33 /// An operator that performs similarity calculation between two vehicle routing solutions. 34 34 /// </summary> 35 /// <remarks> 36 /// The operator calculates the similarity based on the number of edges the two solutions have in common. 37 /// </remarks> 35 38 [Item("VRPSimilarityCalculator", "An operator that performs similarity calculation between two vehicle routing solutions.")] 36 public sealed class VRPSimilarityCalculator : Si milarityCalculator {39 public sealed class VRPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 37 40 private VRPSimilarityCalculator(bool deserializing) : base(deserializing) { } 38 41 private VRPSimilarityCalculator(VRPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 78 81 } 79 82 80 public override double Calculate IndividualSimilarity(IScope left, IScope right) {81 var sol1 = left .Variables[Target].Value as PotvinEncoding;82 var sol2 = right .Variables[Target].Value as PotvinEncoding;83 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 84 var sol1 = leftSolution.Variables[SolutionVariableName].Value as PotvinEncoding; 85 var sol2 = rightSolution.Variables[SolutionVariableName].Value as PotvinEncoding; 83 86 84 87 return CalculateSimilarity(sol1, sol2); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs
r8086 r8319 518 518 } 519 519 520 foreach ( var op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) {520 foreach (IVRPMultiNeighborhoodShakingOperator op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) { 521 521 op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName; 522 522 } 523 foreach (I ImprovementOperator op in Operators.OfType<IImprovementOperator>()) {524 op. TargetParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;525 op. TargetParameter.Hidden = true;526 } 527 foreach (I PathRelinker op in Operators.OfType<IPathRelinker>()) {523 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) { 524 op.SolutionParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName; 525 op.SolutionParameter.Hidden = true; 526 } 527 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) { 528 528 op.ParentsParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName; 529 529 op.ParentsParameter.Hidden = true; 530 530 } 531 foreach ( ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {532 op. Target= SolutionCreator.VRPToursParameter.ActualName;531 foreach (VRPSimilarityCalculator op in Operators.OfType<VRPSimilarityCalculator>()) { 532 op.SolutionVariableName = SolutionCreator.VRPToursParameter.ActualName; 533 533 } 534 534 }
Note: See TracChangeset
for help on using the changeset viewer.