|
template<typename T, int n, int m> |
|
bool OsqpEigen::Solver::setWarmStart(const Eigen::Matrix<T, n, 1> &primalVariable, |
|
const Eigen::Matrix<T, m, 1> &dualVariable) |
|
{ |
|
if(primalVariable.rows() != m_workspace->data->n){ |
|
debugStream() << "[OsqpEigen::Solver::setWarmStart] The size of the primal variable vector has to be equal to " |
|
<< " the number of variables." |
|
<< std::endl; |
|
return false; |
|
} |
|
|
|
if(dualVariable.rows() != m_workspace->data->m){ |
|
debugStream() << "[OsqpEigen::Solver::setWarmStart] The size of the dual variable vector has to be equal to " |
|
<< " the number of constraints." |
|
<< std::endl; |
|
return false; |
|
} |
|
|
|
m_primalVariables = primalVariable.template cast <c_float>(); |
|
m_dualVariables = dualVariable.template cast <c_float>(); |
|
|
|
return (osqp_warm_start(m_workspace.get(), m_primalVariables.data(), m_dualVariables.data()) == 0); |
|
|
|
} |
|
|
|
template<typename T, int n> |
|
bool OsqpEigen::Solver::setPrimalVariable(const Eigen::Matrix<T, n, 1> &primalVariable) |
|
{ |
|
if(primalVariable.rows() != m_workspace->data->n){ |
|
debugStream() << "[OsqpEigen::Solver::setPrimalVariable] The size of the primal variable vector has to be equal to " |
|
<< " the number of variables." |
|
<< std::endl; |
|
return false; |
|
} |
|
|
|
m_primalVariables = primalVariable.template cast <c_float>(); |
|
|
|
return (osqp_warm_start_x(m_workspace.get(), m_primalVariables.data()) == 0); |
|
} |
|
|
|
|
|
template<typename T, int m> |
|
bool OsqpEigen::Solver::setDualVariable(const Eigen::Matrix<T, m, 1> &dualVariable) |
|
{ |
|
if(dualVariable.rows() != m_workspace->data->m){ |
|
debugStream() << "[OsqpEigen::Solver::setDualVariable] The size of the dual variable vector has to be equal to " |
|
<< " the number of constraints." |
|
<< std::endl; |
|
return false; |
|
} |
|
|
|
m_dualVariables = dualVariable.template cast <c_float>(); |
|
|
|
return (osqp_warm_start_y(m_workspace.get(), m_dualVariables.data()) == 0); |
|
} |
|
|
|
template<typename T, int n> |
|
bool OsqpEigen::Solver::getPrimalVariable(Eigen::Matrix<T, n, 1> &primalVariable) |
|
{ |
|
if(n == Eigen::Dynamic){ |
|
primalVariable.resize(m_workspace->data->n, 1); |
|
} |
|
else{ |
|
if (n != m_workspace->data->n){ |
|
debugStream() << "[OsqpEigen::Solver::getPrimalVariable] The size of the vector has to be equal to the number of " |
|
<< "variables. (You can use an eigen dynamic vector)" |
|
<< std::endl; |
|
return false; |
|
} |
|
} |
|
|
|
primalVariable = Eigen::Map<Eigen::Matrix<c_float, n, 1>>(m_workspace->x, m_workspace->data->n).template cast <T>(); |
|
|
|
return true; |
|
} |
|
|
|
template<typename T, int m> |
|
bool OsqpEigen::Solver::getDualVariable(Eigen::Matrix<T, m, 1> &dualVariable) |
|
{ |
|
if(m == Eigen::Dynamic){ |
|
dualVariable.resize(m_workspace->data->m, 1); |
|
} |
|
else{ |
|
if (m != m_workspace->data->m){ |
|
debugStream() << "[OsqpEigen::Solver::getDualVariable] The size of the vector has to be equal to the number of " |
|
<< "constraints. (You can use an eigen dynamic vector)" |
|
<< std::endl; |
|
return false; |
|
} |
|
} |
|
|
|
dualVariable = Eigen::Map<Eigen::Matrix<c_float, m, 1>>(m_workspace->y, m_workspace->data->m).template cast <T>(); |
|
|
|
return true; |
|
} |