Changeset 11677 for branches/ALPS/HeuristicLab.Analysis
- Timestamp:
- 12/10/14 10:31:41 (10 years ago)
- Location:
- branches/ALPS
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS
-
branches/ALPS/HeuristicLab.Analysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Analysis (added) merged: 11610,11615,11618,11623
- Property svn:mergeinfo changed
-
branches/ALPS/HeuristicLab.Analysis/3.3/BestScopeSolutionAnalyzer.cs
r11171 r11677 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 37 38 [StorableClass] 38 39 public class BestScopeSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 40 39 41 public virtual bool EnabledByDefault { 40 42 get { return true; } 41 43 } 42 43 44 public LookupParameter<BoolValue> MaximizationParameter { 44 45 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } … … 47 48 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 48 49 } 49 public ILookupParameter<IScope> BestSolutionParameter { 50 get { return (ILookupParameter<IScope>)Parameters["BestSolution"]; } 51 } 52 public ILookupParameter<IScope> BestKnownSolutionParameter { 53 get { return (ILookupParameter<IScope>)Parameters["BestKnownSolution"]; } 50 public IFixedValueParameter<StringValue> BestSolutionResultNameParameter { 51 get { return (IFixedValueParameter<StringValue>)Parameters["BestSolution ResultName"]; } 54 52 } 55 53 public ILookupParameter<DoubleValue> BestKnownQualityParameter { … … 58 56 public IValueLookupParameter<ResultCollection> ResultsParameter { 59 57 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 58 } 59 60 public string BestSolutionResultName { 61 get { return BestSolutionResultNameParameter.Value.Value; } 62 set { BestSolutionResultNameParameter.Value.Value = value; } 60 63 } 61 64 … … 67 70 return new BestScopeSolutionAnalyzer(this, cloner); 68 71 } 72 73 [StorableHook(HookType.AfterDeserialization)] 74 private void AfterDeserialization() { 75 if (!Parameters.ContainsKey("BestSolution ResultName")) 76 Parameters.Add(new FixedValueParameter<StringValue>("BestSolution ResultName", "The name of the result for storing the best solution.", new StringValue("Best Solution"))); 77 } 69 78 #endregion 70 79 public BestScopeSolutionAnalyzer() … … 72 81 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 73 82 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the solutions.")); 74 Parameters.Add(new LookupParameter<IScope>("BestSolution", "The best solution.")); 75 Parameters.Add(new LookupParameter<IScope>("BestKnownSolution", "The best known solution.")); 83 Parameters.Add(new FixedValueParameter<StringValue>("BestSolution ResultName", "The name of the result for storing the best solution.", new StringValue("Best Solution"))); 76 84 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); 77 85 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the solution should be stored.")); … … 84 92 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 85 93 94 if (results.ContainsKey(BestSolutionResultName) && !typeof(IScope).IsAssignableFrom(results[BestSolutionResultName].DataType)) { 95 throw new InvalidOperationException(string.Format("Could not add best solution result, because there is already a result with the name \"{0}\" present in the result collection.", BestSolutionResultName)); 96 } 97 86 98 int i = -1; 87 99 if (!max) … … 91 103 IEnumerable<IScope> scopes = new IScope[] { ExecutionContext.Scope }; 92 104 for (int j = 0; j < QualityParameter.Depth; j++) 93 scopes = scopes.Select (x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));105 scopes = scopes.SelectMany(x => x.SubScopes); 94 106 IScope currentBestScope = scopes.ToList()[i]; 95 107 … … 98 110 || !max && qualities[i].Value < bestKnownQuality.Value) { 99 111 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 100 BestKnownSolutionParameter.ActualValue = (IScope)currentBestScope.Clone();101 112 } 102 113 103 IScope solution = BestSolutionParameter.ActualValue; 104 if (solution == null) { 105 solution = (IScope)currentBestScope.Clone(); 106 BestSolutionParameter.ActualValue = solution; 107 results.Add(new Result("Best Solution", solution)); 114 if (!results.ContainsKey(BestSolutionResultName)) { 115 var cloner = new Cloner(); 116 //avoid cloning of subscopes 117 cloner.RegisterClonedObject(currentBestScope.SubScopes, new ScopeList()); 118 var solution = cloner.Clone(currentBestScope); 119 120 results.Add(new Result(BestSolutionResultName, solution)); 108 121 } else { 122 var bestSolution = (IScope)results[BestSolutionResultName].Value; 109 123 string qualityName = QualityParameter.TranslatedName; 110 if (solution.Variables.ContainsKey(qualityName)) { 111 double bestSoFarQuality = (solution.Variables[qualityName].Value as DoubleValue).Value; 112 if (max && qualities[i].Value > bestSoFarQuality 113 || !max && qualities[i].Value < bestSoFarQuality) { 114 solution = (IScope)currentBestScope.Clone(); 115 BestSolutionParameter.ActualValue = solution; 116 results["Best Solution"].Value = solution; 124 if (bestSolution.Variables.ContainsKey(qualityName)) { 125 double bestQuality = ((DoubleValue)bestSolution.Variables[qualityName].Value).Value; 126 if (max && qualities[i].Value > bestQuality 127 || !max && qualities[i].Value < bestQuality) { 128 var cloner = new Cloner(); 129 //avoid cloning of subscopes 130 cloner.RegisterClonedObject(currentBestScope.SubScopes, new ScopeList()); 131 var solution = cloner.Clone(currentBestScope); 132 133 results[BestSolutionResultName].Value = solution; 117 134 } 118 135 } 119 136 } 120 121 137 return base.Apply(); 122 138 } -
branches/ALPS/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj
r9288 r11677 11 11 <RootNamespace>HeuristicLab.Analysis</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Analysis-3.3</AssemblyName> 13 <TargetFrameworkVersion>v4. 0</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> 14 14 <TargetFrameworkProfile> 15 15 </TargetFrameworkProfile> … … 46 46 <WarningLevel>4</WarningLevel> 47 47 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 48 <Prefer32Bit>false</Prefer32Bit> 48 49 </PropertyGroup> 49 50 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 57 58 </DocumentationFile> 58 59 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 60 <Prefer32Bit>false</Prefer32Bit> 59 61 </PropertyGroup> 60 62 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> … … 66 68 <ErrorReport>prompt</ErrorReport> 67 69 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 70 <Prefer32Bit>false</Prefer32Bit> 68 71 </PropertyGroup> 69 72 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> … … 77 80 <ErrorReport>prompt</ErrorReport> 78 81 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 82 <Prefer32Bit>false</Prefer32Bit> 79 83 </PropertyGroup> 80 84 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> … … 86 90 <ErrorReport>prompt</ErrorReport> 87 91 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 92 <Prefer32Bit>false</Prefer32Bit> 88 93 </PropertyGroup> 89 94 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> … … 97 102 <ErrorReport>prompt</ErrorReport> 98 103 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 104 <Prefer32Bit>false</Prefer32Bit> 99 105 </PropertyGroup> 100 106 <ItemGroup> … … 153 159 <Compile Include="QualityAnalysis\QualityDistributionAnalyzer.cs" /> 154 160 <Compile Include="QualityAnalysis\ScaledQualityDifferenceAnalyzer.cs" /> 161 <Compile Include="Statistics\NormalDistribution.cs" /> 155 162 <Compile Include="ValueAnalysis\SingleValueAnalyzer.cs" /> 156 163 <Compile Include="ValueAnalysis\MinAverageMaxValueAnalyzer.cs" /> … … 236 243 </BootstrapperPackage> 237 244 </ItemGroup> 245 <ItemGroup /> 238 246 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 239 247 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. … … 245 253 --> 246 254 <PropertyGroup> 247 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)255 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 248 256 set ProjectDir=$(ProjectDir) 249 257 set SolutionDir=$(SolutionDir) … … 252 260 call PreBuildEvent.cmd 253 261 </PreBuildEvent> 254 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">262 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 255 263 export ProjectDir=$(ProjectDir) 256 264 export SolutionDir=$(SolutionDir)
Note: See TracChangeset
for help on using the changeset viewer.