Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs @ 6018

Last change on this file since 6018 was 6018, checked in by cneumuel, 12 years ago

#1215

  • support for maximization problems
  • made base level algorithms stoppable
  • optimization for multiple goals possible (AverageQuality, AverageDeviation, AverageEvaluatedSolutions)
  • lots of fixes
File size: 24.7 KB
Line 
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Drawing;
5using System.Linq;
6using System.Text;
7using HeuristicLab.Collections;
8using HeuristicLab.Common;
9using HeuristicLab.Core;
10using HeuristicLab.Data;
11using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
12using HeuristicLab.Parameters;
13using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
14using HeuristicLab.PluginInfrastructure;
15
16namespace HeuristicLab.Problems.MetaOptimization {
17  [StorableClass]
18  public class ParameterConfiguration : Item, IParameterConfiguration, IStorableContent {
19    public bool IsOptimizable {
20      get { return true; }
21    }
22
23    [Storable]
24    public string Filename { get; set; }
25
26    [Storable]
27    protected bool optimize;
28    public virtual bool Optimize {
29      get { return optimize; }
30      set {
31        if (optimize != value) {
32          optimize = value;
33          if (optimize) {
34            PopulateValueConfigurations();
35          } else {
36            ClearValueConfigurations();
37          }
38          OnOptimizeChanged();
39          OnToStringChanged();
40        }
41      }
42    }
43
44    [Storable]
45    protected Image itemImage;
46    public override Image ItemImage {
47      get { return itemImage ?? base.ItemImage; }
48    }
49
50    [Storable]
51    protected string parameterName;
52    public string ParameterName {
53      get { return parameterName; }
54      set {
55        if (parameterName != value) {
56          parameterName = value;
57          OnToStringChanged();
58        }
59      }
60    }
61
62    [Storable]
63    protected Type parameterDataType;
64    public Type ParameterDataType {
65      get { return this.parameterDataType; }
66    }
67
68    [Storable]
69    protected Type[] validTypes;
70    public Type[] ValidTypes {
71      get { return validTypes; }
72      protected set {
73        if (this.validTypes != value) {
74          this.validTypes = value;
75        }
76      }
77    }
78
79    [Storable]
80    protected Type valueDataType;
81    public Type ValueDataType {
82      get { return valueDataType; }
83      protected set { this.valueDataType = value; }
84    }
85
86    [Storable]
87    protected ICheckedValueConfigurationList valueConfigurations;
88    public ICheckedValueConfigurationList ValueConfigurations {
89      get { return this.valueConfigurations; }
90      protected set {
91        if (this.valueConfigurations != value) {
92          if (this.valueConfigurations != null) DeregisterValueConfigurationEvents();
93          this.valueConfigurations = value;
94          KeepActualValueConfigurationIndexConsistent();
95          if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
96        }
97      }
98    }
99
100    [Storable]
101    private int actualValueConfigurationIndex = 0;
102    public int ActualValueConfigurationIndex {
103      get { return actualValueConfigurationIndex; }
104      set { actualValueConfigurationIndex = value; }
105    }
106
107    [Storable]
108    protected ConstrainedValue actualValue;
109    public ConstrainedValue ActualValue {
110      get { return actualValue; }
111      set {
112        if (actualValue != value) {
113          DeregisterActualValueEvents();
114          actualValue = value;
115          RegisterActualValueEvents();
116        }
117      }
118    }
119
120    [Storable]
121    protected bool isNullable;
122    public bool IsNullable {
123      get { return isNullable; }
124      protected set {
125        if (this.isNullable != value) {
126          this.isNullable = value;
127        }
128      }
129    }
130
131    [Storable]
132    protected bool discoverValidValues;
133    public bool DiscoverValidValues {
134      get { return discoverValidValues; }
135      set { discoverValidValues = value; }
136    }
137
138    [Storable]
139    protected IItemSet<IItem> validValues;
140
141    [Storable]
142    private bool autoPopulateValueConfigurations = true;
143    public bool AutoPopulateValueConfigurations {
144      get { return autoPopulateValueConfigurations; }
145      set { autoPopulateValueConfigurations = value; }
146    }
147
148
149    #region Constructors and Cloning
150    public ParameterConfiguration(string parameterName, IValueParameter valueParameter, bool discoverValidValues) {
151      this.AutoPopulateValueConfigurations = true;
152      this.ParameterName = parameterName;
153      this.parameterDataType = valueParameter.GetType();
154      this.valueDataType = valueParameter.DataType;
155      this.discoverValidValues = discoverValidValues;
156      this.validValues = discoverValidValues ? GetValidValues(valueParameter) : new ItemSet<IItem> { valueParameter.Value };
157      this.validTypes = GetValidTypes(valueParameter).ToArray();
158      this.IsNullable = valueParameter.ItemName.StartsWith("Optional");
159      this.itemImage = valueParameter.ItemImage;
160      if (IsNullable) {
161        validTypes = new List<Type>(validTypes) { typeof(NullValue) }.ToArray();
162      }
163      this.ValueConfigurations = new CheckedValueConfigurationList(this.validValues ?? CreateValidValues());
164      this.ActualValue = new ConstrainedValue(
165        valueParameter.Value != null ? valueParameter.Value : null, // don't clone here; otherwise settings of a non-optimized ValueParameter will not be synchronized with the ConstrainedValue
166        valueParameter.DataType,
167        this.validValues != null ? new ItemSet<IItem>(this.validValues) : CreateValidValues(),
168        this.IsNullable);
169      if (Optimize) {
170        PopulateValueConfigurations();
171      }
172    }
173    public ParameterConfiguration(string parameterName, Type type, IItem actualValue, IEnumerable<IValueConfiguration> valueConfigurations) {
174      this.AutoPopulateValueConfigurations = false;
175      this.ParameterName = parameterName;
176      this.parameterDataType = type;
177      this.valueDataType = type;
178      this.discoverValidValues = false;
179      this.validValues = null; // maybe use values from valueConfigurations
180      this.validTypes = new Type[] { type };
181      this.IsNullable = false;
182      this.itemImage = valueConfigurations.Count() > 0 ? valueConfigurations.FirstOrDefault().ItemImage : null;
183      this.ValueConfigurations = new CheckedValueConfigurationList(valueConfigurations);
184      this.ActualValue = new ConstrainedValue(actualValue, type, CreateValidValues(), this.IsNullable);
185    }
186    public ParameterConfiguration(string parameterName, Type type, IItem actualValue) {
187      this.AutoPopulateValueConfigurations = true;
188      this.ParameterName = parameterName;
189      this.parameterDataType = type;
190      this.valueDataType = type;
191      this.discoverValidValues = false;
192      this.validValues = null;
193      this.validTypes = new Type[] { type };
194      this.IsNullable = false;
195      this.itemImage = actualValue.ItemImage;
196      this.ValueConfigurations = new CheckedValueConfigurationList();
197      this.ActualValue = new ConstrainedValue(actualValue, type, CreateValidValues(), this.IsNullable);
198      if (Optimize) {
199        PopulateValueConfigurations();
200      }
201    }
202    public ParameterConfiguration() { }
203    [StorableConstructor]
204    protected ParameterConfiguration(bool deserializing) { }
205    protected ParameterConfiguration(ParameterConfiguration original, Cloner cloner)
206      : base(original, cloner) {
207      this.parameterName = original.ParameterName;
208      this.parameterDataType = original.parameterDataType;
209      this.valueDataType = original.ValueDataType;
210      this.validValues = cloner.Clone(original.validValues);
211      this.validTypes = original.validTypes.ToArray();
212      this.valueConfigurations = cloner.Clone(original.ValueConfigurations);
213      this.ActualValue = cloner.Clone(original.ActualValue);
214      this.optimize = original.optimize;
215      this.actualValueConfigurationIndex = original.actualValueConfigurationIndex;
216      this.isNullable = original.isNullable;
217      this.itemImage = original.itemImage;
218      this.discoverValidValues = original.discoverValidValues;
219      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
220      this.AutoPopulateValueConfigurations = original.AutoPopulateValueConfigurations;
221    }
222
223
224    public override IDeepCloneable Clone(Cloner cloner) {
225      return new ParameterConfiguration(this, cloner);
226    }
227    [StorableHook(HookType.AfterDeserialization)]
228    private void AfterDeserialization() {
229      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
230    }
231    #endregion
232
233    private void RegisterValueConfigurationEvents() {
234      this.ValueConfigurations.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged);
235      this.ValueConfigurations.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded);
236      this.ValueConfigurations.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved);
237    }
238
239    private void DeregisterValueConfigurationEvents() {
240      this.ValueConfigurations.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged);
241      this.ValueConfigurations.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded);
242      this.ValueConfigurations.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved);
243    }
244
245    private void RegisterActualValueEvents() {
246      if (this.ActualValue != null) this.ActualValue.ToStringChanged += new EventHandler(ActualValue_ToStringChanged);
247    }
248    private void DeregisterActualValueEvents() {
249      if (this.ActualValue != null) this.ActualValue.ToStringChanged -= new EventHandler(ActualValue_ToStringChanged);
250    }
251
252    protected virtual void PopulateValueConfigurations() {
253      if (!this.AutoPopulateValueConfigurations)
254        return;
255
256      foreach (Type t in this.validTypes) {
257        if (t == typeof(NullValue)) {
258          this.ValueConfigurations.Add(new NullValueConfiguration());
259        } else {
260          IItem val;
261          if (ActualValue.Value != null && ActualValue.Value.GetType() == t) {
262            val = (IItem)ActualValue.Value.Clone(); // use existing value for that type (if available)
263          } else {
264            val = CreateItem(t);
265          }
266          if (val != null) { // val can be null when ValidValues does not contain the type (this can happen when discoverValidValues=false)
267            IValueConfiguration valueConfiguration;
268            if (val is IParameterizedItem) {
269              valueConfiguration = new ParameterizedValueConfiguration(val, val.GetType(), true);
270            } else {
271              if (val is ISymbolicExpressionGrammar) {
272                valueConfiguration = new SymbolicExpressionGrammarValueConfiguration((ISymbolicExpressionGrammar)val);
273              } else {
274                valueConfiguration = new RangeValueConfiguration(val, val.GetType());
275              }
276            }
277            this.ValueConfigurations.Add(valueConfiguration, true);
278          }
279        }
280      }
281    }
282
283    protected virtual void ClearValueConfigurations() {
284      if (!this.AutoPopulateValueConfigurations)
285        return;
286
287      this.ValueConfigurations.Clear();
288    }
289
290    private static IEnumerable<Type> GetValidTypes(IValueParameter parameter) {
291      // in case of IOperator return empty list, otherwise hundreds of types would be returned. this mostly occurs for Successor which will never be optimized
292      if (parameter.DataType == typeof(IOperator))
293        return new List<Type>();
294
295      // return only one type for ValueTypeValues<> (Int, Double, Percent, Bool). Otherwise 2 types would be returned for DoubleValue (PercentValue which is derived)
296      if (IsSubclassOfRawGeneric(typeof(ValueTypeValue<>), parameter.DataType))
297        return new List<Type> { parameter.DataType };
298
299      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
300        // use existing validvalues if known
301        var parameterValidValues = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
302        return parameterValidValues.Cast<object>().Select(x => x.GetType());
303      } else {
304        // otherwise use all assignable types
305        return ApplicationManager.Manager.GetTypes(parameter.DataType, true);
306      }
307    }
308
309    private IItemSet<IItem> GetValidValues(IValueParameter parameter) {
310      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
311        var x = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
312        return new ItemSet<IItem>(x.Cast<IItem>().Select(y => (IItem)y.Clone())); // cloning actually saves memory, because references to event-subscribers are removed
313      } else {
314        return null;
315      }
316    }
317
318    public IItem CreateItem(Type type) {
319      // no valid values; just instantiate
320      try {
321        if (validValues == null)
322          return (IItem)Activator.CreateInstance(type);
323      }
324      catch (MissingMemberException) {
325        return null; // can happen, when ApplicationManager.Manager.GetTypes(type, OnlyInstantiable=true) returns objects which have no default constructor
326      }
327
328      if (type == typeof(NullValue))
329        return new NullValue();
330
331      // copy value from ValidValues; this ensures that previously set ActualNames for a type are kept
332      IItem value = this.validValues.Where(v => v.GetType() == type).SingleOrDefault();
333      if (value != null)
334        return value;
335
336      return null;
337    }
338
339    private IItemSet<IItem> CreateValidValues() {
340      var validValues = new ItemSet<IItem>();
341      foreach (Type t in this.validTypes) {
342        try {
343          var val = CreateItem(t);
344          if (val != null) validValues.Add(val);
345        }
346        catch (MissingMethodException) { /* Constructor is missing, don't use those types */ }
347      }
348      return validValues;
349    }
350
351    private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
352      while (toCheck != typeof(object)) {
353        var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
354        if (generic == cur) {
355          return true;
356        }
357        toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface
358        if (toCheck == null)
359          return false;
360      }
361      return false;
362    }
363
364    void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
365      OnToStringChanged();
366      KeepActualValueConfigurationIndexConsistent();
367    }
368
369    void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
370      OnToStringChanged();
371      KeepActualValueConfigurationIndexConsistent();
372    }
373    void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
374      OnToStringChanged();
375      KeepActualValueConfigurationIndexConsistent();
376    }
377
378    #region INamedItem Properties
379    public virtual string Name {
380      get { return ParameterName; }
381      set { throw new NotSupportedException(); }
382    }
383    public virtual string Description {
384      get { return base.ItemDescription; }
385      set { throw new NotSupportedException(); }
386    }
387    public virtual bool CanChangeDescription {
388      get { return false; }
389    }
390    public virtual bool CanChangeName {
391      get { return false; }
392    }
393    public override string ItemDescription {
394      get { return base.ItemDescription; }
395    }
396    public override string ItemName {
397      get { return base.ItemName; }
398    }
399    #endregion
400
401    #region Events
402    void ActualValue_ToStringChanged(object sender, EventArgs e) {
403      OnToStringChanged();
404    }
405    #endregion
406
407    #region Event Handler
408    public virtual event EventHandler NameChanged;
409    protected virtual void OnNameChanged(object sender, EventArgs e) {
410      var handler = NameChanged;
411      if (handler != null) handler(sender, e);
412    }
413
414    public virtual event EventHandler<CancelEventArgs<string>> NameChanging;
415    protected virtual void OnNameChanging(object sender, CancelEventArgs<string> e) {
416      var handler = NameChanging;
417      if (handler != null) handler(sender, e);
418    }
419
420    public virtual event EventHandler DescriptionChanged;
421    protected virtual void OnDescriptionChanged(object sender, EventArgs e) {
422      var handler = DescriptionChanged;
423      if (handler != null) handler(sender, e);
424    }
425
426    public virtual event EventHandler IsOptimizableChanged;
427    private void OnIsOptimizableChanged() {
428      var handler = IsOptimizableChanged;
429      if (handler != null) handler(this, EventArgs.Empty);
430    }
431
432    public virtual event EventHandler OptimizeChanged;
433    protected virtual void OnOptimizeChanged() {
434      var handler = OptimizeChanged;
435      if (handler != null) handler(this, EventArgs.Empty);
436    }
437    #endregion
438
439    public override string ToString() {
440      if (Optimize) {
441        return string.Format("{0}: (Optimize: {1})", ParameterName, ValueConfigurations.CheckedItems.Count());
442      } else {
443        return string.Format("{0}: {1}", ParameterName, ActualValue.Value);
444      }
445    }
446
447    public virtual string ParameterInfoString {
448      get {
449        StringBuilder sb = new StringBuilder();
450        if (this.Optimize) {
451          var vc = this.ValueConfigurations[actualValueConfigurationIndex];
452          if (vc.ActualValue == null || vc.ActualValue.Value == null) {
453            sb.Append(string.Format("{0}: null", parameterName));
454          } else if (IsSubclassOfRawGeneric(typeof(ValueTypeValue<>), vc.ActualValue.Value.GetType())) {
455            // for int, double, bool use the value directly
456            sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value.ToString()));
457          } else {
458            // for other types use NumberedName (this also uses the Number-Property for otherwise ambiguous ValueConfigurations)
459            sb.Append(string.Format("{0}: {1}", parameterName, vc.NumberedName));
460          }
461
462          if (this.ValueConfigurations[actualValueConfigurationIndex] is ParameterizedValueConfiguration) {
463            string subParams = this.ValueConfigurations[actualValueConfigurationIndex].ParameterInfoString;
464            if (!string.IsNullOrEmpty(subParams)) {
465              sb.Append(" (");
466              sb.Append(subParams);
467              sb.Append(")");
468            }
469          }
470        }
471        return sb.ToString();
472      }
473    }
474
475    public static IParameterConfiguration Create(IParameterizedNamedItem parent, IParameter parameter, bool discoverValidValues) {
476      if (parameter is IValueParameter) {
477        IValueParameter valueParameter = parameter as IValueParameter;
478        return new ParameterConfiguration(parameter.Name, valueParameter, discoverValidValues);
479      }
480      return null;
481    }
482
483    public void Parameterize(IValueParameter parameter) {
484      if (parameter is IFixedValueParameter)
485        return;
486
487      if (Optimize) {
488        if (this.ActualValue.Value is IParameterizedItem) {
489          ((ParameterizedValueConfiguration)this.ValueConfigurations[actualValueConfigurationIndex]).Parameterize((IParameterizedItem)this.ActualValue.Value);
490        }
491        if (this.ActualValue.Value is ISymbolicExpressionGrammar) {
492          ((SymbolicExpressionGrammarValueConfiguration)this.ValueConfigurations[actualValueConfigurationIndex]).Parameterize((ISymbolicExpressionGrammar)this.ActualValue.Value);
493        }
494      }
495      var clonedValue = this.ActualValue.Value != null ? (IItem)this.ActualValue.Value.Clone() : null;
496      if (clonedValue != null) AdaptValidValues(parameter, clonedValue);
497      parameter.Value = clonedValue;
498    }
499
500    /// <summary>
501    /// Adds value to the ValidValues of the parameter if they don't contain the value
502    /// </summary>
503    private void AdaptValidValues(IValueParameter parameter, IItem value) {
504      // this requires some tricky reflection, because the type is unknown at runtime so parameter.ValidValues cannot be casted to Collection<?>
505      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
506        var validValues = parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
507        Type validValuesType = validValues.GetType();
508
509        var containsMethod = validValuesType.GetMethod("Contains");
510        if (!(bool)containsMethod.Invoke(validValues, new object[] { value })) {
511          var addMethod = validValuesType.GetMethod("Add");
512          addMethod.Invoke(validValues, new object[] { value });
513        }
514      }
515    }
516
517    public void Randomize(IRandom random) {
518      if (Optimize) {
519        foreach (var vc in this.ValueConfigurations) {
520          if (this.ValueConfigurations.ItemChecked(vc)) {
521            if (vc.Optimize) vc.Randomize(random);
522          }
523        }
524        do {
525          actualValueConfigurationIndex = random.Next(ValueConfigurations.Count());
526        } while (!this.ValueConfigurations.ItemChecked(this.ValueConfigurations[actualValueConfigurationIndex]));
527        this.ActualValue = this.ValueConfigurations[actualValueConfigurationIndex].ActualValue;
528      }
529    }
530
531    public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
532      if (Optimize) {
533        foreach (var vc in this.ValueConfigurations) {
534          if (this.ValueConfigurations.ItemChecked(vc)) {
535            if (vc.Optimize) vc.Mutate(random, mutate, intValueManipulator, doubleValueManipulator);
536          }
537        }
538        mutate(random, this, intValueManipulator, doubleValueManipulator);
539      }
540    }
541
542    public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) {
543      if (Optimize) {
544        IParameterConfiguration otherPc = (IParameterConfiguration)other;
545        for (int i = 0; i < this.ValueConfigurations.Count; i++) {
546          if (this.ValueConfigurations.ItemChecked(this.ValueConfigurations[i])) {
547            if (this.ValueConfigurations[i].Optimize) this.ValueConfigurations[i].Cross(random, otherPc.ValueConfigurations[i], cross, intValueCrossover, doubleValueCrossover);
548          }
549        }
550        cross(random, this, other, intValueCrossover, doubleValueCrossover);
551      }
552    }
553
554    public void UpdateActualValueIndexToItem(IValueConfiguration vc) {
555      for (int i = 0; i < this.ValueConfigurations.Count(); i++) {
556        if (this.ValueConfigurations.ElementAt(i) == vc) {
557          this.actualValueConfigurationIndex = i;
558          return;
559        }
560      }
561    }
562
563    public List<IOptimizable> GetAllOptimizables() {
564      var list = new List<IOptimizable>();
565      foreach (var vc in ValueConfigurations) {
566        if (vc.Optimize) {
567          list.Add(vc);
568          list.AddRange(vc.GetAllOptimizables());
569        }
570      }
571      return list;
572    }
573
574    public void CollectOptimizedParameterNames(List<string> parameterNames, string prefix) {
575      foreach (var vc in ValueConfigurations) {
576        if (vc.Optimize) {
577          vc.CollectOptimizedParameterNames(parameterNames, prefix);
578        }
579      }
580    }
581
582    public double CalculateSimilarity(IOptimizable optimizable) {
583      var other = (IParameterConfiguration)optimizable;
584      if (this.ActualValueConfigurationIndex == other.ActualValueConfigurationIndex) {
585        return this.ValueConfigurations[this.ActualValueConfigurationIndex].CalculateSimilarity(other.ValueConfigurations[other.ActualValueConfigurationIndex]);
586      } else {
587        return 0.0;
588      }
589    }
590
591    /// <summary>
592    /// Ensures that the ActualValueConfigurationIndex has a valid value
593    /// Only indices of items which are checked are allowed
594    /// </summary>
595    private void KeepActualValueConfigurationIndexConsistent() {
596      if (this.valueConfigurations != null && this.valueConfigurations.CheckedItems.Count() > 0) {
597        if(this.valueConfigurations.Count <= this.actualValueConfigurationIndex &&
598           this.valueConfigurations.CheckedItems.Count(x => x.Index == this.actualValueConfigurationIndex) == 1) {
599          // everything is ok; do nothing
600        } else {
601          // current index is invalid, set new one
602          this.ActualValueConfigurationIndex = this.valueConfigurations.CheckedItems.First().Index;
603        }
604      } else {
605        // no checked valueConfiguration is available; cannot be used
606        this.ActualValueConfigurationIndex = -1;
607      }
608    }
609  }
610}
Note: See TracBrowser for help on using the repository browser.