1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 08:55:37 +00:00
LatAnalyze/lib/Numerical/Minimizer.cpp

195 lines
4.1 KiB
C++
Raw Normal View History

2014-02-20 20:21:45 +00:00
/*
* Minimizer.cpp, part of LatAnalyze 3
*
2020-01-13 09:57:06 +00:00
* Copyright (C) 2013 - 2020 Antonin Portelli
2014-02-20 20:21:45 +00:00
*
* LatAnalyze 3 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 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze 3 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 LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/Numerical/Minimizer.hpp>
2014-03-13 18:51:01 +00:00
#include <LatAnalyze/includes.hpp>
2014-02-20 20:21:45 +00:00
using namespace std;
using namespace Latan;
// access //////////////////////////////////////////////////////////////////////
void Minimizer::resize(const Index dim)
{
2015-11-13 16:25:16 +00:00
const Index oldDim = getDim();
Solver::resize(dim);
highLimit_.conservativeResize(dim);
lowLimit_.conservativeResize(dim);
hasHighLimit_.conservativeResize(dim);
hasLowLimit_.conservativeResize(dim);
2015-11-13 16:25:16 +00:00
if (dim > oldDim)
{
highLimit_.segment(oldDim, dim - oldDim).fill(0.);
highLimit_.segment(oldDim, dim - oldDim).fill(0.);
lowLimit_.segment(oldDim, dim - oldDim).fill(0.);
hasHighLimit_.segment(oldDim, dim - oldDim).fill(false);
hasLowLimit_.segment(oldDim, dim - oldDim).fill(false);
}
2014-10-14 16:34:27 +01:00
}
2016-04-12 20:10:37 +01:00
#define checkSupport \
if (!supportLimits())\
{\
LATAN_ERROR(Implementation, "minimizer does not support limits");\
}
2014-10-14 16:34:27 +01:00
double Minimizer::getHighLimit(const Index i) const
{
2016-04-12 20:10:37 +01:00
checkSupport;
2016-04-01 21:39:49 +01:00
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
2014-10-14 16:34:27 +01:00
return highLimit_(i);
}
const DVec & Minimizer::getHighLimit(const PlaceHolder ph __dumb) const
2014-10-14 16:34:27 +01:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
return highLimit_;
}
double Minimizer::getLowLimit(const Index i) const
{
2016-04-12 20:10:37 +01:00
checkSupport;
2016-04-01 21:39:49 +01:00
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
2014-10-14 16:34:27 +01:00
return lowLimit_(i);
}
const DVec & Minimizer::getLowLimit(const PlaceHolder ph __dumb) const
2014-10-14 16:34:27 +01:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
return lowLimit_;
}
bool Minimizer::hasHighLimit(const Index i) const
{
2016-04-12 20:10:37 +01:00
checkSupport;
2016-04-01 21:39:49 +01:00
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
2014-10-14 16:34:27 +01:00
return hasHighLimit_(i);
}
bool Minimizer::hasLowLimit(const Index i) const
{
2016-04-12 20:10:37 +01:00
checkSupport;
2016-04-01 21:39:49 +01:00
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
2014-10-14 16:34:27 +01:00
return hasLowLimit_(i);
}
void Minimizer::setHighLimit(const Index i, const double l)
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
if (i >= getDim())
{
2016-04-01 21:39:49 +01:00
resize(i + 1);
2014-10-14 16:34:27 +01:00
}
2016-04-05 20:55:11 +01:00
highLimit_(i) = l;
useHighLimit(i);
2014-10-14 16:34:27 +01:00
}
void Minimizer::setHighLimit(const PlaceHolder ph __dumb, const DVec &l)
2014-10-14 16:34:27 +01:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
if (l.size() != getDim())
{
2016-04-01 21:39:49 +01:00
resize(l.size());
2014-10-14 16:34:27 +01:00
}
2016-04-05 20:55:11 +01:00
highLimit_ = l;
useHighLimit(_);
2014-10-14 16:34:27 +01:00
}
void Minimizer::setLowLimit(const Index i, const double l)
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
if (i >= getDim())
{
2016-04-01 21:39:49 +01:00
resize(i + 1);
2014-10-14 16:34:27 +01:00
}
2016-04-05 20:55:11 +01:00
lowLimit_(i) = l;
useLowLimit(i);
2014-10-14 16:34:27 +01:00
}
2014-02-20 20:21:45 +00:00
void Minimizer::setLowLimit(const PlaceHolder ph __dumb, const DVec &l)
2014-02-20 20:21:45 +00:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
if (l.size() != getDim())
{
2016-04-01 21:39:49 +01:00
resize(l.size());
2014-10-14 16:34:27 +01:00
}
2016-04-05 20:55:11 +01:00
lowLimit_ = l;
useLowLimit(_);
2014-02-20 20:21:45 +00:00
}
2014-10-14 16:34:27 +01:00
void Minimizer::useHighLimit(const Index i, const bool use)
2014-02-20 20:21:45 +00:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
if (i >= getDim())
{
2016-04-01 21:39:49 +01:00
resize(i + 1);
2014-10-14 16:34:27 +01:00
}
2016-04-05 20:55:11 +01:00
hasHighLimit_(i) = use;
2014-02-20 20:21:45 +00:00
}
void Minimizer::useHighLimit(const PlaceHolder ph __dumb, const bool use)
2014-02-20 20:21:45 +00:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
hasHighLimit_.fill(use);
2014-02-20 20:21:45 +00:00
}
2014-10-14 16:34:27 +01:00
void Minimizer::useLowLimit(const Index i, const bool use)
2014-02-20 20:21:45 +00:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
if (i >= getDim())
{
2016-04-01 21:39:49 +01:00
resize(i + 1);
2014-10-14 16:34:27 +01:00
}
2016-04-05 20:55:11 +01:00
hasLowLimit_(i) = use;
2014-02-20 20:21:45 +00:00
}
void Minimizer::useLowLimit(const PlaceHolder ph __dumb, const bool use)
2014-02-20 20:21:45 +00:00
{
2016-04-12 20:10:37 +01:00
checkSupport;
2014-10-14 16:34:27 +01:00
hasLowLimit_.fill(use);
2014-02-20 20:21:45 +00:00
}
2016-04-01 21:39:49 +01:00
unsigned int Minimizer::getMaxPass(void) const
{
return maxPass_;
}
void Minimizer::setMaxPass(const unsigned int maxPass)
{
maxPass_ = maxPass;
}