summaryrefslogtreecommitdiff
path: root/thirdparty/linux/include/coin/BonIpoptWarmStart.hpp
blob: fffc3e3a68713c8cb72e9249c8bdb96978110c5c (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// (C) Copyright International Business Machines Corporation, Carnegie Mellon University 2006
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors :
// Pierre Bonami, Carnegie Mellon University,
// Andreas Waechter, International Business Machines Corporation
//
// Date : 02/15/2006


#ifndef IpoptWarmStart_HPP
#define IpoptWarmStart_HPP
#include "CoinWarmStartBasis.hpp"
#include "CoinWarmStartPrimalDual.hpp"
#include "BonIpoptInteriorWarmStarter.hpp"


namespace Bonmin
{
  class TMINLP2TNLP;

  /** \brief Class for storing warm start informations for Ipopt.<br>
   * This class inherits from CoinWarmStartPrimalDual, because that's what
   * this warmstart really is. <br>
   * For practical reason (integration in Cbc) this class also inherits from
   * CoinWarmStartBasis. <br>
   * This class stores a starting point (primal and dual values) for Ipopt.
   * <br>
   * <p>
   * The primal part of the base class contains the value of each primal
   * variable.
   * <p>
   * The dual part of the base class consists of three sections (the number of
   * values is 2*numcols+numrows):
     <UL>
     <li> First, values for dual variables associated with the lower bound
          constraints on structurals, i.e., primal variables (constraints
	  \f$ l \leq x \f$); 
     <li> Then values for dual variables associated with upper bound
           constraints on structurals (constraints \f$ x \leq u\f$).
     <li> the values for dual variables associated with regular constraints
          (constraints \f$ g(x) \leq 0 \f$) 
     </UL>
   */
  class IpoptWarmStart :
    public virtual CoinWarmStartPrimalDual, public virtual CoinWarmStartBasis
  {
  public:

    /// Default constructor
    IpoptWarmStart(bool empty = 1, int numvars = 0, int numcont = 0);
    /// Usefull constructor, stores the current optimum of ipopt
    IpoptWarmStart(const Ipopt::SmartPtr<TMINLP2TNLP> tnlp,
        Ipopt::SmartPtr<IpoptInteriorWarmStarter> warm_starter);
    /// Another usefull constructor, stores the passed point
    IpoptWarmStart(int primal_size, int dual_size,
                   const double * primal, const double * dual);
    /// Copy constructor
    IpoptWarmStart( const IpoptWarmStart &other, bool ownValues = 1);
    /// A constructor from a CoinWarmStartPrimalDual
    IpoptWarmStart(const CoinWarmStartPrimalDual& pdws);
    /// Abstract destructor
    virtual ~IpoptWarmStart();

    /// `Virtual constructor'
    virtual CoinWarmStart *clone() const
    {
      return new IpoptWarmStart(*this,1);
    }

    /** Generate the "differences" between two IpoptWarmStart.*/
    virtual CoinWarmStartDiff*
    generateDiff(const CoinWarmStart *const oldCWS) const;
    /** \brief Apply 'differences' to an Ipopt warm start.
     * What this actually does is get a copy to the vector of values stored
     in IpoptWarmStartDiff.*/
    virtual void
    applyDiff (const CoinWarmStartDiff *const cwsdDiff);

    /** Accessor to warm start information obecjt */
    Ipopt::SmartPtr<IpoptInteriorWarmStarter> warm_starter() const
    {
      return warm_starter_;
    }

    /// flush the starting point
    void flushPoint();

    ///Is this an empty warm start?
    bool empty() const
    {
      return empty_;
    }
  private:
    /** warm start information object */
    mutable Ipopt::SmartPtr<IpoptInteriorWarmStarter> warm_starter_;
    ///Say if warm start is empty
    bool empty_;
  };

  //###########################################################################

  /** \brief Diff class for IpoptWarmStart.
   * Actually get the differences from CoinWarmStartBasis and stores the
   whole vector of values.
   \todo Find a way to free unused values.
  */
  class IpoptWarmStartDiff : public CoinWarmStartPrimalDualDiff
  {
  public:
    friend class IpoptWarmStart;
    /** Useful constructor; takes over the data in \c diff */
    IpoptWarmStartDiff(CoinWarmStartPrimalDualDiff * diff,
		       Ipopt::SmartPtr<IpoptInteriorWarmStarter> warm_starter):
      CoinWarmStartPrimalDualDiff(),
      warm_starter_(NULL)//(warm_starter)
    {
      CoinWarmStartPrimalDualDiff::swap(*diff);
    }
    /** Copy constructor. */
    IpoptWarmStartDiff(const IpoptWarmStartDiff &other):
        CoinWarmStartPrimalDualDiff(other),
        warm_starter_(NULL /*other.warm_starter_*/) {}

    /// Abstract destructor
    virtual ~IpoptWarmStartDiff() {}

    /// `Virtual constructor'
    virtual CoinWarmStartDiff *clone() const
    {
      return new IpoptWarmStartDiff(*this);
    }

    /** Accessor to warm start information obecjt */
    Ipopt::SmartPtr<IpoptInteriorWarmStarter> warm_starter() const
    {
      return warm_starter_;
    }
    void flushPoint();
  private:

    /** warm start information object */
    Ipopt::SmartPtr<IpoptInteriorWarmStarter> warm_starter_;
  };

}
#endif