-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d23d478
commit 44b22cc
Showing
2 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/** | ||
* @file Settings.h | ||
* @author Giulio Romualdi | ||
* @copyright Released under the terms of the MIT License. | ||
* @date 2021 | ||
*/ | ||
|
||
#ifndef SCSEIGEN_SETTINGS_H | ||
#define SCSEIGEN_SETTINGS_H | ||
|
||
#include <memory> | ||
|
||
/** | ||
* ScsEigen namespace. | ||
*/ | ||
namespace ScsEigen | ||
{ | ||
/** | ||
* Settings class is a wrapper of the SCS Settings struct. | ||
* @note You can find further information here: | ||
* https://github.com/cvxgrp/scs/blob/48dfbe81caad2162c3ce5757faccdb3f3d31e142/include/scs.h#L44-L63 | ||
*/ | ||
class Settings | ||
{ | ||
struct Impl; | ||
std::unique_ptr<Impl> m_pimpl; | ||
|
||
public: | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
Settings(); | ||
|
||
/** | ||
* Destructor, Required for the pimpl idiom. | ||
*/ | ||
~Settings(); | ||
|
||
/** | ||
* Enable the heuristic data rescaling. | ||
* @param normalize if true the rescaling is enabled. | ||
* @warning If you call this function you should reinitialize the problem. | ||
*/ | ||
void normalize(bool normalize); | ||
|
||
/** | ||
* Is rescaling enabled? | ||
* @return true if the rescaling is enabled. | ||
*/ | ||
bool normalize() const; | ||
|
||
/** | ||
* Set the scaling factor. | ||
* @param scale a positive number. | ||
* @return true in case of success, false otherwise. | ||
* @warning If you call this function you should reinitialize the problem. | ||
*/ | ||
bool scale(double scale); | ||
|
||
/** | ||
* Get the scaling factor | ||
* @return the scaling factor. | ||
*/ | ||
double scale() const; | ||
|
||
/** | ||
* Set the equality constraint scaling. | ||
* @param rho a positive number. | ||
* @return true in case of success, false otherwise. | ||
* @warning If you call this function you should reinitialize the problem. | ||
*/ | ||
bool rho(double rho); | ||
|
||
/** | ||
* Get the scaling factor. | ||
* @return the scaling factor. | ||
*/ | ||
double rho() const; | ||
|
||
/** | ||
* Set the maximum number of iterations. | ||
* @param iterations number of iterations | ||
* @return true in case of success, false otherwise. | ||
*/ | ||
bool maxIterations(int iterations); | ||
|
||
/** | ||
* Get the number of iterations. | ||
* @return the iterations. | ||
*/ | ||
int maxIterations() const; | ||
|
||
/** | ||
* Set the convergence tolerance. | ||
* @param eps convergence tolerance. | ||
* @return true in case of success, false otherwise. | ||
*/ | ||
bool eps(double eps); | ||
|
||
/** | ||
* Get the convergence tolerance. | ||
* @return the tolerance. | ||
*/ | ||
double eps() const; | ||
|
||
/** | ||
* Set the relaxation parameter. | ||
* @param alpha relaxation parameter. | ||
* @return true in case of success, false otherwise. | ||
*/ | ||
bool alpha(double alpha); | ||
|
||
/** | ||
* Get the relaxation parameter. | ||
* @return the parameter. | ||
*/ | ||
double alpha() const; | ||
|
||
/** | ||
* Set the verbosity of the solver. | ||
* @param isVerbose if true the solver will be verbose. | ||
*/ | ||
void verbose(bool isVerbose); | ||
|
||
/** | ||
* Is solver verbose? | ||
* @return true if the solver is verbose. | ||
*/ | ||
bool verbose() const; | ||
|
||
/** | ||
* Enable the warm start. | ||
* @param warmStart if true the warm start is enable | ||
*/ | ||
void warmStart(bool warmStart); | ||
|
||
/** | ||
* Is warm start enabled? | ||
* @return true if warm start is enabled. | ||
*/ | ||
bool warmStart() const; | ||
|
||
/** | ||
* Set the memory for acceleration. | ||
* @param accelerationLookBack memory acceleration. | ||
* @return true if the solver is verbose. | ||
*/ | ||
bool accelerationLookback(int accelerationLookback); | ||
|
||
/** | ||
* Get the memory acceleration. | ||
* @return the memory acceleration. | ||
*/ | ||
int accelerationLookback(); | ||
|
||
/** | ||
* Set the filename used to store the data. | ||
* @filename name of the file where the data will be stored. | ||
*/ | ||
void writeDataFilename(std::string_view filename); | ||
|
||
/** | ||
* Get the filename. | ||
* @return a string containing the filename. | ||
*/ | ||
std::string_view writeDataFilename() const; | ||
}; | ||
|
||
} // namespace ScsEigen | ||
|
||
#endif // SCSEIGEN_SETTINGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* @file Settings.cpp | ||
* @author Giulio Romualdi | ||
* @copyright Released under the terms of the MIT License. | ||
* @date 2021 | ||
*/ | ||
|
||
// scs | ||
#include <scs.h> | ||
|
||
#include <ScsEigen/Settings.h> | ||
|
||
using namespace ScsEigen; | ||
|
||
struct Settings::Impl | ||
{ | ||
ScsSettings settings; /**< Scs Setting struct */ | ||
std::string filename; /**< name of the file where the solution is stored. */ | ||
}; | ||
|
||
Settings::Settings() | ||
: m_pimpl(std::make_unique<Impl>()) | ||
{ | ||
} | ||
|
||
Settings::~Settings() = default; | ||
|
||
void Settings::normalize(bool normalize) | ||
{ | ||
m_pimpl->settings.normalize = normalize ? 1 : 0; | ||
} | ||
bool Settings::normalize() const | ||
{ | ||
return m_pimpl->settings.normalize == 1; | ||
} | ||
|
||
bool Settings::scale(double scale) | ||
{ | ||
if (scale < 0) | ||
{ | ||
return false; | ||
} | ||
|
||
m_pimpl->settings.scale = scale; | ||
return true; | ||
} | ||
|
||
double Settings::scale() const | ||
{ | ||
return m_pimpl->settings.scale; | ||
} | ||
|
||
bool Settings::rho(double rho) | ||
{ | ||
if (rho < 0) | ||
{ | ||
return false; | ||
} | ||
|
||
m_pimpl->settings.rho_x = rho; | ||
return true; | ||
} | ||
|
||
double Settings::rho() const | ||
{ | ||
return m_pimpl->settings.rho_x; | ||
} | ||
|
||
bool Settings::maxIterations(int iterations) | ||
{ | ||
if (iterations < 0) | ||
{ | ||
return false; | ||
} | ||
|
||
m_pimpl->settings.max_iters = iterations; | ||
return true; | ||
} | ||
|
||
int Settings::maxIterations() const | ||
{ | ||
return m_pimpl->settings.max_iters; | ||
} | ||
|
||
bool Settings::eps(double eps) | ||
{ | ||
if (eps < 0) | ||
{ | ||
return false; | ||
} | ||
|
||
m_pimpl->settings.eps = eps; | ||
return true; | ||
} | ||
|
||
double Settings::eps() const | ||
{ | ||
return m_pimpl->settings.eps; | ||
} | ||
|
||
bool Settings::alpha(double alpha) | ||
{ | ||
if (alpha < 0) | ||
{ | ||
return false; | ||
} | ||
|
||
m_pimpl->settings.alpha = alpha; | ||
return true; | ||
} | ||
|
||
double Settings::alpha() const | ||
{ | ||
return m_pimpl->settings.alpha; | ||
} | ||
|
||
void Settings::verbose(bool verbose) | ||
{ | ||
m_pimpl->settings.verbose = verbose ? 1 : 0; | ||
} | ||
|
||
bool Settings::verbose() const | ||
{ | ||
return m_pimpl->settings.verbose == 1; | ||
} | ||
|
||
void Settings::warmStart(bool warmStart) | ||
{ | ||
m_pimpl->settings.warm_start = warmStart ? 1 : 0; | ||
} | ||
|
||
bool Settings::warmStart() const | ||
{ | ||
return m_pimpl->settings.warm_start == 1; | ||
} | ||
|
||
bool Settings::accelerationLookback(int accelerationLookback) | ||
{ | ||
if (accelerationLookback < 0) | ||
{ | ||
return false; | ||
} | ||
|
||
m_pimpl->settings.acceleration_lookback = accelerationLookback; | ||
return true; | ||
} | ||
|
||
void Settings::writeDataFilename(std::string_view filename) | ||
{ | ||
m_pimpl->filename = filename; | ||
m_pimpl->settings.write_data_filename = m_pimpl->filename.c_str(); | ||
} | ||
|
||
std::string_view Settings::writeDataFilename() const | ||
{ | ||
return m_pimpl->settings.write_data_filename; | ||
} |