File: RegisteredTNLP.hpp

package info (click to toggle)
coinor-ipopt 3.14.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,796 kB
  • sloc: cpp: 97,169; sh: 4,802; ansic: 2,537; java: 1,289; makefile: 821; fortran: 224; xml: 210
file content (99 lines) | stat: -rw-r--r-- 2,521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2005, 2006 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors:  Andreas Waechter            IBM    2005-10-20

#ifndef __REGISTEREDTNLPS_HPP__
#define __REGISTEREDTNLPS_HPP__

#include "IpTNLP.hpp"
#include <map>

using namespace Ipopt;

class RegisteredTNLP: public TNLP
{
public:
   RegisteredTNLP()
      : interrupted_(false)
   { }

   /** Initialize internal parameters.
    *
    *  @return false, if N has an invalid value
    */
   virtual bool InitializeProblem(
      Index N  /**< determines problems size */
   ) = 0;

   bool intermediate_callback(
      AlgorithmMode              /*mode*/,
      Index                      /*iter*/,
      Number                     /*obj_value*/,
      Number                     /*inf_pr*/,
      Number                     /*inf_du*/,
      Number                     /*mu*/,
      Number                     /*d_norm*/,
      Number                     /*regularization_size*/,
      Number                     /*alpha_du*/,
      Number                     /*alpha_pr*/,
      Index                      /*ls_trials*/,
      const IpoptData*           /*ip_data*/,
      IpoptCalculatedQuantities* /*ip_cq*/
   )
   {
      /* returning false makes Ipopt stop */
      return !interrupted_;
   }

   bool interrupted_;
};

class RegisteredTNLPs
{
public:
   RegisteredTNLPs(
      const SmartPtr<RegisteredTNLP>& tnlp,
      const std::string&              name
   )
   {
      RegisterTNLP(tnlp, name);
   }

   virtual ~RegisteredTNLPs()
   { }

   static SmartPtr<RegisteredTNLP> GetTNLP(
      const std::string& name
   );

   static void PrintRegisteredProblems();

private:
   void RegisterTNLP(
      const SmartPtr<RegisteredTNLP>& tnlp,
      const std::string&              name
   );

   SmartPtr<RegisteredTNLP> tnlp_;
};

#define REGISTER_TNLP(class_constructor, name) \
class RegisteredTNLP_Setup_ ## name : public RegisteredTNLPs \
{ \
public: \
  RegisteredTNLP_Setup_ ## name() \
    : \
    RegisteredTNLPs(new class_constructor, #name) \
  { } \
  RegisteredTNLP_Setup_ ## name* KeepCompilerFromRemovingThis(); \
}; \
 \
RegisteredTNLP_Setup_ ## name RegisteredTNLP_Setup_ ## name ## instance_; \
RegisteredTNLP_Setup_ ## name* \
RegisteredTNLP_Setup_ ## name::KeepCompilerFromRemovingThis() \
{ return &RegisteredTNLP_Setup_ ## name ## instance_; }

//static RegisteredTNLP_Setup_ ## name RegisteredTNLP_Setup_ ## name ## instance
#endif