MoochoPack : Framework for Large-Scale Optimization Algorithms  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MoochoPack_CalcD_vStep_Step.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <limits>
43 #include <ostream>
44 #include <iostream>
45 
46 #include "MoochoPack_CalcD_vStep_Step.hpp"
47 #include "MoochoPack_IpState.hpp"
48 #include "MoochoPack_moocho_algo_conversion.hpp"
49 #include "IterationPack_print_algorithm_step.hpp"
50 //#include "ConstrainedOptPack_print_vector_change_stats.hpp"
51 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp"
52 #include "AbstractLinAlgPack_VectorMutable.hpp"
53 #include "AbstractLinAlgPack_VectorStdOps.hpp"
54 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
55 #include "AbstractLinAlgPack_VectorOut.hpp"
56 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
57 #include "Teuchos_dyn_cast.hpp"
58 
59 
61  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
62  {
63  using Teuchos::dyn_cast;
64  using IterationPack::print_algorithm_step;
68 
69  NLPAlgo &algo = rsqp_algo(_algo);
70  IpState &s = dyn_cast<IpState>(_algo.state());
71  NLP &nlp = algo.nlp();
72 
73  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
74  std::ostream& out = algo.track().journal_out();
75 
76  // print step header.
77  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) )
78  {
79  using IterationPack::print_algorithm_step;
80  print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
81  }
82 
83  // Get iteration quantities
84  const value_type& mu = s.barrier_parameter().get_k(0);
85  const Vector &d_k = s.d().get_k(0);
86  const MatrixSymDiagStd& invXl = s.invXl().get_k(0);
87  const MatrixSymDiagStd& invXu = s.invXu().get_k(0);
88  const MatrixSymDiagStd& Vl = s.Vl().get_k(0);
89  const MatrixSymDiagStd& Vu = s.Vu().get_k(0);
90 
91  VectorMutable& dvl_k = s.dvl().set_k(0);
92  VectorMutable& dvu_k = s.dvu().set_k(0);
93 
94  lowerbound_multipliers_step(mu, invXl.diag(), Vl.diag(), d_k, &dvl_k);
95  upperbound_multipliers_step(mu, invXu.diag(), Vu.diag(), d_k, &dvu_k);
96 
97  /*
98  // dvl = mu*invXl*e - vl - invXl*Vl*d_k
99  dvl_k = 0;
100  ele_wise_prod(-1.0, invXl.diag(), Vl.diag(), &dvl_k);
101  ele_wise_prod(1.0, dvl_k, d_k, &dvl_k);
102 
103  std::cout << "d_k =\n" << d_k;
104  std::cout << "-invXl*Vl*d_k = \n" << dvl_k;
105 
106  dvl_k.axpy(-1.0, Vl.diag());
107 
108  std::cout << "-vl-invXl*Vl*d_k = \n" << dvl_k;
109 
110  dvl_k.axpy(mu, invXl.diag());
111 
112  std::cout << "dvl_k = \n" << dvl_k;
113 
114  // dvu = mu*invXu*e - vu + invXu*Vu*d_k
115  dvu_k = 0;
116  ele_wise_prod(1.0, invXu.diag(), Vu.diag(), &dvu_k);
117  ele_wise_prod(1.0, dvu_k, d_k, &dvu_k);
118 
119  dvu_k.axpy(-1.0, Vu.diag());
120 
121  dvu_k.axpy(mu, invXu.diag());
122  */
123  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) )
124  {
125  out << "\nx_k = \n" << s.x().get_k(0)
126  << "\nxl = \n" << nlp.xl()
127  << "\nxu = \n" << nlp.xu()
128  << "\ndvl_k = \n" << dvl_k
129  << "\ndvu_k = \n" << dvu_k;
130  }
131 
132  return true;
133  }
134 
136  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
137  , std::ostream& out, const std::string& L ) const
138 {
139  out
140  << L << "*** Calculates the search direction for the dual variables\n"
141  << L << "dvl_k = mu*invXl_k*e - vl_k - invXl_k*Vl_k*d_k\n"
142  << L << "dvu_k = mu*invXu_k*e - vu_k + invXu_k*Vu_k*d_k\n";
143 }
void upperbound_multipliers_step(const value_type mu, const Vector &invXu, const Vector &vu, const Vector &d_k, VectorMutable *dvu)
T_To & dyn_cast(T_From &from)
rSQP Algorithm control class.
virtual std::ostream & journal_out() const
void ele_wise_prod(const value_type &alpha, const Vector &v_rhs1, const Vector &v_rhs2, VectorMutable *v_lhs)
AlgorithmTracker & track()
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
void print_step(const Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss, std::ostream &out, const std::string &leading_str) const
AlgorithmState & state()
void lowerbound_multipliers_step(const value_type mu, const Vector &invXl, const Vector &vl, const Vector &d_k, VectorMutable *dvl)