Changeset 12741 for stable/HeuristicLab.Optimizer
- Timestamp:
- 07/11/15 19:45:29 (9 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12680
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer (added) merged: 12251-12252,12254,12267-12268,12466,12513,12678 /trunk/sources/HeuristicLab.Optimizer merged: 12680
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r12740 r12741 169 169 else boolParameters.Remove(parameter); 170 170 } 171 172 bool isEnumValue = parameter.Value != null && parameter.Value.GetType().IsGenericType 173 && typeof(EnumValue<>).IsAssignableFrom(parameter.Value.GetType().GetGenericTypeDefinition()); 174 if (isEnumValue) { 175 if (e.Item.Checked) multipleChoiceParameters.Add(parameter, new HashSet<IItem>(new EnumValueEqualityComparer())); 176 else multipleChoiceParameters.Remove(parameter); 177 } 171 178 } 172 179 … … 192 199 isOptionalConstrainedValueParameter 193 200 || typeof(ConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition()); 194 195 if (isConstrainedValueParameter) { 201 bool isEnumValue = parameter.Value != null && parameter.Value.GetType().IsGenericType 202 && typeof(EnumValue<>).IsAssignableFrom(parameter.Value.GetType().GetGenericTypeDefinition()); 203 204 if (isConstrainedValueParameter || isEnumValue) { 196 205 detailsTypeLabel.Text = "Choices:"; 197 206 choicesListView.Tag = parameter; 198 207 199 if (isOptionalConstrainedValueParameter) { 200 choicesListView.Items.Add(new ListViewItem("-") { 201 Tag = optionalNullChoice, 202 Checked = multipleChoiceParameters.ContainsKey(parameter) 203 && multipleChoiceParameters[parameter].Contains(optionalNullChoice) 204 }); 205 } 206 dynamic constrainedValuedParameter = parameter; 207 dynamic validValues = constrainedValuedParameter.ValidValues; 208 foreach (var choice in validValues) { 209 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 210 Tag = choice, 211 Checked = multipleChoiceParameters.ContainsKey(parameter) 212 && multipleChoiceParameters[parameter].Contains(choice) 213 }); 208 if (isConstrainedValueParameter) { 209 if (isOptionalConstrainedValueParameter) { 210 choicesListView.Items.Add(new ListViewItem("-") { 211 Tag = optionalNullChoice, 212 Checked = multipleChoiceParameters.ContainsKey(parameter) 213 && multipleChoiceParameters[parameter].Contains(optionalNullChoice) 214 }); 215 } 216 dynamic constrainedValuedParameter = parameter; 217 dynamic validValues = constrainedValuedParameter.ValidValues; 218 foreach (var choice in validValues) { 219 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 220 Tag = choice, 221 Checked = multipleChoiceParameters.ContainsKey(parameter) 222 && multipleChoiceParameters[parameter].Contains(choice) 223 }); 224 } 225 } 226 if (isEnumValue) { 227 var enumType = parameter.Value.GetType().GetGenericArguments()[0]; 228 var enumValueType = typeof(EnumValue<>).MakeGenericType(enumType); 229 foreach (var enumChoice in Enum.GetValues(enumType)) { 230 choicesListView.Items.Add(new ListViewItem(enumChoice.ToString()) { 231 Tag = Activator.CreateInstance(enumValueType, enumChoice), 232 Checked = multipleChoiceParameters.ContainsKey(parameter) 233 && multipleChoiceParameters[parameter].Any((dynamic item) => item.Value.Equals(enumChoice)) 234 }); 235 } 214 236 } 215 237 choicesListView.Enabled = multipleChoiceParameters.ContainsKey(parameter); … … 455 477 if (valueParam != null && (valueParam.Value is ValueTypeValue<bool> 456 478 || valueParam.Value is ValueTypeValue<int> 457 || valueParam.Value is ValueTypeValue<double>) 479 || valueParam.Value is ValueTypeValue<double> 480 || (valueParam.Value != null && valueParam.Value.GetType().IsGenericType 481 && typeof(EnumValue<>).IsAssignableFrom(valueParam.Value.GetType().GetGenericTypeDefinition()))) 458 482 || typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition()) 459 483 || typeof(ConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition())) … … 603 627 bool finished; 604 628 do { 629 foreach (var p in boolParameters) { 630 if (!configuration.ContainsKey(p)) 631 configuration.Add(p, false); 632 } 633 634 yield return configuration; 605 635 finished = true; 636 606 637 foreach (var p in boolParameters) { 607 if (!configuration.ContainsKey(p)) configuration.Add(p, false); 608 else { 609 if (configuration[p]) { 610 configuration[p] = false; 611 } else { 612 configuration[p] = true; 613 finished = false; 614 break; 615 } 616 } 617 } 618 yield return configuration; 638 if (configuration[p]) { 639 configuration[p] = false; 640 } else { 641 configuration[p] = true; 642 finished = false; 643 break; 644 } 645 } 619 646 } while (!finished); 620 647 } … … 650 677 } 651 678 #endregion 679 680 #region EnumValueEqualityComparer 681 private class EnumValueEqualityComparer : EqualityComparer<IItem> { 682 public override bool Equals(IItem x, IItem y) { 683 if (typeof(EnumValue<>).IsAssignableFrom(x.GetType().GetGenericTypeDefinition()) && 684 typeof(EnumValue<>).IsAssignableFrom(y.GetType().GetGenericTypeDefinition())) { 685 dynamic enumValueX = x; 686 dynamic enumValueY = y; 687 return enumValueX.Value.Equals(enumValueY.Value); 688 } else return object.ReferenceEquals(x, y); 689 } 690 691 public override int GetHashCode(IItem obj) { 692 if (typeof(EnumValue<>).IsAssignableFrom(obj.GetType().GetGenericTypeDefinition())) { 693 dynamic enumValue = obj; 694 return enumValue.Value.GetHashCode(); 695 } else return obj.GetHashCode(); 696 } 697 } 698 #endregion 699 652 700 #endregion 653 701 … … 832 880 if (multipleChoiceParameters.Any()) { 833 881 foreach (var m in mcEnumerator.Current) { 834 dynamic variantParam = variant.Parameters[m.Key.Name]; 835 if (m.Value == optionalNullChoice) { 836 variantParam.Value = null; 837 variant.Name += m.Key.Name + "=null, "; 838 continue; 839 } 840 var variantEnumerator = ((IEnumerable<object>)variantParam.ValidValues).GetEnumerator(); 841 var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator(); 842 while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) { 843 if (m.Value == (IItem)originalEnumerator.Current) { 844 variantParam.Value = (dynamic)variantEnumerator.Current; 845 if (m.Value is INamedItem) 846 variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", "; 847 else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", "; 848 break; 882 if (m.Key.Value != null && m.Key.Value.GetType().IsGenericType 883 && typeof(EnumValue<>).IsAssignableFrom(m.Key.Value.GetType().GetGenericTypeDefinition())) { 884 var valueParam = (IValueParameter)variant.Parameters[m.Key.Name]; 885 valueParam.Value = m.Value; 886 variant.Name += m.Key.Name + "=" + m.Value + ", "; 887 } else { 888 dynamic variantParam = variant.Parameters[m.Key.Name]; 889 if (m.Value == optionalNullChoice) { 890 variantParam.Value = null; 891 variant.Name += m.Key.Name + "=null, "; 892 continue; 893 } 894 var variantEnumerator = ((IEnumerable<object>)variantParam.ValidValues).GetEnumerator(); 895 var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator(); 896 while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) { 897 if (m.Value == (IItem)originalEnumerator.Current) { 898 variantParam.Value = (dynamic)variantEnumerator.Current; 899 if (m.Value is INamedItem) 900 variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", "; 901 else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", "; 902 break; 903 } 849 904 } 850 905 }
Note: See TracChangeset
for help on using the changeset viewer.