Commits

Ruben Martinez-Cantin committed 77c2649

Solved minor bug about direct initialization

Comments (0)

Files changed (1)

src/inneroptimization.cpp

    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -----------------------------------------------------------------------------
 */
+#include <cmath>
 #include <nlopt.h>
 #include "nloptwpr.h"
 
 
     for (int i = 0; i < n; ++i) {
 	l[i] = mDown;	u[i] = mUp;
+	// What if x is undefined?
+	if (x[i] < l[i] || x[i] > u[i])
+	  x[i]=(l[i]+u[i])/2.0;
     }
 
     double (*fpointer)(unsigned int, const double *, double *, void *);
     nlopt_set_lower_bounds(opt, l);
     nlopt_set_upper_bounds(opt, u);
     nlopt_set_min_objective(opt, fpointer, objPointer);
-    nlopt_set_maxeval(opt, round(maxf*coef) ) ;
+    int nfeval = static_cast<int>(static_cast<double>(maxf)*coef);
+    nlopt_set_maxeval(opt, nfeval) ;
 
 
     nlopt_result errortype = nlopt_optimize(opt, x, &fmin);
 	nlopt_set_lower_bounds(opt, l);
 	nlopt_set_upper_bounds(opt, u);
 	nlopt_set_min_objective(opt, fpointer, objPointer);
-	nlopt_set_maxeval(opt, maxf-round(maxf*coef));
+	nlopt_set_maxeval(opt, maxf-nfeval);
 	
 	errortype = nlopt_optimize(opt, x, &fmin);
 	checkNLOPTerror(errortype);