Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6421 was 6421, checked in by cneumuel, 13 years ago

#1215

  • small fixes
File size: 24.9 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      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
214      this.actualValue = cloner.Clone(original.actualValue);
215      if (this.actualValue != null) RegisterActualValueEvents();
216      this.optimize = original.optimize;
217      this.actualValueConfigurationIndex = original.actualValueConfigurationIndex;
218      this.isNullable = original.isNullable;
219      this.itemImage = original.itemImage;
220      this.discoverValidValues = original.discoverValidValues;
221      this.AutoPopulateValueConfigurations = original.AutoPopulateValueConfigurations;
222    }
223
224
225    public override IDeepCloneable Clone(Cloner cloner) {
226      return new ParameterConfiguration(this, cloner);
227    }
228    [StorableHook(HookType.AfterDeserialization)]
229    protected virtual void AfterDeserialization() {
230      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
231      if (this.actualValue != null) RegisterActualValueEvents();
232    }
233    #endregion
234
235    private void RegisterValueConfigurationEvents() {
236      this.ValueConfigurations.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged);
237      this.ValueConfigurations.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded);
238      this.ValueConfigurations.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved);
239    }
240
241    private void DeregisterValueConfigurationEvents() {
242      this.ValueConfigurations.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged);
243      this.ValueConfigurations.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded);
244      this.ValueConfigurations.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved);
245    }
246
247    private void RegisterActualValueEvents() {
248      if (this.ActualValue != null) this.ActualValue.ToStringChanged += new EventHandler(ActualValue_ToStringChanged);
249    }
250    private void DeregisterActualValueEvents() {
251      if (this.ActualValue != null) this.ActualValue.ToStringChanged -= new EventHandler(ActualValue_ToStringChanged);
252    }
253
254    protected virtual void PopulateValueConfigurations() {
255      if (!this.AutoPopulateValueConfigurations)
256        return;
257
258      foreach (Type t in this.validTypes) {
259        if (t == typeof(NullValue)) {
260          this.ValueConfigurations.Add(new NullValueConfiguration());
261        } else {
262          IItem val;
263          if (ActualValue.Value != null && ActualValue.Value.GetType() == t) {
264            val = (IItem)ActualValue.Value.Clone(); // use existing value for that type (if available)
265          } else {
266            val = CreateItem(t);
267          }
268          if (val != null) { // val can be null when ValidValues does not contain the type (this can happen when discoverValidValues=false)
269            IValueConfiguration valueConfiguration;
270            if (val is IParameterizedItem) {
271              valueConfiguration = new ParameterizedValueConfiguration(val, val.GetType(), true);
272            } else {
273              if (val is ISymbolicExpressionGrammar) {
274                valueConfiguration = new SymbolicExpressionGrammarValueConfiguration((ISymbolicExpressionGrammar)val);
275              } else {
276                valueConfiguration = new RangeValueConfiguration(val, val.GetType());
277              }
278            }
279            this.ValueConfigurations.Add(valueConfiguration, true);
280          }
281        }
282      }
283    }
284
285    protected virtual void ClearValueConfigurations() {
286      if (!this.AutoPopulateValueConfigurations)
287        return;
288
289      this.ValueConfigurations.Clear();
290    }
291
292    private static IEnumerable<Type> GetValidTypes(IValueParameter parameter) {
293      // in case of IOperator return empty list, otherwise hundreds of types would be returned. this mostly occurs for Successor which will never be optimized
294      if (parameter.DataType == typeof(IOperator))
295        return new List<Type>();
296
297      // return only one type for ValueTypeValues<> (Int, Double, Percent, Bool). Otherwise 2 types would be returned for DoubleValue (PercentValue which is derived)
298      if (IsSubclassOfRawGeneric(typeof(ValueTypeValue<>), parameter.DataType))
299        return new List<Type> { parameter.DataType };
300
301      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
302        // use existing validvalues if known
303        var parameterValidValues = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
304        return parameterValidValues.Cast<object>().Select(x => x.GetType());
305      } else {
306        // otherwise use all assignable types
307        return ApplicationManager.Manager.GetTypes(parameter.DataType, true);
308      }
309    }
310
311    private IItemSet<IItem> GetValidValues(IValueParameter parameter) {
312      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
313        var x = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
314        return new ItemSet<IItem>(x.Cast<IItem>().Select(y => (IItem)y.Clone())); // cloning actually saves memory, because references to event-subscribers are removed
315      } else {
316        return null;
317      }
318    }
319
320    public IItem CreateItem(Type type) {
321      // no valid values; just instantiate
322      try {
323        if (validValues == null)
324          return (IItem)Activator.CreateInstance(type);
325      }
326      catch (MissingMemberException) {
327        return null; // can happen, when ApplicationManager.Manager.GetTypes(type, OnlyInstantiable=true) returns objects which have no default constructor
328      }
329
330      if (type == typeof(NullValue))
331        return new NullValue();
332
333      // copy value from ValidValues; this ensures that previously set ActualNames for a type are kept
334      IItem value = this.validValues.Where(v => v.GetType() == type).SingleOrDefault();
335      if (value != null)
336        return value;
337
338      return null;
339    }
340
341    private IItemSet<IItem> CreateValidValues() {
342      var validValues = new ItemSet<IItem>();
343      foreach (Type t in this.validTypes) {
344        try {
345          var val = CreateItem(t);
346          if (val != null) validValues.Add(val);
347        }
348        catch (MissingMethodException) { /* Constructor is missing, don't use those types */ }
349      }
350      return validValues;
351    }
352
353    private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
354      while (toCheck != typeof(object)) {
355        var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
356        if (generic == cur) {
357          return true;
358        }
359        toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface
360        if (toCheck == null)
361          return false;
362      }
363      return false;
364    }
365
366    private void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
367      OnToStringChanged();
368      KeepActualValueConfigurationIndexConsistent();
369    }
370
371    private void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
372      OnToStringChanged();
373      KeepActualValueConfigurationIndexConsistent();
374    }
375    private void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
376      OnToStringChanged();
377      KeepActualValueConfigurationIndexConsistent();
378    }
379
380    #region INamedItem Properties
381    public virtual string Name {
382      get { return ParameterName; }
383      set { throw new NotSupportedException(); }
384    }
385    public virtual string Description {
386      get { return base.ItemDescription; }
387      set { throw new NotSupportedException(); }
388    }
389    public virtual bool CanChangeDescription {
390      get { return false; }
391    }
392    public virtual bool CanChangeName {
393      get { return false; }
394    }
395    public override string ItemDescription {
396      get { return base.ItemDescription; }
397    }
398    public override string ItemName {
399      get { return base.ItemName; }
400    }
401    #endregion
402
403    #region Events
404    protected virtual void ActualValue_ToStringChanged(object sender, EventArgs e) {
405      OnToStringChanged();
406    }
407    #endregion
408
409    #region Event Handler
410    public virtual event EventHandler NameChanged;
411    protected virtual void OnNameChanged(object sender, EventArgs e) {
412      var handler = NameChanged;
413      if (handler != null) handler(sender, e);
414    }
415
416    public virtual event EventHandler<CancelEventArgs<string>> NameChanging;
417    protected virtual void OnNameChanging(object sender, CancelEventArgs<string> e) {
418      var handler = NameChanging;
419      if (handler != null) handler(sender, e);
420    }
421
422    public virtual event EventHandler DescriptionChanged;
423    protected virtual void OnDescriptionChanged(object sender, EventArgs e) {
424      var handler = DescriptionChanged;
425      if (handler != null) handler(sender, e);
426    }
427
428    public virtual event EventHandler IsOptimizableChanged;
429    private void OnIsOptimizableChanged() {
430      var handler = IsOptimizableChanged;
431      if (handler != null) handler(this, EventArgs.Empty);
432    }
433
434    public virtual event EventHandler OptimizeChanged;
435    protected virtual void OnOptimizeChanged() {
436      var handler = OptimizeChanged;
437      if (handler != null) handler(this, EventArgs.Empty);
438    }
439    #endregion
440
441    public override string ToString() {
442      if (Optimize) {
443        return string.Format("{0}: (Optimize: {1})", ParameterName, ValueConfigurations.CheckedItems.Count());
444      } else {
445        return string.Format("{0}: {1}", ParameterName, ActualValue.Value);
446      }
447    }
448
449    public virtual string ParameterInfoString {
450      get {
451        StringBuilder sb = new StringBuilder();
452        if (this.Optimize) {
453          var vc = this.ValueConfigurations[actualValueConfigurationIndex];
454          if (vc.ActualValue == null || vc.ActualValue.Value == null) {
455            sb.Append(string.Format("{0}: null", parameterName));
456          } else if (IsSubclassOfRawGeneric(typeof(ValueTypeValue<>), vc.ActualValue.Value.GetType())) {
457            // for int, double, bool use the value directly
458            sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value.ToString()));
459          } else {
460            // for other types use NumberedName (this also uses the Number-Property for otherwise ambiguous ValueConfigurations)
461            sb.Append(string.Format("{0}: {1}", parameterName, vc.NumberedName));
462          }
463
464          if (this.ValueConfigurations[actualValueConfigurationIndex] is ParameterizedValueConfiguration) {
465            string subParams = this.ValueConfigurations[actualValueConfigurationIndex].ParameterInfoString;
466            if (!string.IsNullOrEmpty(subParams)) {
467              sb.Append(" (");
468              sb.Append(subParams);
469              sb.Append(")");
470            }
471          }
472        }
473        return sb.ToString();
474      }
475    }
476
477    public static IParameterConfiguration Create(IParameterizedNamedItem parent, IParameter parameter, bool discoverValidValues) {
478      if (parameter is IValueParameter) {
479        IValueParameter valueParameter = parameter as IValueParameter;
480        return new ParameterConfiguration(parameter.Name, valueParameter, discoverValidValues);
481      }
482      return null;
483    }
484
485    public void Parameterize(IValueParameter parameter) {
486      if (parameter is IFixedValueParameter)
487        return;
488
489      if (Optimize) {
490        if (this.ActualValue.Value is IParameterizedItem) {
491          ((ParameterizedValueConfiguration)this.ValueConfigurations[actualValueConfigurationIndex]).Parameterize((IParameterizedItem)this.ActualValue.Value);
492        }
493        if (this.ActualValue.Value is ISymbolicExpressionGrammar) {
494          ((SymbolicExpressionGrammarValueConfiguration)this.ValueConfigurations[actualValueConfigurationIndex]).Parameterize((ISymbolicExpressionGrammar)this.ActualValue.Value);
495        }
496      }
497      var clonedValue = this.ActualValue.Value != null ? (IItem)this.ActualValue.Value.Clone() : null;
498      if (clonedValue != null) AdaptValidValues(parameter, clonedValue);
499      parameter.Value = clonedValue;
500    }
501
502    /// <summary>
503    /// Adds value to the ValidValues of the parameter if they don't contain the value
504    /// </summary>
505    private void AdaptValidValues(IValueParameter parameter, IItem value) {
506      // this requires some tricky reflection, because the type is unknown at runtime so parameter.ValidValues cannot be casted to Collection<?>
507      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
508        var validValues = parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
509        Type validValuesType = validValues.GetType();
510
511        var containsMethod = validValuesType.GetMethod("Contains");
512        if (!(bool)containsMethod.Invoke(validValues, new object[] { value })) {
513          var addMethod = validValuesType.GetMethod("Add");
514          addMethod.Invoke(validValues, new object[] { value });
515        }
516      }
517    }
518
519    public void Randomize(IRandom random) {
520      if (Optimize) {
521        foreach (var vc in this.ValueConfigurations) {
522          if (this.ValueConfigurations.ItemChecked(vc)) {
523            if (vc.Optimize) vc.Randomize(random);
524          }
525        }
526        do {
527          actualValueConfigurationIndex = random.Next(ValueConfigurations.Count());
528        } while (!this.ValueConfigurations.ItemChecked(this.ValueConfigurations[actualValueConfigurationIndex]));
529        this.ActualValue = this.ValueConfigurations[actualValueConfigurationIndex].ActualValue;
530      }
531    }
532
533    public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
534      if (Optimize) {
535        foreach (var vc in this.ValueConfigurations) {
536          if (this.ValueConfigurations.ItemChecked(vc)) {
537            if (vc.Optimize) vc.Mutate(random, mutate, intValueManipulator, doubleValueManipulator);
538          }
539        }
540        mutate(random, this, intValueManipulator, doubleValueManipulator);
541      }
542    }
543
544    public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) {
545      if (Optimize) {
546        IParameterConfiguration otherPc = (IParameterConfiguration)other;
547        for (int i = 0; i < this.ValueConfigurations.Count; i++) {
548          if (this.ValueConfigurations.ItemChecked(this.ValueConfigurations[i])) {
549            if (this.ValueConfigurations[i].Optimize) this.ValueConfigurations[i].Cross(random, otherPc.ValueConfigurations[i], cross, intValueCrossover, doubleValueCrossover);
550          }
551        }
552        cross(random, this, other, intValueCrossover, doubleValueCrossover);
553      }
554    }
555
556    public void UpdateActualValueIndexToItem(IValueConfiguration vc) {
557      for (int i = 0; i < this.ValueConfigurations.Count(); i++) {
558        if (this.ValueConfigurations.ElementAt(i) == vc) {
559          this.actualValueConfigurationIndex = i;
560          return;
561        }
562      }
563    }
564
565    public List<IOptimizable> GetAllOptimizables() {
566      var list = new List<IOptimizable>();
567      foreach (var vc in ValueConfigurations) {
568        if (vc.Optimize) {
569          list.Add(vc);
570          list.AddRange(vc.GetAllOptimizables());
571        }
572      }
573      return list;
574    }
575
576    public void CollectOptimizedParameterNames(List<string> parameterNames, string prefix) {
577      foreach (var vc in ValueConfigurations) {
578        if (vc.Optimize) {
579          vc.CollectOptimizedParameterNames(parameterNames, prefix);
580        }
581      }
582    }
583
584    public double CalculateSimilarity(IOptimizable optimizable) {
585      var other = (IParameterConfiguration)optimizable;
586      if (this.ActualValueConfigurationIndex == other.ActualValueConfigurationIndex) {
587        return this.ValueConfigurations[this.ActualValueConfigurationIndex].CalculateSimilarity(other.ValueConfigurations[other.ActualValueConfigurationIndex]);
588      } else {
589        return 0.0;
590      }
591    }
592
593    /// <summary>
594    /// Ensures that the ActualValueConfigurationIndex has a valid value
595    /// Only indices of items which are checked are allowed
596    /// </summary>
597    private void KeepActualValueConfigurationIndexConsistent() {
598      if (this.valueConfigurations != null && this.valueConfigurations.CheckedItems.Count() > 0) {
599        if(this.valueConfigurations.Count <= this.actualValueConfigurationIndex &&
600           this.valueConfigurations.CheckedItems.Count(x => x.Index == this.actualValueConfigurationIndex) == 1) {
601          // everything is ok; do nothing
602        } else {
603          // current index is invalid, set new one
604          this.ActualValueConfigurationIndex = this.valueConfigurations.CheckedItems.First().Index;
605        }
606      } else {
607        // no checked valueConfiguration is available; cannot be used
608        this.ActualValueConfigurationIndex = -1;
609      }
610    }
611  }
612}
Note: See TracBrowser for help on using the repository browser.