source: branches/dev/Algorithm/IpAlgBuilder.cpp @ 517

Last change on this file since 517 was 517, checked in by andreasw, 14 years ago
  • enabled warm start option for using same application and also for solving problems with identical structure
  • minor cosmetic changes
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1// Copyright (C) 2004, 2005 International Business Machines and others.
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// $Id: IpAlgBuilder.cpp 517 2005-09-13 22:51:57Z andreasw $
6//
7// Authors:  Carl Laird, Andreas Waechter     IBM    2004-09-29
8
9#include "IpAlgBuilder.hpp"
10
11#include "IpStdAugSystemSolver.hpp"
12#include "IpAugRestoSystemSolver.hpp"
13#include "IpPDFullSpaceSolver.hpp"
14#include "IpPDPerturbationHandler.hpp"
15#include "IpOptErrorConvCheck.hpp"
16#include "IpFilterLineSearch.hpp"
17#include "IpMonotoneMuUpdate.hpp"
18#include "IpAdaptiveMuUpdate.hpp"
19#include "IpLoqoMuOracle.hpp"
20#include "IpProbingMuOracle.hpp"
21#include "IpQualityFunctionMuOracle.hpp"
22#include "IpRestoMinC_1Nrm.hpp"
23#include "IpLeastSquareMults.hpp"
24#include "IpDefaultIterateInitializer.hpp"
25#include "IpWarmStartIterateInitializer.hpp"
26#include "IpOrigIterationOutput.hpp"
27#include "IpRestoIterationOutput.hpp"
28#include "IpRestoFilterConvCheck.hpp"
29#include "IpRestoIterateInitializer.hpp"
30#include "IpRestoRestoPhase.hpp"
31#include "IpTSymLinearSolver.hpp"
32
33#ifdef HAVE_MA27
34# include "IpMa27TSolverInterface.hpp"
35#endif
36#ifdef HAVE_MC19
37# include "IpMc19TSymScalingMethod.hpp"
38#endif
39#ifdef HAVE_PARDISO
40# include "IpPardisoSolverInterface.hpp"
41#endif
42#ifdef HAVE_TAUCS
43# include "IpTAUCSSolverInterface.hpp"
44#endif
45
46namespace Ipopt
47{
48#ifdef IP_DEBUG
49  static const Index dbg_verbosity = 0;
50#endif
51
52  void AlgorithmBuilder::RegisterOptions(SmartPtr<RegisteredOptions> roptions)
53  {
54    roptions->SetRegisteringCategory("Undocumented");
55    roptions->AddStringOption3(
56      "linear_solver",
57      "Linear solver used for step computations.",
58      "ma27",
59      "ma27", "use the Harwell routine MA27",
60      "pardiso", "use the Pardiso package",
61      "taucs", "use TAUCS package",
62      "Determines which linear algebra package is to be used for the "
63      "solution of the augmented linear system (for obtaining the search "
64      "directions). "
65      "Note that depending on your Ipopt installation, not all "
66      "options may be available.");
67    roptions->SetRegisteringCategory("Linear Solver");
68    roptions->AddStringOption2(
69      "linear_system_scaling",
70      "Method for scaling the linear system.",
71      "none",
72      "none", "no scaling will be performed",
73      "mc19", "use the Harwell routine mc19",
74      "Determines the method used to compute symmetric scaling "
75      "factors for the augmented system. This scaling will be done "
76      "in addition to any NLP problem scaling.");
77
78    roptions->SetRegisteringCategory("Mu Update");
79    roptions->AddStringOption2(
80      "mu_strategy",
81      "Update strategy for barrier parameter.",
82      "monotone",
83      "monotone", "use the monotone (Fiacco-McCormick) strategy",
84      "adaptive", "use the adaptive update strategy",
85      "Determines which barrier parameter update strategy is to be used.");
86    roptions->AddStringOption3(
87      "mu_oracle",
88      "Oracle for a new barrier parameter in the adaptive strategy.",
89      "probing",
90      "probing", "Mehrotra's probing heuristic",
91      "loqo", "LOQO's centrality rule",
92      "quality_function", "minimize a quality function",
93      "Determines how a new barrier parameter is computed in each "
94      "\"free-mode\" iteration of the adaptive barrier parameter "
95      "strategy. (Only considered if \"adaptive\" is selected for "
96      "option \"mu_strategy\").");
97    roptions->AddStringOption4(
98      "fixed_mu_oracle",
99      "Oracle for the barrier parameter when switching to fixed mode.",
100      "average_compl",
101      "probing", "Mehrotra's probing heuristic",
102      "loqo", "LOQO's centrality rule",
103      "quality_function", "minimize a quality function",
104      "average_compl", "base on current average complementarity",
105      "Determines how the first value of the barrier parameter should be "
106      "computed when switching to the \"monotone mode\" in the adaptive "
107      "strategy. (Only considered if \"adaptive\" is selected for option "
108      "\"mu_strategy\".)");
109  }
110
111  SmartPtr<IpoptAlgorithm>
112  AlgorithmBuilder::BuildBasicAlgorithm(const Journalist& jnlst,
113                                        const OptionsList& options,
114                                        const std::string& prefix)
115  {
116    DBG_START_FUN("AlgorithmBuilder::BuildBasicAlgorithm",
117                  dbg_verbosity);
118    // Create the convergence check
119    SmartPtr<ConvergenceCheck> convCheck =
120      new OptimalityErrorConvergenceCheck();
121
122    // Create the solvers that will be used by the main algorithm
123    SmartPtr<TSymScalingMethod> ScalingMethod;
124    std::string linear_system_scaling;
125    options.GetStringValue("linear_system_scaling",
126                           linear_system_scaling, prefix);
127    if (linear_system_scaling=="mc19") {
128#ifdef HAVE_MC19
129      ScalingMethod = new Mc19TSymScalingMethod();
130#else
131
132      THROW_EXCEPTION(OPTION_INVALID,
133                      "Selected linear system scaling method MC19 not available.");
134#endif
135
136    }
137
138    SmartPtr<SparseSymLinearSolverInterface> SolverInterface;
139    std::string linear_solver;
140    options.GetStringValue("linear_solver", linear_solver, prefix);
141    if (linear_solver=="ma27") {
142#ifdef HAVE_MA27
143      SolverInterface = new Ma27TSolverInterface();
144#else
145
146      THROW_EXCEPTION(OPTION_INVALID,
147                      "Selected linear solver MA27 not available.");
148#endif
149
150    }
151    else if (linear_solver=="pardiso") {
152#ifdef HAVE_PARDISO
153      SolverInterface = new PardisoSolverInterface();
154#else
155
156      THROW_EXCEPTION(OPTION_INVALID,
157                      "Selected linear solver Pardiso not available.");
158#endif
159
160    }
161    else if (linear_solver=="taucs") {
162#ifdef HAVE_TAUCS
163      SolverInterface = new TAUCSSolverInterface();
164#else
165
166      THROW_EXCEPTION(OPTION_INVALID,
167                      "Selected linear solver TAUCS not available.");
168#endif
169
170    }
171
172    SmartPtr<SymLinearSolver> ScaledSolver =
173      new TSymLinearSolver(SolverInterface, ScalingMethod);
174
175    SmartPtr<AugSystemSolver> AugSolver =
176      //        = new AugTSystemSolver(*Ma27Solver);
177      new StdAugSystemSolver(*ScaledSolver);
178    SmartPtr<PDPerturbationHandler> pertHandler =
179      new PDPerturbationHandler();
180    SmartPtr<PDSystemSolver> PDSolver =
181      new PDFullSpaceSolver(*AugSolver, *pertHandler);
182
183    // Create the object for initializing the iterates Initialization
184    // object.  We include both the warm start and the defaut
185    // initializer, so that the warm start options can be activated
186    // without having to rebuild the algorithm
187    SmartPtr<EqMultiplierCalculator> EqMultCalculator =
188      new LeastSquareMultipliers(*AugSolver);
189    SmartPtr<IterateInitializer> WarmStartInitializer =
190      new WarmStartIterateInitializer();
191    SmartPtr<IterateInitializer> IterInitializer =
192      new DefaultIterateInitializer(EqMultCalculator, WarmStartInitializer);
193
194    // Solver for the restoration phase
195    SmartPtr<AugSystemSolver> resto_AugSolver =
196      new AugRestoSystemSolver(*AugSolver);
197    SmartPtr<PDPerturbationHandler> resto_pertHandler =
198      new PDPerturbationHandler();
199    SmartPtr<PDSystemSolver> resto_PDSolver =
200      new PDFullSpaceSolver(*resto_AugSolver, *resto_pertHandler);
201
202    // Convergence check in the restoration phase
203    SmartPtr<RestoFilterConvergenceCheck> resto_convCheck =
204      new RestoFilterConvergenceCheck();
205
206    // Line search method for the restoration phase
207    SmartPtr<RestoRestorationPhase> resto_resto =
208      new RestoRestorationPhase();
209    SmartPtr<FilterLineSearch> resto_LineSearch =
210      new FilterLineSearch(GetRawPtr(resto_resto), GetRawPtr(resto_PDSolver),
211                           GetRawPtr(resto_convCheck));
212
213    // Create the mu update that will be used by the restoration phase
214    // algorithm
215    SmartPtr<MuUpdate> resto_MuUpdate;
216    std::string resto_smuupdate;
217    options.GetStringValue("mu_strategy", resto_smuupdate, "resto."+prefix);
218
219    std::string resto_smuoracle;
220    std::string resto_sfixmuoracle;
221    if (resto_smuupdate=="adaptive" ) {
222      options.GetStringValue("mu_oracle", resto_smuoracle, "resto."+prefix);
223      options.GetStringValue("fixed_mu_oracle", resto_sfixmuoracle, "resto."+prefix);
224    }
225
226    if (resto_smuupdate=="monotone" ) {
227      resto_MuUpdate = new MonotoneMuUpdate(GetRawPtr(resto_LineSearch));
228    }
229    else if (resto_smuupdate=="adaptive") {
230      SmartPtr<MuOracle> resto_MuOracle;
231      if (resto_smuoracle=="loqo") {
232        resto_MuOracle = new LoqoMuOracle();
233      }
234      else if (resto_smuoracle=="probing") {
235        resto_MuOracle = new ProbingMuOracle(resto_PDSolver);
236      }
237      else if (resto_smuoracle=="quality_function") {
238        resto_MuOracle = new QualityFunctionMuOracle(resto_PDSolver);
239      }
240      SmartPtr<MuOracle> resto_FixMuOracle;
241      if (resto_sfixmuoracle=="loqo") {
242        resto_FixMuOracle = new LoqoMuOracle();
243      }
244      else if (resto_sfixmuoracle=="probing") {
245        resto_FixMuOracle = new ProbingMuOracle(resto_PDSolver);
246      }
247      else if (resto_sfixmuoracle=="quality_function") {
248        resto_FixMuOracle = new QualityFunctionMuOracle(resto_PDSolver);
249      }
250      else {
251        resto_FixMuOracle = NULL;
252      }
253      resto_MuUpdate =
254        new AdaptiveMuUpdate(GetRawPtr(resto_LineSearch),
255                             resto_MuOracle, resto_FixMuOracle);
256    }
257
258    // Initialization of the iterates for the restoration phase
259    SmartPtr<EqMultiplierCalculator> resto_EqMultCalculator =
260      new LeastSquareMultipliers(*resto_AugSolver);
261    SmartPtr<IterateInitializer> resto_IterInitializer =
262      new RestoIterateInitializer(resto_EqMultCalculator);
263
264    // Create the object for the iteration output during restoration
265    SmartPtr<OrigIterationOutput> resto_OrigIterOutput = NULL;
266    //   new OrigIterationOutput();
267    SmartPtr<IterationOutput> resto_IterOutput =
268      new RestoIterationOutput(resto_OrigIterOutput);
269
270    // Put together the overall restoration phase IP algorithm
271    SmartPtr<IpoptAlgorithm> resto_alg =
272      new IpoptAlgorithm(resto_PDSolver,
273                         GetRawPtr(resto_LineSearch),
274                         GetRawPtr(resto_MuUpdate),
275                         GetRawPtr(resto_convCheck),
276                         resto_IterInitializer,
277                         resto_IterOutput);
278
279    // Set the restoration phase
280    SmartPtr<RestorationPhase> resto_phase =
281      new MinC_1NrmRestorationPhase(*resto_alg, EqMultCalculator);
282
283    // Create the line search to be used by the main algorithm
284    SmartPtr<FilterLineSearch> lineSearch =
285      new FilterLineSearch(GetRawPtr(resto_phase), GetRawPtr(PDSolver),
286                           convCheck);
287
288    // The following cross reference is not good: We have to store a
289    // pointer to the lineSearch object in resto_convCheck as a
290    // non-SmartPtr to make sure that things are properly deleted when
291    // the IpoptAlgorithm return by the Builder is destructed.
292    resto_convCheck->SetOrigFilterLineSearch(*lineSearch);
293
294    // Create the mu update that will be used by the main algorithm
295    SmartPtr<MuUpdate> MuUpdate;
296    std::string smuupdate;
297    options.GetStringValue("mu_strategy", smuupdate, prefix);
298    std::string smuoracle;
299    std::string sfixmuoracle;
300    if (smuupdate=="adaptive" ) {
301      options.GetStringValue("mu_oracle", smuoracle, prefix);
302      options.GetStringValue("fixed_mu_oracle", sfixmuoracle, prefix);
303    }
304
305    if (smuupdate=="monotone" ) {
306      MuUpdate = new MonotoneMuUpdate(GetRawPtr(lineSearch));
307    }
308    else if (smuupdate=="adaptive") {
309      SmartPtr<MuOracle> muOracle;
310      if (smuoracle=="loqo") {
311        muOracle = new LoqoMuOracle();
312      }
313      else if (smuoracle=="probing") {
314        muOracle = new ProbingMuOracle(PDSolver);
315      }
316      else if (smuoracle=="quality_function") {
317        muOracle = new QualityFunctionMuOracle(PDSolver);
318      }
319      SmartPtr<MuOracle> FixMuOracle;
320      if (sfixmuoracle=="loqo") {
321        FixMuOracle = new LoqoMuOracle();
322      }
323      else if (sfixmuoracle=="probing") {
324        FixMuOracle = new ProbingMuOracle(PDSolver);
325      }
326      else if (sfixmuoracle=="quality_function") {
327        FixMuOracle = new QualityFunctionMuOracle(PDSolver);
328      }
329      else {
330        FixMuOracle = NULL;
331      }
332      MuUpdate = new AdaptiveMuUpdate(GetRawPtr(lineSearch),
333                                      muOracle, FixMuOracle);
334    }
335
336    // Create the object for the iteration output
337    SmartPtr<IterationOutput> IterOutput =
338      new OrigIterationOutput();
339
340    // Create the main algorithm
341    SmartPtr<IpoptAlgorithm> alg =
342      new IpoptAlgorithm(PDSolver,
343                         GetRawPtr(lineSearch), MuUpdate,
344                         convCheck, IterInitializer, IterOutput);
345
346    return alg;
347  }
348
349} // namespace
Note: See TracBrowser for help on using the repository browser.