/* -*- mona-c++ -*-
* Copyright (c) Leipzig, Madrid 2004 - 2008
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// $Id: goal.cc,v 1.10 2005/06/08 16:10:55 gerddie Exp $
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <libmona/goal.hh>
#include <libmona/monaHelprs.hh>
#include <libmona/plugin_handler.cxx>
#include <stdexcept>
#include <cassert>
MONA_NAMESPACE_BEGIN
CGoal::CGoal(CGoal::vector& pos, const CGoal::vector& min, const CGoal::vector& max):
_M_evaluations(0),
_M_pos(pos),
_M_min(min),
_M_max(max),
_M_range(max - min)
{
}
CGoal::~CGoal()
{
}
const CGoal::vector& CGoal::get_position() const
{
return _M_pos;
}
void CGoal::set_position(const CGoal::vector& pos)
{
_M_pos = pos;
do_set_position(pos);
}
size_t CGoal::size()const
{
if (_M_pos.size() != _M_range.size())
throw std::invalid_argument("CGoal::CGoal: pos.size() != range.size()");
return _M_pos.size();
}
double boundary_penalty(double x)
{
if (x < 3)
return expf(x);
else
return expf(3.0) + x - 3.0;
}
double CGoal::operator()(const CGoal::vector& x) const
{
assert(x.size() == _M_pos.size());
++_M_evaluations;
double result = do_evaluate(x);
// penalize unenforced boundary condition
for (size_t i = 0; i < x.size(); ++i) {
if (x[i] < _M_min[i]) {
result += boundary_penalty(_M_min[i] - x[i]);
break;
}
if (x[i] > _M_max[i]) {
result += boundary_penalty(x[i] - _M_max[i]);
break;
}
}
return result;
}
size_t CGoal::get_evaluations()const
{
return _M_evaluations;
}
const CGoal::vector& CGoal::get_range() const
{
return _M_range;
}
const CGoal::vector& CGoal::get_min() const
{
return _M_min;
}
const CGoal::vector& CGoal::get_max() const
{
return _M_max;
}
void CGoal::do_set_position(const CGoal::vector& pos)
{
}
FGradientFreeOptimiserBase::~FGradientFreeOptimiserBase()
{
}
CGFOptimiserFactory::CGFOptimiserFactory(char const * const name):
TFactory< FGradientFreeOptimiserBase>(name, "gfoptimiser","vscalar")
{
}
std::string const CGFOptimiserFactory::get_plugin_searchpattern()
{
return ".*_gf_optimiser.so";
}
CGoalFactory::CGoalFactory(char const * const name):
TFactory<CGoal>(name, "gfgoal","vscalar")
{
}
std::string const CGoalFactory::get_plugin_searchpattern()
{
return ".*_gf_goal.so";
}
template class TPluginHandler<CGFOptimiserFactory>;
template class TPluginHandler<CGoalFactory>;
MONA_NAMESPACE_END
/*
$Log: goal.cc,v $
Revision 1.10 2005/06/08 16:10:55 gerddie
playing around
Revision 1.9 2005/05/24 14:13:34 gerddie
save the work on symmetric registration
Revision 1.8 2005/05/23 17:10:09 gerddie
ssdsym test cought some errors
Revision 1.7 2005/05/23 14:33:14 gerddie
slight changes in the factory infrastructure
Revision 1.6 2005/05/20 10:44:33 gerddie
rigidreggoal compiles
Revision 1.5 2005/05/19 13:08:48 gerddie
some tweaking in genetic optimisation
Revision 1.4 2005/05/19 07:55:37 gerddie
change goal vector handling to valarray
Revision 1.3 2005/05/12 13:14:58 gerddie
Add a function to get the goal range
Revision 1.2 2005/05/12 09:25:15 gerddie
make the gradfree optimiser a plugin based entity
Revision 1.1 2005/05/11 22:58:32 gerddie
add seperate goal file
*/