- Timestamp:
- 06/22/12 11:11:38 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/HeuristicLab.Problems.Knapsack-3.3.csproj
r7789 r8086 116 116 <Compile Include="MoveEvaluators\KnapsackMoveEvaluator.cs" /> 117 117 <Compile Include="MoveEvaluators\KnapsackOneBitflipMoveEvaluator.cs" /> 118 <Compile Include="PathRelinkers\KnapsackMultipleGuidesPathRelinker.cs" />119 118 <Compile Include="PathRelinkers\KnapsackPathRelinker.cs" /> 120 119 <Compile Include="PathRelinkers\KnapsackSimultaneousPathRelinker.cs" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/Improvers/KnapsackImprovementOperator.cs
r7789 r8086 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; … … 26 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 27 28 using HeuristicLab.Operators; 28 using HeuristicLab.Optimization .Operators;29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 70 71 set { PenaltyParameter.ActualValue = value; } 71 72 } 72 private IItem Target {73 get { return TargetParameter.ActualValue; }74 }75 73 private IntArray Values { 76 74 get { return ValuesParameter.ActualValue; } … … 89 87 : base() { 90 88 #region Create parameters 91 Parameters.Add(new ScopeParameter("CurrentScope" ));92 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity" ));93 Parameters.Add(new LookupParameter<DoubleValue>("Penalty" ));94 Parameters.Add(new ValueLookupParameter<IItem>("Target" ));95 Parameters.Add(new LookupParameter<IntArray>("Values" ));96 Parameters.Add(new LookupParameter<IntArray>("Weights" ));89 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved.")); 90 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); 91 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.")); 93 Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items.")); 94 Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items.")); 97 95 #endregion 98 96 } … … 104 102 public override IOperation Apply() { 105 103 BinaryVector sol = CurrentScope.Variables[TargetParameter.ActualName].Value as BinaryVector; 104 if (sol == null) 105 throw new ArgumentException("Cannot improve solution because it has the wrong type."); 106 106 107 107 // calculate value-to-weight ratio … … 113 113 // calculate order for ratio 114 114 int[] order = new int[ratio.Length]; 115 ratio.Select((x, index) => new { Value = x, ValueIndex = index }) 116 .OrderBy(x => x.Value) 117 .Select((x, index) => new { ValueIndex = x.ValueIndex, ItemIndex = index }).ToList() 118 .ForEach(x => order[x.ItemIndex] = x.ValueIndex); 115 foreach (var x in ratio.Select((x, index) => new { Value = x, ValueIndex = index }) 116 .OrderBy(x => x.Value) 117 .Select((x, index) => new { ValueIndex = x.ValueIndex, ItemIndex = index })) { 118 order[x.ItemIndex] = x.ValueIndex; 119 } 119 120 121 int evaluatedSolutions = 0; 120 122 int j = sol.Length - 1; 121 123 while (KnapsackEvaluator.Apply(sol, KnapsackCapacity, Penalty, Weights, Values) 122 .SumWeights.Value > KnapsackCapacity.Value && j >= 0) 124 .SumWeights.Value > KnapsackCapacity.Value && j >= 0) { 123 125 sol[order[j--]] = false; 126 evaluatedSolutions++; 127 } 124 128 125 129 // calculate weight … … 136 140 weight += Weights[order[j]]; 137 141 } else feasible = false; 142 evaluatedSolutions++; 138 143 } 139 144 140 145 CurrentScope.Variables[TargetParameter.ActualName].Value = sol; 146 CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions))); 141 147 142 148 return base.Apply(); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r7789 r8086 28 28 using HeuristicLab.Encodings.BinaryVectorEncoding; 29 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Optimization.Operators;31 30 using HeuristicLab.Parameters; 32 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 246 245 private void InitializeOperators() { 247 246 Operators.Add(new KnapsackImprovementOperator()); 248 Operators.Add(new KnapsackMultipleGuidesPathRelinker());249 247 Operators.Add(new KnapsackPathRelinker()); 250 248 Operators.Add(new KnapsackSimultaneousPathRelinker()); … … 306 304 } 307 305 foreach (ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) { 308 op.TargetParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 309 op.TargetParameter.Hidden = true; 306 op.Target = SolutionCreator.BinaryVectorParameter.ActualName; 310 307 } 311 308 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/Plugin.cs.frame
r7259 r8086 36 36 [PluginDependency("HeuristicLab.Operators", "3.3")] 37 37 [PluginDependency("HeuristicLab.Optimization", "3.3")] 38 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 38 39 [PluginDependency("HeuristicLab.Parameters", "3.3")] 39 40 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs
r7793 r8086 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.BinaryVectorEncoding; 25 26 using HeuristicLab.Optimization.Operators; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;27 27 28 28 namespace HeuristicLab.Problems.Knapsack { … … 31 31 /// </summary> 32 32 [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions.")] 33 [StorableClass]34 33 public sealed class KnapsackSimilarityCalculator : SimilarityCalculator { 35 [StorableConstructor]36 34 private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { } 37 35 private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 38 36 public KnapsackSimilarityCalculator() : base() { } 39 37 40 public override IDeepCloneable Clone(Cloner cloner) { 41 return new KnapsackSimilarityCalculator(this, cloner); 38 public static double CalculateSimilarity(BinaryVector left, BinaryVector right) { 39 if (left == null || right == null) 40 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 41 42 double similarity = 0.0; 43 for (int i = 0; i < left.Length; i++) 44 if (left[i] == right[i]) similarity++; 45 return similarity / left.Length; 42 46 } 43 47 44 48 protected override double CalculateSimilarity(IScope left, IScope right) { 45 BinaryVector sol1 = left.Variables[Target Parameter.ActualName].Value as BinaryVector;46 BinaryVector sol2 = right.Variables[Target Parameter.ActualName].Value as BinaryVector;49 BinaryVector sol1 = left.Variables[Target].Value as BinaryVector; 50 BinaryVector sol2 = right.Variables[Target].Value as BinaryVector; 47 51 48 double similarity = 0.0; 49 for (int i = 0; i < sol1.Length; i++) 50 if (sol1[i] == sol2[i]) similarity++; 51 return similarity / sol1.Length; 52 return CalculateSimilarity(sol1, sol2); 52 53 } 53 54 }
Note: See TracChangeset
for help on using the changeset viewer.