44 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp" 45 #include "AbstractLinAlgPack_VectorMutable.hpp" 63 #include "RTOpPack_RTOpC.hpp" 64 #include "Teuchos_Assert.hpp" 70 static Teuchos::RCP<RTOpPack::ReductTarget> log_bound_barrier_targ;
73 static Teuchos::RCP<RTOpPack::ReductTarget> combined_nu_comp_err_targ;
76 static Teuchos::RCP<RTOpPack::ReductTarget> combined_nu_comp_err_lower_targ;
79 static Teuchos::RCP<RTOpPack::ReductTarget> combined_nu_comp_err_upper_targ;
82 static Teuchos::RCP<RTOpPack::ReductTarget> comp_err_with_mu_targ;
85 static Teuchos::RCP<RTOpPack::ReductTarget> max_near_feas_step_targ;
88 static Teuchos::RCP<RTOpPack::ReductTarget> fraction_to_boundary_targ;
91 static Teuchos::RCP<RTOpPack::ReductTarget> fraction_to_zero_boundary_targ;
94 static Teuchos::RCP<RTOpPack::ReductTarget> max_rel_step_targ;
97 static Teuchos::RCP<RTOpPack::ReductTarget> num_bounded_targ;
114 class init_rtop_server_t {
116 init_rtop_server_t() {
118 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_log_bound_barrier_construct(&log_bound_barrier_op.
op()));
121 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_combined_nu_comp_err_construct(&combined_nu_comp_err_op.
op()));
124 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_combined_nu_comp_err_one_only_construct(&combined_nu_comp_err_lower_op.
op()));
125 combined_nu_comp_err_lower_targ = combined_nu_comp_err_lower_op.
reduct_obj_create();
127 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_combined_nu_comp_err_one_only_construct(&combined_nu_comp_err_upper_op.
op()));
128 combined_nu_comp_err_upper_targ = combined_nu_comp_err_upper_op.
reduct_obj_create();
130 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_comp_err_with_mu_construct(0.0,0.0,&comp_err_with_mu_op.
op()));
133 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_max_near_feas_step_construct(0.0,&max_near_feas_step_op.
op()));
136 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_max_rel_step_construct(&max_rel_step_op.
op()));
139 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_fraction_to_boundary_construct(0.99,&fraction_to_boundary_op.
op()));
142 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_fraction_to_zero_boundary_construct(0.99,&fraction_to_zero_boundary_op.
op()));
143 fraction_to_zero_boundary_targ = fraction_to_zero_boundary_op.
reduct_obj_create();
145 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_num_bounded_construct(0.0,&num_bounded_op.
op()));
148 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_force_in_bounds_construct( &force_in_bounds_op.
op() ));
150 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_force_in_bounds_buffer_construct( 0.01, 0.001, &force_in_bounds_buffer_op.
op() ));
152 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_inv_of_difference_construct( 1.0, &inv_of_difference_op.
op()));
154 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_Correct_Multipliers_construct( -1e50, 0, &correct_lower_bound_multipliers_op.
op()));
156 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_Correct_Multipliers_construct( 1e50, 1, &correct_upper_bound_multipliers_op.
op()));
158 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_multiplier_step_construct( 1.0, -1.0, &lowerbound_multipliers_step_op.
op()));
160 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_multiplier_step_construct( 1.0, 1.0, &upperbound_multipliers_step_op.
op()));
162 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_ele_wise_sqrt_construct( &ele_wise_sqrt_op.
op()));
168 init_rtop_server_t init_rtop_server;
172 AbstractLinAlgPack::value_type
176 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_max_construct(&op.
op()));
178 const Vector* vecs[1] = { &v };
179 apply_op(op,1,vecs,0,NULL,&*reduct_obj);
180 return RTOp_ROp_max_val(op(*reduct_obj));
183 std::pair<AbstractLinAlgPack::value_type,AbstractLinAlgPack::value_type>
187 ,value_type max_bnd_viol
190 const int num_vecs = 4;
192 vecs[num_vecs] = { &xl, &x, &d, &xu };
193 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_max_near_feas_step_set_beta( max_bnd_viol, &max_near_feas_step_op.
op() ));
196 max_near_feas_step_op, num_vecs, vecs, 0, NULL
197 ,&*max_near_feas_step_targ );
199 u = RTOp_ROp_max_near_feas_step_val(max_near_feas_step_op(*max_near_feas_step_targ));;
200 return std::pair<value_type,value_type>(u.alpha_pos,u.alpha_neg);
203 AbstractLinAlgPack::value_type
208 const int num_vecs = 2;
210 vecs[num_vecs] = { &x, &d };
213 max_rel_step_op, num_vecs, vecs, 0, NULL
214 ,&*max_rel_step_targ );
215 return RTOp_ROp_max_rel_step_val(max_rel_step_op(*max_rel_step_targ));
219 AbstractLinAlgPack::value_type
221 const value_type tau,
228 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_fraction_to_boundary_init( tau, &fraction_to_boundary_op.
op() ));
230 const int num_vecs = 4;
232 vecs[num_vecs] = { &x, &d, &xl, &xu };
234 fraction_to_boundary_op, num_vecs, vecs, 0, NULL
235 ,&*fraction_to_boundary_targ );
236 return RTOp_ROp_fraction_to_boundary_val(fraction_to_boundary_op(*fraction_to_boundary_targ));
239 AbstractLinAlgPack::value_type
241 const value_type tau,
246 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_fraction_to_zero_boundary_init( tau, &fraction_to_zero_boundary_op.
op() ));
247 fraction_to_zero_boundary_op.
reduct_obj_reinit(fraction_to_zero_boundary_targ.ptr());
248 const int num_vecs = 2;
250 vecs[num_vecs] = { &x, &d };
252 fraction_to_zero_boundary_op, num_vecs, vecs, 0, NULL
253 ,&*fraction_to_zero_boundary_targ );
254 return RTOp_ROp_fraction_to_zero_boundary_val(fraction_to_zero_boundary_op(*fraction_to_zero_boundary_targ));
257 AbstractLinAlgPack::size_type
260 ,value_type inf_bound
263 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_num_bounded_set_inf_bnd( inf_bound, &num_bounded_op.
op() ));
265 const int num_vecs = 2;
267 vecs[num_vecs] = { &xl, &xu };
269 num_bounded_op, num_vecs, vecs, 0, NULL
270 ,&*num_bounded_targ );
271 return RTOp_ROp_num_bounded_val(num_bounded_op(*num_bounded_targ));
274 AbstractLinAlgPack::value_type
282 const int num_vecs = 3;
284 vecs[num_vecs] = { &x, &xl, &xu };
286 log_bound_barrier_op, num_vecs, vecs, 0, NULL
287 ,&*log_bound_barrier_targ
290 return RTOp_ROp_log_bound_barrier_val(log_bound_barrier_op(*log_bound_barrier_targ));
293 AbstractLinAlgPack::value_type
302 const int num_vecs = 4;
304 vecs[num_vecs] = {&v, &x, &xl, &xu };
306 combined_nu_comp_err_op, num_vecs, vecs, 0, NULL
307 ,&*combined_nu_comp_err_targ
309 return RTOp_ROp_combined_nu_comp_err_val(combined_nu_comp_err_op(*combined_nu_comp_err_targ));
312 AbstractLinAlgPack::value_type
319 combined_nu_comp_err_lower_op.
reduct_obj_reinit(combined_nu_comp_err_lower_targ.ptr());
320 const int num_vecs = 3;
322 vecs[num_vecs] = {&v, &xl, &x};
324 combined_nu_comp_err_lower_op, num_vecs, vecs, 0, NULL
325 ,&*combined_nu_comp_err_lower_targ
327 return RTOp_ROp_combined_nu_comp_err_one_only_val(combined_nu_comp_err_lower_op(*combined_nu_comp_err_lower_targ));
331 AbstractLinAlgPack::value_type
338 combined_nu_comp_err_upper_op.
reduct_obj_reinit(combined_nu_comp_err_upper_targ.ptr());
339 const int num_vecs = 3;
341 vecs[num_vecs] = {&v, &xu, &x};
343 combined_nu_comp_err_upper_op, num_vecs, vecs, 0, NULL
344 ,&*combined_nu_comp_err_upper_targ
346 return RTOp_ROp_combined_nu_comp_err_one_only_val(combined_nu_comp_err_upper_op(*combined_nu_comp_err_upper_targ));
349 AbstractLinAlgPack::value_type
352 ,
const value_type inf_bound
360 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_comp_err_with_mu_init(mu, inf_bound, &comp_err_with_mu_op.
op()));
362 const int num_vecs = 5;
364 vecs[num_vecs] = {&x, &xl, &xu, &vl, &vu};
366 comp_err_with_mu_op, num_vecs, vecs, 0, NULL
367 ,&*comp_err_with_mu_targ
369 return RTOp_ROp_comp_err_with_mu_val(comp_err_with_mu_op(*comp_err_with_mu_targ));
376 ,AbstractLinAlgPack::size_type *max_viol_i
377 ,AbstractLinAlgPack::value_type *max_viol
378 ,AbstractLinAlgPack::value_type *v_i
380 ,AbstractLinAlgPack::value_type *vLU_i
384 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_ROp_max_inequ_viol_construct(&op.
op()));
386 const int num_vecs = 3;
388 vecs[num_vecs] = { &v, &vL, &vU };
390 op, num_vecs, vecs, 0, NULL
394 ro = RTOp_ROp_max_inequ_viol_val(op(*reduct_obj));
395 *max_viol_i = ro.max_viol_i;
396 *max_viol = ro.max_viol;
398 *bnd_type = ro.bnd_type;
400 return *max_viol_i > 0.0;
409 TEUCHOS_TEST_FOR_EXCEPTION(x==NULL,std::logic_error,
"force_in_bounds(...), Error");
411 const Vector* vecs[2] = { &xl, &xu };
413 apply_op(force_in_bounds_op,2,vecs,1,targ_vecs,NULL);
418 const value_type rel_push,
419 const value_type abs_push,
425 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_force_in_bounds_buffer_init( rel_push, abs_push, &force_in_bounds_buffer_op.
op()));
426 const Vector* vecs[2] = { &xl, &xu };
428 apply_op(force_in_bounds_buffer_op,2,vecs,1,targ_vecs,NULL);
433 const value_type alpha
439 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_inv_of_difference_init( alpha, &inv_of_difference_op.
op()));
440 const Vector* vecs[2] = { &v0, &v1 };
442 apply_op(inv_of_difference_op,2,vecs,1,targ_vecs,NULL);
447 ,
const value_type inf_bound_limit
451 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_Correct_Multipliers_init( inf_bound_limit, 0, &correct_lower_bound_multipliers_op.
op()))
452 const Vector* vecs[1] = { &xl };
454 apply_op(correct_lower_bound_multipliers_op,1,vecs,1,targ_vecs,NULL);
459 ,
const value_type inf_bound_limit
463 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_Correct_Multipliers_init( inf_bound_limit, 1, &correct_upper_bound_multipliers_op.
op()));
464 const Vector* vecs[1] = { &xu };
466 apply_op(correct_upper_bound_multipliers_op,1,vecs,1,targ_vecs,NULL);
477 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_multiplier_step_init(mu, -1.0, &lowerbound_multipliers_step_op.
op()));
478 const Vector* vecs[] = { &invXl, &vl, &d_k };
480 apply_op(lowerbound_multipliers_step_op,3,vecs,1,targ_vecs,NULL);
491 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_multiplier_step_init(mu, 1.0, &upperbound_multipliers_step_op.
op()));
492 const Vector* vecs[] = { &invXu, &vu, &d_k };
494 apply_op(upperbound_multipliers_step_op,3,vecs,1,targ_vecs,NULL);
502 apply_op(ele_wise_sqrt_op,0,NULL,1,targ_vecs,NULL);
511 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_max_vec_scalar_construct(min_ele,&op.
op()));
513 apply_op(op,0,NULL,1,targ_vecs,NULL);
522 TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_max_abs_vec_scalar_construct(min_ele,&op.
op()));
524 apply_op(op,0,NULL,1,targ_vecs,NULL);
void max_vec_scalar(value_type min_ele, VectorMutable *y)
Take the maximum value of the vector elements and a scalar.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
value_type IP_comp_err_with_mu(const value_type mu, const value_type inf_bound, const Vector &x, const Vector &xl, const Vector &xu, const Vector &vl, const Vector &vu)
Computes the complementarity error for a primal/dual interior point algorithm using inf norm...
void inv_of_difference(const value_type alpha, const Vector &v0, const Vector &v1, VectorMutable *z)
Computes the inverse of the difference between two vectors.
void force_in_bounds_buffer(const value_type rel_push, const value_type abs_push, const Vector &xl, const Vector &xu, VectorMutable *x)
Force a vector sufficiently within bounds according to a specified absolute and relative buffer...
void upperbound_multipliers_step(const value_type mu, const Vector &invXu, const Vector &vu, const Vector &d_k, VectorMutable *dvu)
Calculates the multiplier step for the upper bounds.
value_type max_element(const Vector &v)
Compute the maximum element in a vector.
void max_abs_vec_scalar(value_type min_ele, VectorMutable *y)
Take the maximum value of the absolute vector elements and a scalar.
value_type max_rel_step(const Vector &x, const Vector &d)
Computes the maximum relative step of x = x + d.
value_type combined_nu_comp_err(const Vector &v, const Vector &x, const Vector &xl, const Vector &xu)
Computes an estimate of the complementarity error.
void reduct_obj_reinit(const Ptr< ReductTarget > &reduct_obj) const
bool max_inequ_viol(const AbstractLinAlgPack::Vector &v, const AbstractLinAlgPack::Vector &vL, const AbstractLinAlgPack::Vector &vU, AbstractLinAlgPack::size_type *max_viol_i, AbstractLinAlgPack::value_type *max_viol, AbstractLinAlgPack::value_type *v_i, int *bnd_type, AbstractLinAlgPack::value_type *vLU_i)
Compute the maximum violation from a set of inequality constraints vL <= v <= vU. ...
size_type num_bounded(const Vector &xl, const Vector &xu, value_type inf_bound)
Count the number of finitly bounded elements in xl <= x <= xu.
value_type fraction_to_boundary(const value_type tau, const Vector &x, const Vector &d, const Vector &xl, const Vector &xu)
value_type fraction_to_zero_boundary(const value_type tau, const Vector &x, const Vector &d)
Teuchos::RCP< ReductTarget > reduct_obj_create() const
void ele_wise_sqrt(VectorMutable *z)
Calculates the sqrt of each element in the vector Pre Condition: all elements of z must be positive...
value_type log_bound_barrier(const Vector &x, const Vector &xl, const Vector &xu)
Computes the log barrier term:
std::pair< value_type, value_type > max_near_feas_step(const Vector &x, const Vector &d, const Vector &xl, const Vector &xu, value_type max_bnd_viol)
Computes the maximum positive and negative step that can be taken that are within the relaxed bounds...
Abstract interface for mutable coordinate vectors {abstract}.
void force_in_bounds(const Vector &xl, const Vector &xu, VectorMutable *x)
Force a vector in bounds.
void correct_lower_bound_multipliers(const Vector &xl, const value_type inf_bound_limit, VectorMutable *vl)
Corrects the lower bound multipliers with infinite bounds.
void lowerbound_multipliers_step(const value_type mu, const Vector &invXl, const Vector &vl, const Vector &d_k, VectorMutable *dvl)
Calculates the multiplier step for lower bounds.
void correct_upper_bound_multipliers(const Vector &xu, const value_type inf_bound_limit, VectorMutable *vu)
Corrects the upper bound multipliers with infinite bounds.
value_type combined_nu_comp_err_upper(const Vector &v, const Vector &x, const Vector &xu)
Computes an estimate of the complementarity error when only the upper bounds are non-infinite.
value_type combined_nu_comp_err_lower(const Vector &v, const Vector &x, const Vector &xl)
Computes an estimate of the complementarity error when only the lower bounds are non-infinite.