|
From: Luigi B. <lui...@gm...> - 2012-04-17 15:33:48
|
On Tue, Apr 17, 2012 at 10:28 AM, Simon Ibbotson
<Sim...@fs...> wrote:
> Possibly this should be submitted as a bug-fix…
>
> Why does the class Problem store a reference to the CostFunction and a
> reference to the Constraint?
>
> This seems incredibly bad programming / commenting. A call to create a
> Problem class of the form:
>
> Problem prob(preCreatedCostFunction, PositiveConstraint(), initialValues);
>
> will fail unpredictably at optimisation time as the Constraint is no longer
> a valid reference.
>
> If you want to force the CostFunction and the Constraint to be pre-created
> at the very least this should be commented, better would be to pass a shared
> pointer (which could be tested).
Simon,
you're right, that's downright embarrassing. Strange that I never
bumped into this...
At this time replacing the references with a shared pointer would
break backward compatibility, but I agree that this should at least be
documented. I'll add a warning to the class.
Thanks for the heads-up.
Luigi
|