Page MenuHomec4science

ncp_function.hpp
No OneTemporary

File Metadata

Created
Fri, Jun 28, 11:45

ncp_function.hpp

/*-------------------------------------------------------
- Module : micpsolver
- File : ncp_function.hpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#ifndef SPECMICP_MICPSOLVE_NCPFUNCTION_HPP
#define SPECMICP_MICPSOLVE_NCPFUNCTION_HPP
#include <cassert>
//! \file ncp_function.hpp implements the ncp function
namespace specmicp {
namespace micpsolver {
//! \brief The Fisher-Burmeister NCP-function
//!
//! @param a a scalar, first argument of the NCP-function
//! @param b a scalar, second argument of the NCP-function
//!
//! References:
//! - \cite Munson2001
//! - \cite Facchinei2003
template <typename ScalarT>
ScalarT fisher_burmeister(ScalarT a, ScalarT b)
{
ScalarT s = std::abs(a) + std::abs(b);
if (s != 0)
{
s = s*std::sqrt((a*a)/(s*s) + (b*b)/(s*s));
}
if ( a + b <= 0)
{
return s - (a + b);
}
else
{
return -2*a*b/(s + (a+b));
}
}
//! \brief The penalized Fisher-Burmeister NCP-function
//!
//! @param t in (0, 1), penalization factor
//! @param a a scalar, first argument of the NCP-function
//! @param b a scalar, second argument of the NCP-function
//!
//! References:
//! - \cite Chen1997a
//! - \cite Chen2000
//! - \cite Munson2001
template <typename ScalarT>
inline ScalarT penalized_fisher_burmeister(ScalarT a, ScalarT b, ScalarT t)
{
assert(t >= 0);
assert(t <= 1);
return t*fisher_burmeister(a,b)-(1-t)*std::max(0.0, a)*std::max(0.0, b);
}
} // end namespace micpsolver
} // end namespace specmicp
#endif // SPECMICP_MICPSOLVE_NCPFUNCTION_HPP

Event Timeline