46 #include "ConstrainedOptPack_QPInitFixedFreeStd.hpp"
47 #include "ConstrainedOptPack_initialize_Q_R_Q_X.hpp"
49 namespace ConstrainedOptPack {
50 namespace QPSchurPack {
69 ,
const EBounds bnd_fixed[]
70 ,
const DVectorSlice &b_X
71 ,
const MatrixSymOpNonsing &Ko
72 ,
const DVectorSlice &fo
76 ,value_type warning_tol
78 ,
bool print_all_warnings
81 namespace GPMSTP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
84 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
85 "constraints == NULL is not allowed." );
92 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
93 "n_R > constraints->n() is not allowed." );
95 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
96 "g.dim() != constraints->n()." );
97 if(G.rows() != n || G.cols() !=
n)
98 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
99 "G.rows() != constraints->n() or G.cols() != constraints->n()." );
105 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
106 "A->rows() != constraints->n()." );
109 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
110 "b_X.dim() != constraints->n() - n_R." );
111 if(Ko.rows() != n_R+m || Ko.cols() != n_R+
m)
112 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
113 "Ko.rows() != n_R+A->cols() or Ko.cols() != n_R+A->cols()." );
114 if(fo.dim() != n_R+
m)
115 throw std::invalid_argument(
"QPInitFixedFreeStd::initialize(...) : Error, "
116 "fo.dim() != n_R+A->cols()." );
120 const int NOT_SET_YET = -9999;
122 x_init_.assign( n, (EBounds)NOT_SET_YET );
125 l_x_X_map_.assign(n,0);
126 i_x_X_map_.assign(n_X,0);
129 if( i_x_free == NULL ) {
135 for(
const size_type *i_x_R = i_x_free; i_x_R != i_x_free +
n_R; ++i_x_R ) {
136 if( *i_x_R < 1 || *i_x_R > n ) {
137 std::ostringstream omsg;
139 <<
"QPInitFixedFreeStd::initialize(...) : Error, "
140 <<
"i_x_free[" << i_x_R-i_x_free <<
"] = "
141 << (*i_x_R) <<
" is out of bounds";
142 throw std::invalid_argument( omsg.str() );
144 if( x_init_(*i_x_R) != NOT_SET_YET ) {
145 std::ostringstream omsg;
147 <<
"QPInitFixedFreeStd::initialize(...) : Error, "
148 <<
"Duplicate entries for i_x_free[i] = "
150 throw std::invalid_argument( omsg.str() );
152 x_init_(*i_x_R) = FREE;
156 for(
const size_type *i_x_R = i_x_free; i_x_R != i_x_free +
n_R; ++i_x_R ) {
157 x_init_(*i_x_R) = FREE;
168 i_x_X_map_t::iterator
169 i_x_X_map_itr = i_x_X_map_.begin();
171 for(
size_type l = 1; l <= n_X; ++l, ++i_x_X, ++bnd, ++i_x_X_map_itr ) {
172 if( *i_x_X < 1 || *i_x_X > n ) {
173 std::ostringstream omsg;
175 <<
"QPInitFixedFreeStd::initialize(...) : Error, "
176 <<
"i_x_fixed[" << i_x_X-i_x_fixed <<
"] = "
177 << (*i_x_X) <<
" is out of bounds";
178 throw std::invalid_argument( omsg.str() );
181 std::ostringstream omsg;
183 <<
"QPInitFixedFreeStd::initialize(...) : Error, "
184 <<
"bnd_fixed[" << l-1 <<
"] can not equal FREE";
185 throw std::invalid_argument( omsg.str() );
187 if( x_init_(*i_x_X) != NOT_SET_YET ) {
188 std::ostringstream omsg;
190 <<
"QPInitFixedFreeStd::initialize(...) : Error, "
191 <<
"Duplicate entries for i_x_fixed[i] = "
193 throw std::invalid_argument( omsg.str() );
195 x_init_(*i_x_X) = *bnd;
196 l_x_X_map_(*i_x_X) = l;
197 *i_x_X_map_itr = *i_x_X;
201 if( x_init_(i) == NOT_SET_YET ) {
202 std::ostringstream omsg;
204 <<
"QPInitFixedFreeStd::initialize(...) : Error, "
205 <<
"x_init(" << i <<
") has not been set by"
206 " i_x_free[] or i_x_fixed[].";
207 throw std::invalid_argument( omsg.str() );
212 for(
size_type l = 1; l <= n_X; ++l, ++i_x_X, ++bnd, ++i_x_X_map_itr ) {
213 x_init_(*i_x_X) = *bnd;
214 l_x_X_map_(*i_x_X) = l;
215 *i_x_X_map_itr = *i_x_X;
221 Q_R_row_i_.resize( i_x_free ? n_R : 0 );
222 Q_R_col_j_.resize( i_x_free ? n_R : 0 );
223 Q_X_row_i_.resize(n_X);
224 Q_X_col_j_.resize(n_X);
226 n_R,n_X,i_x_free,i_x_fixed,test_setup
227 ,n_R && i_x_free ? &Q_R_row_i_[0] : NULL
228 ,n_R && i_x_free ? &Q_R_col_j_[0] : NULL
230 ,n_X ? &Q_X_row_i_[0] : NULL
231 ,n_X ? &Q_X_col_j_[0] : NULL
239 g_.bind(const_cast<DVectorSlice&>(g));
242 b_X_.bind(const_cast<DVectorSlice&>(b_X));
244 fo_.bind(const_cast<DVectorSlice&>(fo));
252 assert_initialized();
258 assert_initialized();
264 assert_initialized();
270 assert_initialized();
282 assert_initialized();
288 assert_initialized();
294 assert_initialized();
300 assert_initialized();
306 assert_initialized();
312 assert_initialized();
318 assert_initialized();
324 assert_initialized();
330 assert_initialized();
336 assert_initialized();
337 return *constraints_;
342 assert_initialized();
343 return *constraints_;
348 void QPInitFixedFreeStd::assert_initialized()
const
351 throw std::logic_error(
"QPInitFixedFreeStd::assert_initialized(), Error "
352 "object not initialized\n" );
Constraints & constraints()
const x_init_t & x_init() const
const MatrixSymOpNonsing & Ko() const
void initialize(const DVectorSlice &g, const MatrixSymOp &G, const MatrixOp *A, size_type n_R, const size_type i_x_free[], const size_type i_x_fixed[], const EBounds bnd_fixed[], const DVectorSlice &b_X, const MatrixSymOpNonsing &Ko, const DVectorSlice &fo, Constraints *constraints, std::ostream *out=NULL, bool test_setup=false, value_type warning_tol=1e-10, value_type error_tol=1e-5, bool print_all_warnings=false)
Initialize.
const GenPermMatrixSlice & Q_X() const
const DVectorSlice g() const
const MatrixSymOp & G() const
const l_x_X_map_t & l_x_X_map() const
const MatrixOp & A() const
const DVectorSlice fo() const
QPInitFixedFreeStd()
Construct uninitialized.
const GenPermMatrixSlice & Q_R() const
Utility class for a ranged check vector.
virtual size_type n() const =0
Represents the extra constraints in the QP to be satisfied by the schur complement QP solver QPSchur ...
const DVectorSlice b_X() const
const i_x_X_map_t & i_x_X_map() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)