Changeset 14691 for branches/PerformanceComparison
- Timestamp:
- 02/23/17 10:42:58 (8 years ago)
- Location:
- branches/PerformanceComparison
- Files:
-
- 4 added
- 15 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/HeuristicLab.Algorithms.MemPR-3.3.csproj
r14678 r14691 132 132 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4"> 133 133 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 134 <Private>False</Private> 135 </Reference> 136 <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 137 <SpecificVersion>False</SpecificVersion> 138 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 139 <Private>False</Private> 140 </Reference> 141 <Reference Include="HeuristicLab.Problems.QuadraticAssignment-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 142 <SpecificVersion>False</SpecificVersion> 143 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.QuadraticAssignment-3.3.dll</HintPath> 134 144 <Private>False</Private> 135 145 </Reference> -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/MemPRContext.cs
r14690 r14691 469 469 470 470 private TContext parent; 471 protected TContext BaseContext { 472 get { return parent;} 473 } 471 474 public IExecutionContext Parent { 472 475 get { return parent; } -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimb.cs
r14690 r14691 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.QuadraticAssignment; 30 31 31 32 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 54 55 var quality = context.Solution.Fitness; 55 56 try { 57 58 var min = 0.0; 59 var max = 1.0; 60 var qap = context.Problem as QuadraticAssignmentProblem; 61 if (qap != null) { 62 min = qap.LowerBound.Value; 63 max = qap.AverageQuality.Value; 64 } 65 56 66 var path = new List<Tuple<Encodings.PermutationEncoding.Permutation, double>>(); 57 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), quality));67 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), (quality - min) / (max - min))); 58 68 59 69 var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, quality, 60 70 context.Maximization, context.Evaluate, CancellationToken.None); 61 62 Tuple<Encodings.PermutationEncoding.Permutation, double, int> last = null;71 72 var evaluations = 0; 63 73 foreach (var step in result) { 64 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), step.Item2));65 last = step;74 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), (step.Item2 - min) / (max - min))); 75 evaluations = step.Item3; // last one will be actual evaluations 66 76 } 67 77 context.LocalSearchPaths.AddPath(path); 68 context.IncrementEvaluatedSolutions( last.Item3);78 context.IncrementEvaluatedSolutions(evaluations); 69 79 context.Iterations = path.Count - 2; 70 80 } finally { -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimbSubspace.cs
r14690 r14691 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.QuadraticAssignment; 30 31 31 32 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 54 55 var quality = context.Solution.Fitness; 55 56 try { 57 var min = 0.0; 58 var max = 1.0; 59 var qap = context.Problem as QuadraticAssignmentProblem; 60 if (qap != null) { 61 min = qap.LowerBound.Value; 62 max = qap.AverageQuality.Value; 63 } 64 56 65 var path = new List<Tuple<Encodings.PermutationEncoding.Permutation, double>>(); 57 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), quality));66 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), (quality - min) / (max - min))); 58 67 59 68 var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, quality, 60 69 context.Maximization, context.Evaluate, CancellationToken.None, context.Subspace.Subspace); 61 70 62 Tuple<Encodings.PermutationEncoding.Permutation, double, int> last = null;71 var evaluations = 0; 63 72 foreach (var step in result) { 64 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), step.Item2));65 last = step;73 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), (step.Item2 - min) / (max - min))); 74 evaluations = step.Item3; // last one will be actual evaluations 66 75 } 67 76 context.LocalSearchPaths.AddPath(path); 68 context.IncrementEvaluatedSolutions( last.Item3);77 context.IncrementEvaluatedSolutions(evaluations); 69 78 context.Iterations = path.Count - 2; 70 79 } finally { -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/PermutationMemPRContext.cs
r14552 r14691 23 23 using System.Runtime.Remoting.Contexts; 24 24 using HeuristicLab.Algorithms.MemPR.Interfaces; 25 using HeuristicLab.Analysis.FitnessLandscape; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 61 62 [Item("MemPR Solution Context (permutation)", "MemPR solution context for permutation encoded problems.")] 62 63 [StorableClass] 63 public sealed class PermutationMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation, PermutationMemPRPopulationContext, PermutationMemPRSolutionContext>, IPermutationSubspaceContext { 64 public sealed class PermutationMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation, PermutationMemPRPopulationContext, PermutationMemPRSolutionContext>, IPermutationSubspaceContext, 65 ILocalSearchPathContext<Encodings.PermutationEncoding.Permutation> { 64 66 65 67 [Storable] … … 87 89 return new PermutationMemPRSolutionContext(this, cloner); 88 90 } 91 92 public DirectedPath<Encodings.PermutationEncoding.Permutation> LocalSearchPaths { 93 get { return BaseContext.LocalSearchPaths; } 94 } 89 95 } 90 96 } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/HeuristicLab.Analysis.FitnessLandscape-3.3.csproj
r14678 r14691 207 207 <Compile Include="CharacteristicCalculator\RandomWalkCalculator.cs" /> 208 208 <Compile Include="ProblemCharacteristicAnalysis\CharacteristicCalculator.cs" /> 209 <Compile Include="ProblemCharacteristicAnalysis\CurveAnalysis.cs" /> 209 210 <Compile Include="ProblemCharacteristicAnalysis\DoubleMatrixCharacteristicCalculator.cs" /> 211 <Compile Include="ProblemCharacteristicAnalysis\PermutationPathAnalysis.cs" /> 210 212 <Compile Include="ProblemCharacteristicAnalysis\QAP\QAPCharacteristicCalculator.cs" /> 211 213 <Compile Include="ProblemCharacteristicAnalysis\QAP\QAPDirectedWalk.cs" /> -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/QAP/QAPDirectedWalk.cs
r14690 r14691 79 79 private QAPDirectedWalk(QAPDirectedWalk original, Cloner cloner) : base(original, cloner) { } 80 80 public QAPDirectedWalk() { 81 characteristics.AddRange(new[] { "Swap2.Sharpness", "Swap2.Bumpiness", "Swap2.Flatness", "Swap2.Steadiness"}81 characteristics.AddRange(new[] { "Swap2.Sharpness", "Swap2.Bumpiness", "Swap2.Flatness", /*"Swap2.Steadiness"*/ } 82 82 .Select(x => new StringValue(x)).ToList()); 83 83 Parameters.Add(new FixedValueParameter<IntValue>("Paths", "The number of paths to explore (a path is a set of solutions that connect two randomly chosen solutions).", new IntValue(50))); … … 118 118 119 119 var trajectories = Run(random, (QuadraticAssignmentProblem)Problem, permutations, BestImprovement).ToList(); 120 var firstDerivatives = trajectories.Select(path => ApproximateDerivative(path).ToList()).ToList(); 121 var secondDerivatives = firstDerivatives.Select(d1 => ApproximateDerivative(d1).ToList()).ToList(); 120 var result = PermutationPathAnalysis.GetCharacteristics(trajectories); 122 121 123 var props = GetCharacteristics(trajectories, firstDerivatives, secondDerivatives).ToDictionary(x => x.Item1, x => x.Item2);124 122 foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) { 125 if (chara == "Swap2.Sharpness") yield return new Result("Swap2.Sharpness", new DoubleValue(props["Sharpness"])); 126 if (chara == "Swap2.Bumpiness") yield return new Result("Swap2.Bumpiness", new DoubleValue(props["Bumpiness"])); 127 if (chara == "Swap2.Flatness") yield return new Result("Swap2.Flatness", new DoubleValue(props["Flatness"])); 128 if (chara == "Swap2.Steadiness") yield return new Result("Swap2.Steadiness", new DoubleValue(props["Steadiness"])); 129 } 130 } 131 132 public static IEnumerable<IResult> Calculate(List<List<Tuple<Permutation, double>>> trajectories) { 133 var firstDerivatives = trajectories.Select(path => ApproximateDerivative(path).ToList()).ToList(); 134 var secondDerivatives = firstDerivatives.Select(d1 => ApproximateDerivative(d1).ToList()).ToList(); 135 136 var props = GetCharacteristics(trajectories, firstDerivatives, secondDerivatives).ToDictionary(x => x.Item1, x => x.Item2); 137 yield return new Result("Swap2.Sharpness", new DoubleValue(props["Sharpness"])); 138 yield return new Result("Swap2.Bumpiness", new DoubleValue(props["Bumpiness"])); 139 yield return new Result("Swap2.Flatness", new DoubleValue(props["Flatness"])); 140 yield return new Result("Swap2.Steadiness", new DoubleValue(props["Steadiness"])); 123 if (chara == "Swap2.Sharpness") yield return new Result("Swap2.Sharpness", new DoubleValue(result.Sharpness)); 124 if (chara == "Swap2.Bumpiness") yield return new Result("Swap2.Bumpiness", new DoubleValue(result.Bumpiness)); 125 if (chara == "Swap2.Flatness") yield return new Result("Swap2.Flatness", new DoubleValue(result.Flatness)); 126 } 141 127 } 142 128 … … 158 144 } 159 145 160 private static IEnumerable<Tuple<string, double>> GetCharacteristics(List<List<Tuple<Permutation, double>>> f, List<List<Tuple<Permutation, double>>> f1, List<List<Tuple<Permutation, double>>> f2) { 161 var sharpness = f2.Average(x => Area(x)); 162 var bumpiness = 0.0; 163 var flatness = 0.0; 164 var downPointing = f1.Where(x => x.Min(y => y.Item2) < 0).ToList(); 165 166 var steadiness = 0.0; 167 foreach (var path in downPointing) { 168 steadiness += ComBelowZero(path); 169 } 170 if (downPointing.Count > 0) steadiness /= downPointing.Count; 171 172 for (var p = 0; p < f2.Count; p++) { 173 if (f2[p].Count <= 2) continue; 174 var bump = 0; 175 var flat = 0; 176 for (var i = 0; i < f2[p].Count - 1; i++) { 177 if ((f2[p][i].Item2 > 0 && f2[p][i + 1].Item2 < 0) || (f2[p][i].Item2 < 0 && f2[p][i + 1].Item2 > 0)) { 178 bump++; 179 } else if (f2[p][i].Item2 == 0) { 180 flat++; 181 } 182 } 183 bumpiness += bump / (f2[p].Count - 1.0); 184 flatness += flat / (f2[p].Count - 1.0); 185 } 186 bumpiness /= f2.Count; 187 flatness /= f2.Count; 188 return new[] { 189 Tuple.Create("Sharpness", sharpness), 190 Tuple.Create("Bumpiness", bumpiness), 191 Tuple.Create("Flatness", flatness), 192 Tuple.Create("Steadiness", steadiness) 193 }; 194 } 195 196 public static IEnumerable<Tuple<Permutation, double>> BestDirectedWalk(QuadraticAssignmentProblem qap, Permutation start, Permutation end) { 146 private static IEnumerable<Tuple<Permutation, double>> BestDirectedWalk(QuadraticAssignmentProblem qap, Permutation start, Permutation end) { 197 147 var N = qap.Weights.Rows; 198 148 var sol = start; … … 225 175 } 226 176 227 p ublicstatic IEnumerable<Tuple<Permutation, double>> FirstDirectedWalk(IRandom random, QuadraticAssignmentProblem qap, Permutation start, Permutation end) {177 private static IEnumerable<Tuple<Permutation, double>> FirstDirectedWalk(IRandom random, QuadraticAssignmentProblem qap, Permutation start, Permutation end) { 228 178 var N = qap.Weights.Rows; 229 179 var sol = start; … … 260 210 } 261 211 262 private static double Area(IEnumerable<Tuple<Permutation, double>> path) {263 var iter = path.GetEnumerator();264 if (!iter.MoveNext()) return 0.0;265 var area = 0.0;266 var prev = iter.Current;267 while (iter.MoveNext()) {268 area += TrapezoidArea(prev, iter.Current);269 prev = iter.Current;270 }271 return area;272 }273 274 private static double TrapezoidArea(Tuple<Permutation, double> a, Tuple<Permutation, double> b) {275 var area = 0.0;276 var dist = Dist(a.Item1, b.Item1);277 if ((a.Item2 <= 0 && b.Item2 <= 0) || (a.Item2 >= 0 && b.Item2 >= 0))278 area += dist * (Math.Abs(a.Item2) + Math.Abs(b.Item2)) / 2.0;279 else {280 var k = (b.Item2 - a.Item2) / dist;281 var d = a.Item2;282 var x = -d / k;283 area += Math.Abs(x * a.Item2 / 2.0);284 area += Math.Abs((dist - x) * b.Item2 / 2.0);285 }286 return area;287 }288 289 // Center-of-Mass290 private static double ComBelowZero(IEnumerable<Tuple<Permutation, double>> path) {291 var area = 0.0;292 var com = 0.0;293 var nwalkDist = 0.0;294 Tuple<Permutation, double> prev = null;295 var iter = path.GetEnumerator();296 while (iter.MoveNext()) {297 var c = iter.Current;298 if (prev != null) {299 var ndist = Dist(prev.Item1, c.Item1) / (double)c.Item1.Length;300 nwalkDist += ndist;301 if (prev.Item2 < 0 || c.Item2 < 0) {302 var a = TrapezoidArea(prev, c) / (double)c.Item1.Length;303 area += a;304 com += (nwalkDist - (ndist / 2.0)) * a;305 }306 }307 prev = c;308 }309 return com / area;310 }311 312 private static IEnumerable<Tuple<Permutation, double>> ApproximateDerivative(IEnumerable<Tuple<Permutation, double>> data) {313 Tuple<Permutation, double> prev = null, prev2 = null;314 foreach (var d in data) {315 if (prev == null) {316 prev = d;317 continue;318 }319 if (prev2 == null) {320 prev2 = prev;321 prev = d;322 continue;323 }324 var dist = Dist(prev2.Item1, d.Item1);325 yield return Tuple.Create(prev.Item1, (d.Item2 - prev2.Item2) / (double)dist);326 prev2 = prev;327 prev = d;328 }329 }330 331 private static double Dist(Permutation a, Permutation b) {332 var dist = 0;333 for (var i = 0; i < a.Length; i++)334 if (a[i] != b[i]) dist++;335 return dist;336 }337 338 212 private static int[] GetInverse(Permutation p) { 339 213 var inv = new int[p.Length]; -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemInstanceAnalysis/ProblemInstanceAnalyzer.cs
r14678 r14691 78 78 if (currentCharacteristics == null) return base.Apply(); 79 79 80 var order = Enumerable.Range(0, kbCharacteristics.Rows) 80 var means = kbCharacteristics.GetRow(kbCharacteristics.Rows - 2).ToArray(); 81 var stdevs = kbCharacteristics.GetRow(kbCharacteristics.Rows - 1).ToArray(); 82 83 for (var i = 0; i < means.Length; i++) { 84 currentCharacteristics[i] = (currentCharacteristics[i] - means[i]) / stdevs[i]; 85 } 86 87 var order = Enumerable.Range(0, kbCharacteristics.Rows - 2) 81 88 .Select(row => new { Row = row, MSE = kbCharacteristics.GetRow(row).Zip(currentCharacteristics, (a, b) => (a - b) * (a - b)).Average() }) 82 89 .OrderBy(x => x.MSE); 83 90 84 91 var instances = kbCharacteristics.RowNames.ToList(); 85 while (instances.Count < kbCharacteristics.Rows )92 while (instances.Count < kbCharacteristics.Rows - 2) 86 93 instances.Add(instances.Count.ToString(CultureInfo.CurrentCulture.NumberFormat)); 87 94 -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemInstanceAnalysis/QAPPRProblemInstanceAnalyzer.cs
r14678 r14691 49 49 if (trajectories.Count == 0) return null; 50 50 51 var characteristics = QAPDirectedWalk.Calculate(trajectories).Select(x => x.Value).ToList(); 52 var result = new DoubleArray(characteristics.Count); 53 for (var i = 0; i < characteristics.Count; i++) { 54 var dv = characteristics[i] as DoubleValue; 55 if (dv != null) result[i] = dv.Value; 56 else { 57 var iv = characteristics[i] as IntValue; 58 if (iv != null) result[i] = iv.Value; 59 } 60 } 61 return result; 51 return new DoubleArray(PermutationPathAnalysis.GetCharacteristics(trajectories).GetValues().ToArray()); 62 52 } 63 53 } -
branches/PerformanceComparison/HeuristicLab.Optimization.Views
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/PerformanceComparison/HeuristicLab.Problems.Instances.QAPLIB/3.3/HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj
r11650 r14691 19 19 <DebugType>full</DebugType> 20 20 <Optimize>false</Optimize> 21 <OutputPath>..\..\ bin\</OutputPath>21 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 22 22 <DefineConstants>DEBUG;TRACE</DefineConstants> 23 23 <ErrorReport>prompt</ErrorReport> … … 28 28 <DebugType>pdbonly</DebugType> 29 29 <Optimize>true</Optimize> 30 <OutputPath>..\..\ bin\</OutputPath>30 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 31 31 <DefineConstants>TRACE</DefineConstants> 32 32 <ErrorReport>prompt</ErrorReport> … … 42 42 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> 43 43 <DebugSymbols>true</DebugSymbols> 44 <OutputPath>..\..\ bin\</OutputPath>44 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 45 45 <DefineConstants>DEBUG;TRACE</DefineConstants> 46 46 <DebugType>full</DebugType> … … 58 58 </PropertyGroup> 59 59 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> 60 <OutputPath>..\..\ bin\</OutputPath>60 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 61 61 <DefineConstants>TRACE</DefineConstants> 62 62 <Optimize>true</Optimize> … … 76 76 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 77 77 <DebugSymbols>true</DebugSymbols> 78 <OutputPath>..\..\ bin\</OutputPath>78 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 79 79 <DefineConstants>DEBUG;TRACE</DefineConstants> 80 80 <DebugType>full</DebugType> … … 92 92 </PropertyGroup> 93 93 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 94 <OutputPath>..\..\ bin\</OutputPath>94 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 95 95 <DefineConstants>TRACE</DefineConstants> 96 96 <Optimize>true</Optimize> … … 109 109 </PropertyGroup> 110 110 <ItemGroup> 111 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 112 <SpecificVersion>False</SpecificVersion> 113 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 114 <Private>False</Private> 115 </Reference> 116 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 117 <SpecificVersion>False</SpecificVersion> 118 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 119 <Private>False</Private> 120 </Reference> 121 <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 122 <SpecificVersion>False</SpecificVersion> 123 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 124 <Private>False</Private> 125 </Reference> 111 126 <Reference Include="System" /> 112 127 <Reference Include="System.Core" /> … … 115 130 </ItemGroup> 116 131 <ItemGroup> 132 <Compile Include="OneSizeDataDescriptor.cs" /> 133 <Compile Include="OneSizeInstanceProvider.cs" /> 117 134 <Compile Include="TaillardQAPInstanceProvider.cs" /> 118 135 <Compile Include="DreznerQAPInstanceProvider.cs" /> … … 137 154 <ItemGroup> 138 155 <None Include="HeuristicLab.snk" /> 139 </ItemGroup>140 <ItemGroup>141 <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">142 <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>143 <Name>HeuristicLab.Common-3.3</Name>144 <Private>False</Private>145 </ProjectReference>146 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">147 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>148 <Name>HeuristicLab.PluginInfrastructure-3.3</Name>149 <Private>False</Private>150 </ProjectReference>151 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">152 <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>153 <Name>HeuristicLab.Problems.Instances-3.3</Name>154 <Private>False</Private>155 </ProjectReference>156 156 </ItemGroup> 157 157 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/PerformanceComparison/PerformanceComparison.sln
r14678 r14691 25 25 EndProject 26 26 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.DataAnalysis-3.4", "HeuristicLab.Algorithms.DataAnalysis\3.4\HeuristicLab.Algorithms.DataAnalysis-3.4.csproj", "{2E782078-FA81-4B70-B56F-74CE38DAC6C8}" 27 EndProject 28 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.Instances.QAPLIB-3.3", "HeuristicLab.Problems.Instances.QAPLIB\3.3\HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj", "{73F29D43-5714-4069-8FAB-0D18FEB5F175}" 27 29 EndProject 28 30 Global … … 168 170 {2E782078-FA81-4B70-B56F-74CE38DAC6C8}.Release|x86.ActiveCfg = Release|x86 169 171 {2E782078-FA81-4B70-B56F-74CE38DAC6C8}.Release|x86.Build.0 = Release|x86 172 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 173 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Debug|Any CPU.Build.0 = Debug|Any CPU 174 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Debug|x64.ActiveCfg = Debug|x64 175 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Debug|x64.Build.0 = Debug|x64 176 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Debug|x86.ActiveCfg = Debug|x86 177 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Debug|x86.Build.0 = Debug|x86 178 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Release|Any CPU.ActiveCfg = Release|Any CPU 179 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Release|Any CPU.Build.0 = Release|Any CPU 180 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Release|x64.ActiveCfg = Release|x64 181 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Release|x64.Build.0 = Release|x64 182 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Release|x86.ActiveCfg = Release|x86 183 {73F29D43-5714-4069-8FAB-0D18FEB5F175}.Release|x86.Build.0 = Release|x86 170 184 EndGlobalSection 171 185 GlobalSection(SolutionProperties) = preSolution -
branches/PerformanceComparison/ProblemInstanceIdentifier/InstanceDescriptor.cs
r14690 r14691 46 46 47 47 public static InstanceDescriptor FromPaths(QuadraticAssignmentProblem qap, List<List<Tuple<Permutation, double>>> trajectories) { 48 var features = QAPDirectedWalk.Calculate(trajectories).ToDictionary(x => x.Name, x => x.Value);49 48 var result = PermutationPathAnalysis.GetCharacteristics(trajectories); 49 50 50 return new InstanceDescriptor() { 51 51 Name = qap.Name, 52 52 Cls = GetClass(qap.Name), 53 53 Dimension = qap.Weights.Rows, 54 FeatureNames = features.Keys.ToArray(),55 FeatureValues = features.Values.Select(x => ((DoubleValue)x).Value).ToArray()54 FeatureNames = result.GetNames(), 55 FeatureValues = result.GetValues() 56 56 }; 57 57 } … … 87 87 private double[] featureStdevs; 88 88 89 public IEnumerable<double> GetMeans() { 90 return featureMeans; 91 } 92 public IEnumerable<double> GetStdevs() { 93 return featureStdevs; 94 } 95 89 96 private InstancesStandardizer() { } 90 97 … … 101 108 return standardizer; 102 109 } 110 public static InstancesStandardizer CreateAndApply(IList<InstanceDescriptor> instances) { 111 var standardizer = Create(instances); 112 standardizer.Apply(instances); 113 return standardizer; 114 } 103 115 104 116 public void Apply(IList<InstanceDescriptor> instances) { -
branches/PerformanceComparison/ProblemInstanceIdentifier/InstanceExplorer.cs
r14690 r14691 1 using System.Linq; 1 using System; 2 using System.Linq; 2 3 using System.Threading; 4 using HeuristicLab.Algorithms.MemPR.Permutation; 3 5 using HeuristicLab.Analysis.FitnessLandscape; 4 6 using HeuristicLab.Data; … … 57 59 var walk = new RandomWalk() { 58 60 SeedParameter = { Value = { Value = seed ?? 0 } }, 59 SetSeedRandomlyParameter = { Value = { Value = seed.HasValue } },61 SetSeedRandomlyParameter = { Value = { Value = !seed.HasValue } }, 60 62 MaximumIterationsParameter = { Value = { Value = Iterations } }, 61 63 RepetitionsParameter = { Value = { Value = 1 } } … … 71 73 } 72 74 } 75 76 public class MemPRExplorer : InstanceExplorer { 77 public int Seconds { get; set; } 78 79 public bool IncludeLocalSearch { get; set; } 80 81 public override string Name { get { return "MemPR Explorer"; } } 82 public override int Effort { get { return Seconds; } } 83 84 public MemPRExplorer() { 85 86 } 87 88 public override InstanceDescriptor Explore(QuadraticAssignmentProblem problem, int? seed = null) { 89 var memPr = new PermutationMemPR(); 90 memPr.Problem = problem; 91 memPr.Prepare(true); 92 memPr.MaximumExecutionTime = TimeSpan.FromSeconds(Seconds); 93 memPr.SetSeedRandomly = !seed.HasValue; 94 memPr.Seed = seed ?? 0; 95 memPr.StartSync(); 96 if (memPr.Context.RelinkedPaths.IsEmpty 97 || IncludeLocalSearch && memPr.Context.LocalSearchPaths.IsEmpty) { 98 Console.Write("{0} not all paths present!", problem.Name); 99 return null; 100 }; 101 102 var features = PermutationPathAnalysis.GetCharacteristics(memPr.Context.RelinkedPaths.Paths.ToList()); 103 var result = features.GetValues(); 104 var resultNames = features.GetNames(); 105 if (IncludeLocalSearch) { 106 features = PermutationPathAnalysis.GetCharacteristics(memPr.Context.LocalSearchPaths.Paths.ToList()); 107 result = result.Concat(features.GetValues()).ToArray(); 108 resultNames = resultNames.Concat(features.GetNames()).ToArray(); 109 } 110 return new InstanceDescriptor(problem.Name, InstanceDescriptor.GetClass(problem.Name), problem.Weights.Rows, resultNames, result); 111 } 112 } 73 113 } -
branches/PerformanceComparison/ProblemInstanceIdentifier/Program.cs
r14690 r14691 9 9 using HeuristicLab.Problems.Instances.QAPLIB; 10 10 using HeuristicLab.Problems.QuadraticAssignment; 11 using HeuristicLab.Random; 11 12 12 13 namespace ProblemInstanceIdentifier { … … 18 19 }; 19 20 static void Main(string[] args) { 21 var instances = Get20DifferentClasses(); 22 //var instances = GetSomeRandomInstances(50); 23 24 /*var classes = instances.Select(InstanceDescriptor.FromProblemOnly).GroupBy(x => x.Cls); 25 foreach (var cls in classes.OrderBy(x => x.Key)) { 26 Console.WriteLine("{0};{1}", cls.Key, cls.Count()); 27 }*/ 28 29 var prExplorer = new PathRelinkingExplorer() { 30 LocalOptima = false, 31 Paths = 200 32 }; 33 var prLocalExplorer = new PathRelinkingExplorer() { 34 LocalOptima = true, 35 Paths = 200 36 }; 37 var memPrExplorer = new MemPRExplorer() { 38 IncludeLocalSearch = false, 39 Seconds = 10 40 }; 41 42 var training = GenerateData(instances, prExplorer, parallel:true); 43 var standardizer = InstancesStandardizer.CreateAndApply(training); 44 var test = GenerateData(instances, prExplorer, parallel: false); 45 standardizer.Apply(test); 46 PrintMatchResult(Compare(training, test)); 47 48 ExploreMatching(instances, new [] { prLocalExplorer }, new [] { memPrExplorer }); 49 } 50 51 private static List<QuadraticAssignmentProblem> GetSomeRandomInstances(int totalInstances) { 52 var sync = new object(); 53 var provider = new OneSizeInstanceProvider(); 54 var instances = new List<QuadraticAssignmentProblem>(); 55 var random = new FastRandom(0); 56 Parallel.ForEach(provider.GetDataDescriptors().Shuffle(random), desc => { 57 var qapData = provider.LoadData(desc); 58 if (qapData.Dimension < 25) return; 59 if (instances.Count >= totalInstances) return; 60 var qap = new QuadraticAssignmentProblem(); 61 qap.Load(qapData); 62 lock (sync) { 63 if (instances.Count >= totalInstances) return; 64 instances.Add(qap); 65 } 66 }); 67 return instances; 68 } 69 70 private static List<QuadraticAssignmentProblem> Get20DifferentClasses() { 20 71 var sync = new object(); 21 72 … … 36 87 }); 37 88 } 38 39 /*var classes = instances.Select(InstanceDescriptor.FromProblemOnly).GroupBy(x => x.Cls); 40 foreach (var cls in classes.OrderBy(x => x.Key)) { 41 Console.WriteLine("{0};{1}", cls.Key, cls.Count()); 42 }*/ 43 44 //var kb = GenerateKnowledgeBase(instances, 200, localOptima: false); 45 46 47 //var paths = new[] { 1, 2, 3, 5, 10, 20, 30, 50, 100, 200 }; 48 //var kbExplorers = paths.Select(x => new PathRelinkingExplorer() { Paths = x }).ToArray(); 49 //var expExplorers = paths.Select(x => new PathRelinkingExplorer() { Paths = x }).ToArray(); 50 //ExploreSelfIdentification(instances, kbExplorers, expExplorers); 51 52 var iterations = new[] { 100, 1000, 10000, 100000 }; 53 var kbExplorers = iterations.Select(x => new RandomWalkExplorer() { Iterations = x }).ToArray(); 54 var expExplorers = iterations.Select(x => new RandomWalkExplorer() { Iterations = x }).ToArray(); 55 ExploreSelfIdentification(instances, kbExplorers, expExplorers); 56 57 //ExploreMemPrIdentification(instances); 58 } 59 60 private static List<InstanceDescriptor> GenerateKnowledgeBase(List<QuadraticAssignmentProblem> instances, InstanceExplorer explorer) { 61 var headerPrinted = false; 62 var sync = new object(); 63 var kb = new List<InstanceDescriptor>(); 64 Parallel.ForEach(instances.OrderBy(x => x.Weights.Rows), qap => { 89 return instances; 90 } 91 92 private static List<InstanceDescriptor> GenerateData(List<QuadraticAssignmentProblem> instances, InstanceExplorer explorer, bool parallel = false) { 93 var sync = new object(); 94 var data = new List<InstanceDescriptor>(); 95 Action<QuadraticAssignmentProblem> body = (qap) => { 65 96 var instance = explorer.Explore(qap); 66 lock (sync) { 67 if (!headerPrinted) { 68 headerPrinted = true; 69 Console.WriteLine(string.Join(";", 70 new [] { "Name", "Cls", "Dimension" } 71 .Concat(instance.FeatureNames))); 72 } 73 PrintInstanceLine(instance); 74 kb.Add(instance); 75 } 76 }); 77 var standardizer = InstancesStandardizer.Create(kb); 78 var normalizedKb = kb.Select(x => new InstanceDescriptor(x)).ToList(); 79 standardizer.Apply(normalizedKb); 80 Console.WriteLine(); 81 foreach (var instance in kb) { 82 PrintInstanceLine(instance); 83 } 84 //return normalizedKb; 85 return kb; 97 if (instance == null) return; 98 lock (sync) { 99 data.Add(instance); 100 } 101 }; 102 if (parallel) { 103 Parallel.ForEach(instances, body); 104 } else { 105 foreach (var qap in instances) body(qap); 106 } 107 return data; 108 } 109 110 private static MatchResult Compare(List<InstanceDescriptor> training, List<InstanceDescriptor> test) { 111 int exactCount = 0, clsCount = 0, totalCount = 0; 112 int exactRank = 0, clsRank = 0; 113 foreach (var e in test) { 114 var ordered = training.OrderBy(x => x.CalculateSimilarity(e)).ToList(); 115 var bestMatch = ordered.First(); 116 if (bestMatch.Cls == e.Cls) clsCount++; 117 if (bestMatch.Name == e.Name) exactCount++; 118 totalCount++; 119 clsRank += ordered.FindIndex((id) => id.Cls == e.Cls) + 1; 120 exactRank += ordered.FindIndex((id) => id.Name == e.Name) + 1; 121 } 122 123 return new MatchResult() { 124 ExactCount = exactCount, 125 ClsCount = clsCount, 126 TotalCount = totalCount, 127 ExactAverageRank = exactRank / (double)totalCount, 128 ClsAverageRank = clsRank / (double)totalCount 129 }; 130 } 131 132 private static void PrintMatchResult(MatchResult result) { 133 Console.WriteLine("{0}\t{1}\t{2}\t{3:F2}\t{4:F2}", 134 result.ExactCount, result.ClsCount, result.TotalCount, 135 result.ExactAverageRank, result.ClsAverageRank); 136 } 137 138 private static void PrintData(List<InstanceDescriptor> instances) { 139 using (var iter = instances.GetEnumerator()) { 140 if (!iter.MoveNext()) return; 141 Console.WriteLine(string.Join(";", new[] {"Name", "Cls", "Dimension"} 142 .Concat(iter.Current != null ? iter.Current.FeatureNames : new [] { "(null)" }))); 143 do { 144 PrintInstanceLine(iter.Current); 145 } while (iter.MoveNext()); 146 } 86 147 } 87 148 … … 92 153 } 93 154 94 private static void ExploreSelfIdentification(List<QuadraticAssignmentProblem> instances, InstanceExplorer[] kbExplorer, InstanceExplorer[] expExporer) { 95 var sync = new object(); 96 Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", "Repetition", "KB-Effort", "Exp-Effort", 97 "Exact-Hits", "No-Hits", "Exact-Rank"); 98 var kbSeeds = Enumerable.Range(0, 20).ToList(); 99 var expSeeds = Enumerable.Range(20, 20).ToList(); 100 for (var r = 0; r < 10; r++) { 101 var rlokal = r; 102 Parallel.ForEach(kbExplorer, kbPaths => { 103 //foreach (var kbPaths in kbExplorer) { 104 foreach (var expPaths in expExporer) { 105 //if (expPaths > kbPaths) continue; 106 var kb = new List<InstanceDescriptor>(); 107 var exp = new List<InstanceDescriptor>(); 108 foreach (var qap in instances) { 109 kb.Add(kbPaths.Explore(qap, kbSeeds[rlokal])); 110 exp.Add(expPaths.Explore(qap, expSeeds[rlokal])); 111 } 112 var standardizer = InstancesStandardizer.Create(kb); 113 standardizer.Apply(kb); 114 standardizer.Apply(exp); 115 int exactCount = 0, clsCount = 0, missedCount = 0; 116 int exactRank = 0, clsRank = 0; 117 foreach (var e in exp) { 118 var ordered = kb.OrderBy(x => x.CalculateSimilarity(e)).ToList(); 119 var bestMatch = ordered.First(); 120 if (bestMatch.Cls == e.Cls) { 121 clsCount++; 122 if (bestMatch.Name == e.Name) exactCount++; 123 } 124 else missedCount++; 125 clsRank += ordered.FindIndex((id) => id.Cls == e.Cls) + 1; 126 exactRank += ordered.FindIndex((id) => id.Name == e.Name) + 1; 127 } 128 lock (sync) { 129 Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5:F2}", rlokal, kbPaths.Effort, expPaths.Effort, exactCount, 130 missedCount, exactRank / (double) exp.Count); 131 } 155 private static void ExploreMatching(List<QuadraticAssignmentProblem> instances, InstanceExplorer[] trainingExplorers, InstanceExplorer[] testExporers, bool parallel = false) { 156 var sync = new object(); 157 var rand = new Random(); 158 var first = rand.Next(); 159 var second = rand.Next(); 160 while (first == second) second = rand.Next(); 161 162 var knowledgeBase = new Dictionary<InstanceExplorer, Tuple<InstancesStandardizer, List<InstanceDescriptor>>>(); 163 Action<InstanceExplorer> trainingBody = (kbExplorer) => { 164 var trainingData = GenerateData(instances, kbExplorer, parallel); 165 var standardizer = InstancesStandardizer.Create(trainingData); 166 standardizer.Apply(trainingData); 167 lock (sync) { 168 knowledgeBase.Add(kbExplorer, Tuple.Create(standardizer, trainingData)); 169 } 170 }; 171 if (parallel) { 172 Parallel.ForEach(trainingExplorers, trainingBody); 173 } else { 174 foreach (var kbExplorer in trainingExplorers) trainingBody(kbExplorer); 175 } 176 177 var experimentBase = new Dictionary<InstanceExplorer, List<InstanceDescriptor>>(); 178 Action<InstanceExplorer> testBody = (expExplorer) => { 179 var trainingData = GenerateData(instances, expExplorer, parallel); 180 lock (sync) { 181 experimentBase.Add(expExplorer, trainingData); 182 } 183 }; 184 if (parallel) { 185 Parallel.ForEach(testExporers, testBody); 186 } else { 187 foreach (var expExplorer in testExporers) testBody(expExplorer); 188 } 189 190 var data = from kb in knowledgeBase 191 from exp in experimentBase 192 select new { Training = kb, Test = exp }; 193 194 if (parallel) { 195 Parallel.ForEach(data, (point) => { 196 var normalizedTest = point.Test.Value.Select(x => new InstanceDescriptor(x)).ToList(); 197 point.Training.Value.Item1.Apply(normalizedTest); 198 var result = Compare(point.Training.Value.Item2, normalizedTest); 199 lock (sync) { 200 Console.WriteLine("{0}\t{1}\t{2}\t{3:F2}\t{4}\t{5:F2}\t{6}", 201 point.Training.Key.Effort, point.Test.Key.Effort, result.ExactCount, 202 result.ExactAverageRank, result.ClsCount, result.ClsAverageRank, result.TotalCount); 132 203 } 133 204 }); 134 //} 135 } 136 } 137 138 private static void ExploreMemPrIdentification(List<QuadraticAssignmentProblem> instances) { 139 var sync = new object(); 140 Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", "Repetition", "KB-Runtime", "Exp-Runtime", 141 "Exact-Hits", "No-Hits", "Average-Rank"); 142 var paths = new[] { 10 }; 143 var repetitions = 10; 144 var kbSeeds = Enumerable.Range(0, repetitions).ToList(); 145 var expSeeds = Enumerable.Range(repetitions, repetitions).ToList(); 146 for (var r = 0; r < repetitions; r++) { 147 var rlokal = r; 148 Parallel.ForEach(paths, kbPaths => { 149 var memPr = new PermutationMemPR(); 150 foreach (var expPaths in paths) { 151 //if (expPaths > kbPaths) continue; 152 var kb = new List<InstanceDescriptor>(); 153 var exp = new List<InstanceDescriptor>(); 154 foreach (var qap in instances.Select(x => (QuadraticAssignmentProblem)x.Clone())) { 155 memPr.Problem = qap; 156 memPr.Prepare(true); 157 memPr.Seed = kbSeeds[rlokal]; 158 memPr.MaximumExecutionTime = TimeSpan.FromSeconds(kbPaths); 159 memPr.StartSync(); 160 if (memPr.Context.RelinkedPaths.IsEmpty) continue; 161 kb.Add(InstanceDescriptor.FromPaths(qap, memPr.Context.RelinkedPaths.Paths.ToList())); 162 memPr.Prepare(true); 163 memPr.Seed = expSeeds[rlokal]; 164 memPr.MaximumExecutionTime = TimeSpan.FromSeconds(expPaths); 165 memPr.StartSync(); 166 if (memPr.Context.RelinkedPaths.IsEmpty) continue; 167 exp.Add(InstanceDescriptor.FromPaths(qap, memPr.Context.RelinkedPaths.Paths.ToList())); 168 } 169 var standardizer = InstancesStandardizer.Create(kb); 170 standardizer.Apply(kb); 171 standardizer.Apply(exp); 172 int exactCount = 0, clsCount = 0, missedCount = 0; 173 int exactRank = 0, clsRank = 0; 174 foreach (var e in exp) { 175 var ordered = kb.OrderBy(x => x.CalculateSimilarity(e)).ToList(); 176 var bestMatch = ordered.First(); 177 if (bestMatch.Cls == e.Cls) { 178 clsCount++; 179 if (bestMatch.Name == e.Name) exactCount++; 180 } else missedCount++; 181 clsRank += ordered.FindIndex((id) => id.Cls == e.Cls) + 1; 182 exactRank += ordered.FindIndex((id) => id.Name == e.Name) + 1; 183 } 184 lock (sync) { 185 Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5:F2}", rlokal, kbPaths, expPaths, exactCount, 186 missedCount, exactRank / (double)exp.Count); 187 } 188 } 189 }); 190 } 205 } else { 206 foreach (var point in data) { 207 var normalizedTest = point.Test.Value.Select(x => new InstanceDescriptor(x)).ToList(); 208 point.Training.Value.Item1.Apply(normalizedTest); 209 var result = Compare(point.Training.Value.Item2, normalizedTest); 210 Console.WriteLine("{0}\t{1}\t{2}\t{3:F2}\t{4}\t{5:F2}\t{6}", 211 point.Training.Key.Effort, point.Test.Key.Effort, result.ExactCount, 212 result.ExactAverageRank, result.ClsCount, result.ClsAverageRank, result.TotalCount); 213 } 214 } 215 } 216 217 private class MatchResult { 218 public int ExactCount { get; set; } 219 public int ClsCount { get; set; } 220 public int TotalCount { get; set; } 221 public double ExactAverageRank { get; set; } 222 public double ClsAverageRank { get; set; } 191 223 } 192 224 }
Note: See TracChangeset
for help on using the changeset viewer.