Free cookie consent management tool by TermsFeed Policy Generator

Opened 14 years ago

Closed 14 years ago

#1049 closed feature request (done)

Provide a default instance when creating a new ValueParameter

Reported by: abeham Owned by: abeham
Priority: medium Milestone: HeuristicLab 3.3.4
Component: Parameters Version: 3.3.4
Keywords: Cc:

Description

Adding a new ValueParameter<T> could create a default value if T is instantiable. For most ValueParameters you will want to have a value upon creation.

Change History (20)

comment:1 Changed 14 years ago by mkommend

  • Owner changed from swagner to mkommend
  • Status changed from new to assigned

comment:2 Changed 14 years ago by mkommend

  • Milestone changed from HeuristicLab Backlog to HeuristicLab 3.3.4
  • Priority changed from lowest to medium
  • Status changed from assigned to accepted

comment:3 Changed 14 years ago by mkommend

r5843: Added code to create default values in ValueParameters if possible.

comment:4 Changed 14 years ago by mkommend

  • Owner changed from mkommend to swagner
  • Status changed from accepted to reviewing

r5848: Adapted TypeSelector to respect the new() constraint on generic types.

comment:5 Changed 14 years ago by mkommend

  • Version changed from 3.3 to 3.3.3

comment:6 Changed 14 years ago by mkommend

  • Owner changed from swagner to mkommend
  • Status changed from reviewing to assigned

comment:7 Changed 14 years ago by mkommend

  • Owner changed from mkommend to swagner
  • Status changed from assigned to reviewing

r5859: Added version information to the plugin !treeNodes in the TypeSelector.

comment:8 Changed 14 years ago by mkommend

r5898: Changed TypeSelector to display major and minor plugin version without brackets. IMHO it is not necessary to display the full version (this can be seen in the textbox below).

comment:9 Changed 14 years ago by abeham

I was quite surprised recently when I saw this already in action. It's very handy when designing custom algorithms!

comment:10 Changed 14 years ago by swagner

  • Owner changed from swagner to abeham

comment:11 Changed 14 years ago by abeham

  • Owner changed from abeham to mkommend
  • Status changed from reviewing to assigned

I tested this a little further and think that somewhere an error was introduced:

I tried to add a new parameter in a user-defined algorithm , e.g. a LookupParameter<T> and then choose the type for T. The dialog that lists all possible types for T however lists only instantiable types. A LookupParameter can look up a wide range of possible types, sometimes only specified by an interface. I think it should be and has been possible to create that parameter with IOperator as its generic type. The restriction to limit the type selector dialog to instantiable types should only be set if the generic type of a FixedValueParameter<T> is going to be defined. Maybe this error is also related to #1418 where FixedValueParameter<T> was introduced.

Change in r5848 is difficult to understand.

comment:12 Changed 14 years ago by mkommend

  • Status changed from assigned to accepted

comment:13 Changed 14 years ago by mkommend

r6019: Corrected bug in TypeSelector.

comment:14 Changed 14 years ago by mkommend

Thx for the testing Andreas. The revision r5848 is quite simple to explain; it only removes unnecessary checks (line 122 -124), makes the try-catch block (line 134 - 140) obsolete by checking for a default constructor and configures the nested type selector correctly.

comment:15 Changed 14 years ago by mkommend

  • Owner changed from mkommend to abeham
  • Status changed from accepted to reviewing

comment:16 Changed 14 years ago by abeham

  • Owner changed from abeham to mkommend
  • Status changed from reviewing to assigned

I tested it again: Creating a ValueParameter<SingleSuccessorOperator> results in an exception. Here is the exception message:

TargetInvocationException: Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType)
   at System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct signature, RuntimeType declaringType)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at HeuristicLab.Core.Views.CreateParameterDialog.get_Parameter()
-----
MemberAccessException: Cannot create an instance of HeuristicLab.Operators.SingleSuccessorOperator because it is an abstract class.
   at System.Reflection.RuntimeConstructorInfo.CheckCanCreateInstance(Type declaringType, Boolean isVarArg)
   at System.Reflection.RuntimeConstructorInfo.ThrowNoInvokeException()
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at HeuristicLab.Parameters.ValueParameter`1.CreateDefaultValue()
   at HeuristicLab.Parameters.ValueParameter`1..ctor(String name, String description)

I think a check for abstract types is missing before invoking the constructor.

comment:17 Changed 14 years ago by mkommend

  • Status changed from assigned to accepted

comment:18 Changed 14 years ago by mkommend

  • Owner changed from mkommend to abeham
  • Status changed from accepted to reviewing

r6025: Added a check for abstract types in ValueParameter.CreateDefaultValue.

comment:19 Changed 14 years ago by abeham

  • Status changed from reviewing to readytorelease

Very well I think that should do it. Great feature, thx for implementing it!

comment:20 Changed 14 years ago by swagner

  • Resolution set to done
  • Status changed from readytorelease to closed
  • Version changed from 3.3.3 to 3.3.4
Note: See TracTickets for help on using tickets.