Changeset 14133


Ignore:
Timestamp:
07/20/16 18:02:08 (13 months ago)
Author:
mkommend
Message:

#2281: Merged r14037,r14056,r14057,r14071, r14100 into stable.

Location:
stable
Files:
3 deleted
9 edited
3 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization

  • stable/HeuristicLab.Optimization.Views

  • stable/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r13282 r14133  
    160160      <DependentUpon>ExperimentListView.cs</DependentUpon>
    161161    </Compile>
     162    <Compile Include="ResultParameterView.cs">
     163      <SubType>UserControl</SubType>
     164    </Compile>
     165    <Compile Include="ResultParameterView.Designer.cs">
     166      <DependentUpon>ResultParameterView.cs</DependentUpon>
     167    </Compile>
    162168    <Compile Include="MultiEncodingView.cs">
    163169      <SubType>UserControl</SubType>
     
    399405      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    400406      <Name>HeuristicLab.Optimization-3.3</Name>
     407      <Private>False</Private>
     408    </ProjectReference>
     409    <ProjectReference Include="..\..\HeuristicLab.Parameters.Views\3.3\HeuristicLab.Parameters.Views-3.3.csproj">
     410      <Project>{ae5b1ce5-9862-4d6f-a700-d72cd9aea295}</Project>
     411      <Name>HeuristicLab.Parameters.Views-3.3</Name>
     412      <Private>False</Private>
     413    </ProjectReference>
     414    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     415      <Project>{56f9106a-079f-4c61-92f6-86a84c2d84b7}</Project>
     416      <Name>HeuristicLab.Parameters-3.3</Name>
    401417      <Private>False</Private>
    402418    </ProjectReference>
  • stable/HeuristicLab.Optimization.Views/3.3/Plugin.cs.frame

    r13316 r14133  
    3939  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
    4040  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     41  [PluginDependency("HeuristicLab.Parameters.Views", "3.3")]
    4142  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    4243  [PluginDependency("HeuristicLab.Problems.Instances.Views", "3.3")]
  • stable/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r13282 r14133  
    155155    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
    156156    <Compile Include="Interfaces\IMultiObjectiveOperator.cs" />
     157    <Compile Include="Results\IResultParameter.cs" />
    157158    <Compile Include="Interfaces\ISingleObjectiveOperator.cs" />
    158159    <Compile Include="Interfaces\ISingleObjectivePathRelinker.cs" />
     
    168169    <Compile Include="MetaOptimizers\Experiment.cs" />
    169170    <Compile Include="MetaOptimizers\TimeLimitRun.cs" />
     171    <Compile Include="Results\ResultParameter.cs" />
    170172    <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" />
    171173    <Compile Include="Plugin.cs" />
     
    229231    <Compile Include="RunCollection.cs" />
    230232    <Compile Include="Run.cs" />
    231     <Compile Include="Interfaces\IResult.cs" />
     233    <Compile Include="Results\IResult.cs" />
    232234    <Compile Include="Interfaces\IDiscreteDoubleValueModifier.cs" />
    233235    <Compile Include="Interfaces\IExhaustiveMoveGenerator.cs" />
     
    253255    <Compile Include="Interfaces\ITabuChecker.cs" />
    254256    <Compile Include="Interfaces\ITabuMaker.cs" />
    255     <Compile Include="Result.cs" />
     257    <Compile Include="Results\Result.cs" />
    256258    <Compile Include="Algorithms\UserDefinedAlgorithm.cs" />
    257259    <Compile Include="Algorithms\EngineAlgorithm.cs" />
    258260    <Compile Include="Properties\AssemblyInfo.cs" />
    259     <Compile Include="ResultCollection.cs" />
     261    <Compile Include="Results\ResultCollection.cs" />
    260262    <Compile Include="Problems\UserDefinedProblem.cs" />
    261263  </ItemGroup>
  • stable/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

    r14071 r14133  
    3333  public sealed class ResultParameter<T> : LookupParameter<T>, IResultParameter<T> where T : class, IItem {
    3434    public override Image ItemImage { get { return VSImageLibrary.Exception; } }
     35    public override bool CanChangeDescription { get { return true; } }
    3536
    3637    [Storable]
     
    7172    }
    7273    public ResultParameter() : this("Anonymous", string.Empty, "Results") { }
    73     public ResultParameter(string name) : this(name, string.Empty, "Results") { }
    7474    public ResultParameter(string name, string description) : this(name, description, "Results") { }
     75
    7576    public ResultParameter(string name, string description, string resultCollectionName)
    7677      : base(name, description, string.Empty) {
    7778      if (string.IsNullOrEmpty(resultCollectionName)) throw new ArgumentException("resultCollectionName");
    7879      this.resultCollectionName = resultCollectionName;
     80      Hidden = false;
    7981    }
    8082    public ResultParameter(string name, string description, string resultCollectionName, T defaultValue)
     
    8486      this.resultCollectionName = resultCollectionName;
    8587      this.defaultValue = defaultValue;
     88      Hidden = false;
    8689    }
    8790
     
    102105      if (!results.TryGetValue(ActualName, out result)) {
    103106        if (DefaultValue == null) throw new InvalidOperationException("ResultParameter (" + ActualName + "): Result not found and no default value specified.");
    104         result = new Result(ActualName, (T)DefaultValue.Clone());
     107        result = ItemDescription == Description ? new Result(ActualName, (T)DefaultValue.Clone()) : new Result(ActualName, Description, (T)DefaultValue.Clone());
    105108        results.Add(result);
    106109      }
     
    127130      IResult result;
    128131      if (!results.TryGetValue(ActualName, out result)) {
    129         result = new Result(ActualName, value);
     132        result = ItemDescription == Description ? new Result(ActualName, value) : new Result(ActualName, Description, value);
    130133        results.Add(result);
    131134      } else result.Value = value;
  • stable/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

    r11920 r14133  
    217217      <Private>False</Private>
    218218    </ProjectReference>
    219     <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">
    220       <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>
    221       <Name>HeuristicLab.Optimization.Views-3.3</Name>
    222       <Private>False</Private>
    223     </ProjectReference>
    224     <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    225       <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    226       <Name>HeuristicLab.Optimization-3.3</Name>
    227       <Private>False</Private>
    228     </ProjectReference>
    229219    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
    230220      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
  • stable/HeuristicLab.Parameters/3.3/LookupParameter.cs

    r12009 r14133  
    5050    public string TranslatedName {
    5151      get {
    52         string translatedName;
    53         GetValueParameterAndTranslateName(out translatedName);
     52        string translatedName = Name;
     53        GetValueParameterAndTranslateName(ExecutionContext, ref translatedName);
    5454        return translatedName;
    5555      }
     
    6161
    6262    private Lazy<ThreadLocal<IItem>> cachedActualValues;
    63     private IItem CachedActualValue {
     63    protected IItem CachedActualValue {
    6464      get { return cachedActualValues.Value.Value; }
     65      set { cachedActualValues.Value.Value = value; }
    6566    }
    6667
     
    128129    }
    129130
    130     private IValueParameter GetValueParameterAndTranslateName(out string actualName) {
     131    protected static IValueParameter GetValueParameterAndTranslateName(IExecutionContext executionContext, ref string translatedName) {
    131132      IValueParameter valueParam;
    132133      ILookupParameter lookupParam;
    133       IExecutionContext currentExecutionContext = ExecutionContext;
    134 
    135       actualName = Name;
     134      IExecutionContext currentExecutionContext = executionContext;
     135
    136136      while (currentExecutionContext != null) {
    137         valueParam = currentExecutionContext.Parameters[actualName] as IValueParameter;
    138         lookupParam = currentExecutionContext.Parameters[actualName] as ILookupParameter;
     137        IParameter param = null;
     138        while (currentExecutionContext != null && !currentExecutionContext.Parameters.TryGetValue(translatedName, out param))
     139          currentExecutionContext = currentExecutionContext.Parent;
     140        if (currentExecutionContext == null) break;
     141
     142        valueParam = param as IValueParameter;
     143        lookupParam = param as ILookupParameter;
    139144
    140145        if ((valueParam == null) && (lookupParam == null))
    141146          throw new InvalidOperationException(
    142147            string.Format("Parameter look-up chain broken. Parameter \"{0}\" is not an \"{1}\" or an \"{2}\".",
    143                           actualName, typeof(IValueParameter).GetPrettyName(), typeof(ILookupParameter).GetPrettyName())
     148                          translatedName, typeof(IValueParameter).GetPrettyName(), typeof(ILookupParameter).GetPrettyName())
    144149          );
    145150
     
    148153          else if (lookupParam == null) return valueParam;
    149154        }
    150         if (lookupParam != null) actualName = lookupParam.ActualName;
     155        translatedName = lookupParam.ActualName;
    151156
    152157        currentExecutionContext = currentExecutionContext.Parent;
    153         while ((currentExecutionContext != null) && !currentExecutionContext.Parameters.ContainsKey(actualName))
    154           currentExecutionContext = currentExecutionContext.Parent;
    155158      }
    156159      return null;
    157160    }
    158     private IVariable LookupVariable(string name) {
    159       IScope scope = ExecutionContext.Scope;
    160       while ((scope != null) && !scope.Variables.ContainsKey(name))
     161    protected static IVariable LookupVariable(IScope scope, string name) {
     162      IVariable variable = null;
     163      while (scope != null && !scope.Variables.TryGetValue(name, out variable))
    161164        scope = scope.Parent;
    162       return scope != null ? scope.Variables[name] : null;
    163     }
     165      return scope != null ? variable : null;
     166    }
     167
    164168    protected override IItem GetActualValue() {
    165169      if (CachedActualValue != null) return CachedActualValue;
    166       string name;
     170
     171      string translatedName = Name;
     172      var value = GetValue(ExecutionContext, ref translatedName);
     173      if (value != null && !(value is T))
     174        throw new InvalidOperationException(
     175          string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
     176                        translatedName,
     177                        typeof(T).GetPrettyName())
     178        );
     179      CachedActualValue = value;
     180      return value;
     181    }
     182
     183    protected static IItem GetValue(IExecutionContext executionContext, ref string name) {
    167184      // try to get value from context stack
    168       IValueParameter param = GetValueParameterAndTranslateName(out name);
     185      IValueParameter param = GetValueParameterAndTranslateName(executionContext, ref name);
    169186      if (param != null) return param.Value;
    170187
    171188      // try to get variable from scope
    172       IVariable var = LookupVariable(name);
    173       if (var != null) {
    174         if (!(var.Value is T))
    175           throw new InvalidOperationException(
    176             string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
    177                           name,
    178                           typeof(T).GetPrettyName())
    179           );
    180         cachedActualValues.Value.Value = var.Value;
    181         return var.Value;
    182       }
    183       return null;
    184     }
     189      IVariable var = LookupVariable(executionContext.Scope, name);
     190      return var != null ? var.Value : null;
     191    }
     192
    185193    protected override void SetActualValue(IItem value) {
    186194      if (!(value is T))
     
    189197                        typeof(T).GetPrettyName())
    190198        );
    191       cachedActualValues.Value.Value = value;
    192 
     199      CachedActualValue = value;
     200
     201      string translatedName = Name;
     202      SetValue(ExecutionContext, ref translatedName, value);
     203    }
     204
     205    protected static void SetValue(IExecutionContext executionContext, ref string name, IItem value) {
    193206      // try to set value in context stack
    194       string name;
    195       IValueParameter param = GetValueParameterAndTranslateName(out name);
     207      IValueParameter param = GetValueParameterAndTranslateName(executionContext, ref name);
    196208      if (param != null) {
    197209        param.Value = value;
     
    200212
    201213      // try to set value in scope
    202       IVariable var = LookupVariable(name);
     214      IVariable var = LookupVariable(executionContext.Scope, name);
    203215      if (var != null) {
    204216        var.Value = value;
     
    207219
    208220      // create new variable
    209       ExecutionContext.Scope.Variables.Add(new Variable(name, value));
     221      executionContext.Scope.Variables.Add(new Variable(name, value));
    210222    }
    211223
Note: See TracChangeset for help on using the changeset viewer.