chiark / gitweb /
Use trusty
[nlopt.git] / api / nlopt.h
index 29b7d1869edc462a0b2a31cd4383aca067025c15..a0e6b384b1f9f65c23ea086e82bffd31aa408ab5 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2010 Massachusetts Institute of Technology
+/* Copyright (c) 2007-2014 Massachusetts Institute of Technology
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -25,9 +25,8 @@
 
 #include <stddef.h> /* for ptrdiff_t and size_t */
 
-/* use stdcall convention under Windows, since this seems to
-   be more standard there and is important for calling from .NET */
-#if defined(_WIN32) || defined(__WIN32__)
+/* Change 0 to 1 to use stdcall convention under Win32 */
+#if 0 && (defined(_WIN32) || defined(__WIN32__))
 #  if defined(__GNUC__)
 #    define NLOPT_STDCALL __attribute__((stdcall))
 #  elif defined(_MSC_VER) || defined(_ICC) || defined(_STDCALL_SUPPORTED)
            #define NLOPT_DLL
    when using NLopt from a DLL, in order to do the proper
    Windows importing nonsense. */
-#if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__))
+#if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__)) && !defined(__LCC__)
 /* annoying Windows syntax for calling functions in a DLL */
-#  define NLOPT_EXTERN(T) extern __declspec(dllimport) T NLOPT_STDCALL
+#  if defined(NLOPT_DLL_EXPORT)
+#    define NLOPT_EXTERN(T) extern __declspec(dllexport) T NLOPT_STDCALL
+#  else
+#    define NLOPT_EXTERN(T) extern __declspec(dllimport) T NLOPT_STDCALL
+#  endif
 #else
 #  define NLOPT_EXTERN(T) extern T NLOPT_STDCALL
 #endif
@@ -59,6 +62,16 @@ typedef double (*nlopt_func)(unsigned n, const double *x,
                             double *gradient, /* NULL if not needed */
                             void *func_data);
 
+typedef void (*nlopt_mfunc)(unsigned m, double *result,
+                           unsigned n, const double *x,
+                            double *gradient, /* NULL if not needed */
+                            void *func_data);
+
+/* A preconditioner, which preconditions v at x to return vpre. 
+   (The meaning of "preconditioning" is algorithm-dependent.) */
+typedef void (*nlopt_precond)(unsigned n, const double *x, const double *v,
+                             double *vpre, void *data);
+
 typedef enum {
      /* Naming conventions:
 
@@ -132,10 +145,16 @@ typedef enum {
      NLOPT_G_MLSL,
      NLOPT_G_MLSL_LDS,
 
+     NLOPT_LD_SLSQP,
+
+     NLOPT_LD_CCSAQ,
+
+     NLOPT_GN_ESCH,
+
      NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
 } nlopt_algorithm;
 
-extern const char *nlopt_algorithm_name(nlopt_algorithm a);
+NLOPT_EXTERN(const char *) nlopt_algorithm_name(nlopt_algorithm a);
 
 typedef enum {
      NLOPT_FAILURE = -1, /* generic failure code */
@@ -184,9 +203,14 @@ NLOPT_EXTERN(nlopt_result) nlopt_set_min_objective(nlopt_opt opt, nlopt_func f,
 NLOPT_EXTERN(nlopt_result) nlopt_set_max_objective(nlopt_opt opt, nlopt_func f, 
                                                  void *f_data);
 
+NLOPT_EXTERN(nlopt_result) nlopt_set_precond_min_objective(nlopt_opt opt, nlopt_func f, nlopt_precond pre, void *f_data);
+NLOPT_EXTERN(nlopt_result) nlopt_set_precond_max_objective(nlopt_opt opt, nlopt_func f, nlopt_precond pre, void *f_data);
+
 NLOPT_EXTERN(nlopt_algorithm) nlopt_get_algorithm(const nlopt_opt opt);
 NLOPT_EXTERN(unsigned) nlopt_get_dimension(const nlopt_opt opt);
 
+NLOPT_EXTERN(const char*) nlopt_get_errmsg(nlopt_opt opt);
+
 /* constraints: */
 
 NLOPT_EXTERN(nlopt_result) nlopt_set_lower_bounds(nlopt_opt opt, 
@@ -205,12 +229,28 @@ NLOPT_EXTERN(nlopt_result) nlopt_add_inequality_constraint(nlopt_opt opt,
                                                          nlopt_func fc,
                                                          void *fc_data,
                                                          double tol);
+NLOPT_EXTERN(nlopt_result) nlopt_add_precond_inequality_constraint(
+     nlopt_opt opt, nlopt_func fc, nlopt_precond pre, void *fc_data,
+     double tol);
+NLOPT_EXTERN(nlopt_result) nlopt_add_inequality_mconstraint(nlopt_opt opt,
+                                                           unsigned m,
+                                                           nlopt_mfunc fc,
+                                                           void *fc_data,
+                                                           const double *tol);
 
 NLOPT_EXTERN(nlopt_result) nlopt_remove_equality_constraints(nlopt_opt opt);
 NLOPT_EXTERN(nlopt_result) nlopt_add_equality_constraint(nlopt_opt opt,
                                                        nlopt_func h,
                                                        void *h_data,
                                                        double tol);
+NLOPT_EXTERN(nlopt_result) nlopt_add_precond_equality_constraint(
+     nlopt_opt opt, nlopt_func h, nlopt_precond pre, void *h_data,
+     double tol);
+NLOPT_EXTERN(nlopt_result) nlopt_add_equality_mconstraint(nlopt_opt opt,
+                                                         unsigned m,
+                                                         nlopt_mfunc h,
+                                                         void *h_data,
+                                                         const double *tol);
 
 /* stopping criteria: */
 
@@ -230,14 +270,14 @@ NLOPT_EXTERN(nlopt_result) nlopt_get_xtol_abs(const nlopt_opt opt,
                                             double *tol);
 
 NLOPT_EXTERN(nlopt_result) nlopt_set_maxeval(nlopt_opt opt, int maxeval);
-NLOPT_EXTERN(int) nlopt_get_maxeval(nlopt_opt opt);
+NLOPT_EXTERN(int) nlopt_get_maxeval(const nlopt_opt opt);
 
 NLOPT_EXTERN(nlopt_result) nlopt_set_maxtime(nlopt_opt opt, double maxtime);
-NLOPT_EXTERN(double) nlopt_get_maxtime(nlopt_opt opt);
+NLOPT_EXTERN(double) nlopt_get_maxtime(const nlopt_opt opt);
 
 NLOPT_EXTERN(nlopt_result) nlopt_force_stop(nlopt_opt opt);
 NLOPT_EXTERN(nlopt_result) nlopt_set_force_stop(nlopt_opt opt, int val);
-NLOPT_EXTERN(int) nlopt_get_force_stop(nlopt_opt opt);
+NLOPT_EXTERN(int) nlopt_get_force_stop(const nlopt_opt opt);
 
 /* more algorithm-specific parameters */
 
@@ -247,6 +287,9 @@ NLOPT_EXTERN(nlopt_result) nlopt_set_local_optimizer(nlopt_opt opt,
 NLOPT_EXTERN(nlopt_result) nlopt_set_population(nlopt_opt opt, unsigned pop);
 NLOPT_EXTERN(unsigned) nlopt_get_population(const nlopt_opt opt);
 
+NLOPT_EXTERN(nlopt_result) nlopt_set_vector_storage(nlopt_opt opt, unsigned dim);
+NLOPT_EXTERN(unsigned) nlopt_get_vector_storage(const nlopt_opt opt);
+
 NLOPT_EXTERN(nlopt_result) nlopt_set_default_initial_step(nlopt_opt opt, 
                                                         const double *x);
 NLOPT_EXTERN(nlopt_result) nlopt_set_initial_step(nlopt_opt opt, 
@@ -263,6 +306,9 @@ typedef void* (*nlopt_munge)(void *p);
 NLOPT_EXTERN(void) nlopt_set_munge(nlopt_opt opt,
                                  nlopt_munge munge_on_destroy,
                                  nlopt_munge munge_on_copy);
+typedef void* (*nlopt_munge2)(void *p, void *data);
+NLOPT_EXTERN(void) nlopt_munge_data(nlopt_opt opt,
+                                    nlopt_munge2 munge, void *data);
 
 /*************************** DEPRECATED API **************************/
 /* The new "object-oriented" API is preferred, since it allows us to