Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/10/14 10:31:41 (9 years ago)
Author:
pfleck
Message:

#2269 Merged trunk. Updated .net version of ALPS plugin.

Location:
branches/ALPS
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/ALPS

  • branches/ALPS/HeuristicLab.Analysis

  • branches/ALPS/HeuristicLab.Analysis/3.3/BestScopeSolutionAnalyzer.cs

    r11171 r11677  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3738  [StorableClass]
    3839  public class BestScopeSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     40
    3941    public virtual bool EnabledByDefault {
    4042      get { return true; }
    4143    }
    42 
    4344    public LookupParameter<BoolValue> MaximizationParameter {
    4445      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    4748      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4849    }
    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"]; }
    5452    }
    5553    public ILookupParameter<DoubleValue> BestKnownQualityParameter {
     
    5856    public IValueLookupParameter<ResultCollection> ResultsParameter {
    5957      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     58    }
     59
     60    public string BestSolutionResultName {
     61      get { return BestSolutionResultNameParameter.Value.Value; }
     62      set { BestSolutionResultNameParameter.Value.Value = value; }
    6063    }
    6164
     
    6770      return new BestScopeSolutionAnalyzer(this, cloner);
    6871    }
     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    }
    6978    #endregion
    7079    public BestScopeSolutionAnalyzer()
     
    7281      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    7382      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")));
    7684      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
    7785      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the solution should be stored."));
     
    8492      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    8593
     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
    8698      int i = -1;
    8799      if (!max)
     
    91103      IEnumerable<IScope> scopes = new IScope[] { ExecutionContext.Scope };
    92104      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);
    94106      IScope currentBestScope = scopes.ToList()[i];
    95107
     
    98110          || !max && qualities[i].Value < bestKnownQuality.Value) {
    99111        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    100         BestKnownSolutionParameter.ActualValue = (IScope)currentBestScope.Clone();
    101112      }
    102113
    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));
    108121      } else {
     122        var bestSolution = (IScope)results[BestSolutionResultName].Value;
    109123        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;
    117134          }
    118135        }
    119136      }
    120 
    121137      return base.Apply();
    122138    }
  • branches/ALPS/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r9288 r11677  
    1111    <RootNamespace>HeuristicLab.Analysis</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Analysis-3.3</AssemblyName>
    13     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    1414    <TargetFrameworkProfile>
    1515    </TargetFrameworkProfile>
     
    4646    <WarningLevel>4</WarningLevel>
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     48    <Prefer32Bit>false</Prefer32Bit>
    4849  </PropertyGroup>
    4950  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    5758    </DocumentationFile>
    5859    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     60    <Prefer32Bit>false</Prefer32Bit>
    5961  </PropertyGroup>
    6062  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     
    6668    <ErrorReport>prompt</ErrorReport>
    6769    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     70    <Prefer32Bit>false</Prefer32Bit>
    6871  </PropertyGroup>
    6972  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     
    7780    <ErrorReport>prompt</ErrorReport>
    7881    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     82    <Prefer32Bit>false</Prefer32Bit>
    7983  </PropertyGroup>
    8084  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
     
    8690    <ErrorReport>prompt</ErrorReport>
    8791    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     92    <Prefer32Bit>false</Prefer32Bit>
    8893  </PropertyGroup>
    8994  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
     
    97102    <ErrorReport>prompt</ErrorReport>
    98103    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     104    <Prefer32Bit>false</Prefer32Bit>
    99105  </PropertyGroup>
    100106  <ItemGroup>
     
    153159    <Compile Include="QualityAnalysis\QualityDistributionAnalyzer.cs" />
    154160    <Compile Include="QualityAnalysis\ScaledQualityDifferenceAnalyzer.cs" />
     161    <Compile Include="Statistics\NormalDistribution.cs" />
    155162    <Compile Include="ValueAnalysis\SingleValueAnalyzer.cs" />
    156163    <Compile Include="ValueAnalysis\MinAverageMaxValueAnalyzer.cs" />
     
    236243    </BootstrapperPackage>
    237244  </ItemGroup>
     245  <ItemGroup />
    238246  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    239247  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
     
    245253  -->
    246254  <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)
    248256set ProjectDir=$(ProjectDir)
    249257set SolutionDir=$(SolutionDir)
     
    252260call PreBuildEvent.cmd
    253261</PreBuildEvent>
    254 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     262    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
    255263export ProjectDir=$(ProjectDir)
    256264export SolutionDir=$(SolutionDir)
Note: See TracChangeset for help on using the changeset viewer.