chiark / gitweb /
return error if more than n equality constraints are specified
authorstevenj <stevenj@alum.mit.edu>
Wed, 7 Jul 2010 23:10:56 +0000 (19:10 -0400)
committerstevenj <stevenj@alum.mit.edu>
Wed, 7 Jul 2010 23:10:56 +0000 (19:10 -0400)
darcs-hash:20100707231056-c8de0-74c179fa38352cee82f7ee5e209602be5aafe27b.gz

api/options.c

index 9b2bedaf19c02ab2084ffc0c32dde900c86c5401..fbd32a757682b5fa21a7183972d2516d650864ff 100644 (file)
@@ -431,7 +431,8 @@ NLOPT_STDCALL nlopt_add_equality_mconstraint(nlopt_opt opt, unsigned m,
                                             const double *tol)
 {
      if (!m) return NLOPT_SUCCESS; /* empty constraints are always ok */
-     if (!opt || !equality_ok(opt->algorithm)) return NLOPT_INVALID_ARGS;
+     if (!opt || !equality_ok(opt->algorithm)
+        || nlopt_count_constraints(opt->p, opt->h) + m > opt->n) return NLOPT_INVALID_ARGS;
      return add_constraint(&opt->p, &opt->p_alloc, &opt->h,
                           m, NULL, fc, fc_data, tol);
 }
@@ -441,7 +442,8 @@ NLOPT_STDCALL nlopt_add_equality_constraint(nlopt_opt opt,
                                            nlopt_func fc, void *fc_data,
                                            double tol)
 {
-     if (!opt || !equality_ok(opt->algorithm)) return NLOPT_INVALID_ARGS;
+     if (!opt || !equality_ok(opt->algorithm)
+        || nlopt_count_constraints(opt->p, opt->h) + 1 > opt->n) return NLOPT_INVALID_ARGS;
      return add_constraint(&opt->p, &opt->p_alloc, &opt->h,
                           1, fc, NULL, fc_data, &tol);
 }