From 6133358ba19e911cbc3fe25343b657f502e028db Mon Sep 17 00:00:00 2001
From: Anders Markvardsen <anders.markvardsen@stfc.ac.uk>
Date: Sat, 12 Dec 2009 10:21:17 +0000
Subject: [PATCH] Start on interface to allow not only LM and Simplex to be
 used with Fit but also other minimizers. Refs #1044.

---
 Code/Mantid/API/inc/MantidAPI/IPeakFunction.h |  2 +-
 Code/Mantid/CurveFitting/CurveFitting.vcproj  | 12 ++++
 .../inc/MantidCurveFitting/IFuncMinimizer.h   | 52 ++++++++++++++++++
 .../LevenbergMarquardtMinimizer.h             | 55 +++++++++++++++++++
 .../src/LevenbergMarquardtMinimizer.cpp       | 29 ++++++++++
 5 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 Code/Mantid/CurveFitting/inc/MantidCurveFitting/IFuncMinimizer.h
 create mode 100644 Code/Mantid/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h
 create mode 100644 Code/Mantid/CurveFitting/src/LevenbergMarquardtMinimizer.cpp

diff --git a/Code/Mantid/API/inc/MantidAPI/IPeakFunction.h b/Code/Mantid/API/inc/MantidAPI/IPeakFunction.h
index 442aee53581..822605e9236 100644
--- a/Code/Mantid/API/inc/MantidAPI/IPeakFunction.h
+++ b/Code/Mantid/API/inc/MantidAPI/IPeakFunction.h
@@ -37,7 +37,7 @@ namespace API
     File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
     Code Documentation is available at: <http://doxygen.mantidproject.org>
 */
-class DLLExport IPeakFunction : public IFunctionWithLocation//, public Function
+class DLLExport IPeakFunction : public IFunctionWithLocation
 {
 public:
   /// Returns the peak FWHM
diff --git a/Code/Mantid/CurveFitting/CurveFitting.vcproj b/Code/Mantid/CurveFitting/CurveFitting.vcproj
index 54e8a8ce4c9..7c010242707 100644
--- a/Code/Mantid/CurveFitting/CurveFitting.vcproj
+++ b/Code/Mantid/CurveFitting/CurveFitting.vcproj
@@ -234,6 +234,10 @@
 				RelativePath=".\src\IkedaCarpenterPV1D.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\src\LevenbergMarquardtMinimizer.cpp"
+				>
+			</File>
 			<File
 				RelativePath=".\src\Linear.cpp"
 				>
@@ -336,6 +340,10 @@
 				RelativePath=".\test\GaussianTest.h"
 				>
 			</File>
+			<File
+				RelativePath=".\inc\MantidCurveFitting\IFuncMinimizer.h"
+				>
+			</File>
 			<File
 				RelativePath=".\inc\MantidCurveFitting\IkedaCarpenterPV.h"
 				>
@@ -352,6 +360,10 @@
 				RelativePath=".\test\IkedaCarpenterPVTest.h"
 				>
 			</File>
+			<File
+				RelativePath=".\inc\MantidCurveFitting\LevenbergMarquardtMinimizer.h"
+				>
+			</File>
 			<File
 				RelativePath=".\inc\MantidCurveFitting\Linear.h"
 				>
diff --git a/Code/Mantid/CurveFitting/inc/MantidCurveFitting/IFuncMinimizer.h b/Code/Mantid/CurveFitting/inc/MantidCurveFitting/IFuncMinimizer.h
new file mode 100644
index 00000000000..966cc624fc9
--- /dev/null
+++ b/Code/Mantid/CurveFitting/inc/MantidCurveFitting/IFuncMinimizer.h
@@ -0,0 +1,52 @@
+#ifndef MANTID_CURVEFITTING_IFUNCMINIMIZER_H_
+#define MANTID_CURVEFITTING_IFUNCMINIMIZER_H_
+
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidKernel/System.h"
+#include <string>
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+/** An interface for function minimizers.
+
+    @author Anders Markvardsen, ISIS, RAL
+    @date 11/12/2009
+
+    Copyright &copy; 2009 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+*/
+class DLLExport IFuncMinimizer 
+{
+public:
+  /// Get name of minimizer
+  virtual std::string name()const = 0;
+
+  /// Perform iteration with minimizer
+  virtual void iterate() = 0;
+};
+
+} // namespace CurveFitting
+} // namespace Mantid
+
+#endif /*MANTID_CURVEFITTING_IFUNCMINIMIZER_H_*/
diff --git a/Code/Mantid/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h b/Code/Mantid/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h
new file mode 100644
index 00000000000..979334433de
--- /dev/null
+++ b/Code/Mantid/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h
@@ -0,0 +1,55 @@
+#ifndef MANTID_CURVEFITTING_LEVENBERGMARQUARDTMINIMIZER_H_
+#define MANTID_CURVEFITTING_LEVENBERGMARQUARDTMINIMIZER_H_
+
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidCurveFitting/IFuncMinimizer.h"
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+/** Implementing Levenberg-Marquardt. Wrap the GSL implementation of this 
+    algorithm into using IFuncMinimizer interface.
+
+    @author Anders Markvardsen, ISIS, RAL
+    @date 11/12/2009
+
+    Copyright &copy; 2009 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+*/
+class DLLExport LevenbergMarquardtMinimizer : public IFuncMinimizer
+{
+public:
+  /// Virtual destructor
+  virtual ~LevenbergMarquardtMinimizer(){}
+
+  /// Get name of minimizer
+  virtual std::string name()const;
+
+  /// Perform iteration with minimizer
+  virtual void iterate();
+};
+
+} // namespace CurveFitting
+} // namespace Mantid
+
+#endif /*MANTID_CURVEFITTING_LEVENBERGMARQUARDTMINIMIZER_H_*/
diff --git a/Code/Mantid/CurveFitting/src/LevenbergMarquardtMinimizer.cpp b/Code/Mantid/CurveFitting/src/LevenbergMarquardtMinimizer.cpp
new file mode 100644
index 00000000000..5e947e3b9fc
--- /dev/null
+++ b/Code/Mantid/CurveFitting/src/LevenbergMarquardtMinimizer.cpp
@@ -0,0 +1,29 @@
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidCurveFitting/LevenbergMarquardtMinimizer.h"
+#include <gsl/gsl_errno.h>
+#include <gsl/gsl_fit.h>
+#include "MantidKernel/Exception.h"
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+
+/// Get name of minimizer
+std::string LevenbergMarquardtMinimizer::name()const
+{
+  throw Kernel::Exception::NotImplementedError("Not implemented yet");
+  return std::string("Not implemented yet");
+}
+
+/// Perform iteration with minimizer
+void LevenbergMarquardtMinimizer::iterate() 
+{
+  throw Kernel::Exception::NotImplementedError("Not implemented yet");
+}
+
+
+} // namespace CurveFitting
+} // namespace Mantid
-- 
GitLab