// Copyright (C) 2011 Deltares
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program 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, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

/**
 * @file
 * @brief xxx
 * @author Dirk Schwanenberg
 * @version 1.0
 * @date 2011
 */

#include "rtcToolsSA.h"

// constructors
rtcToolsSA::rtcToolsSA(rtcToolsRuntime *tool, rtcRuntimeConfigSettings::SA par)
{
	this->n = tool->getN();
	this->tool = tool;
	this->par = par;
}

//destructor
rtcToolsSA::~rtcToolsSA()
{
	//
}

rtcToolsRuntime *saTemp;
double safunc(int n, double* xArray)
{
	// compute objective function value
	double obj_value = saTemp->simulate(n, xArray);
	if (obj_value!=obj_value) obj_value = 10e20;
	printf(" obj_value = %lf\n", obj_value);
	
	// free memory
	delete[] xArray;

	return obj_value;
}

int rtcToolsSA::optimize()
{
	double* x = new double[n];
	double* x_l = new double[n];
	double* x_u = new double[n];
	tool->get_bounds_info(n, x_l, x_u, 0, (double*)0, (double*)0);

	for (int i=0; i<n; i++) {
		x[i] = x_l[i];
	}

	saTemp = tool;

	printf("Amoeba started\n");
	/*Amoeba sa(par.ftoll);
	sa.minimize(x, par.dels, safunc);*/
	printf("Amoeba finalized\n");

	delete[] x;
	delete[] x_l;
	delete[] x_u;

	return 0;
}