source: trunk/Bonmin/src/IpoptInterface/IpoptWarmStart.cpp @ 1

Last change on this file since 1 was 1, checked in by andreasw, 13 years ago

imported initial code

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 4.0 KB
Line 
1// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// Pierre Bonami, Carnegie Mellon University,
7// Andreas Waechter, International Business Machines Corporation
8//
9// Date : 02/15/2006
10
11
12#include "IpoptWarmStart.hpp"
13#include "CoinHelperFunctions.hpp"
14
15
16
17#include "IpoptInterface.hpp"
18#include "IpoptInteriorWarmStarter.hpp"
19
20
21/// Default constructor
22IpoptWarmStart::IpoptWarmStart
23(bool empty, int numvars, int numcont):
24    CoinWarmStartBasis(),
25    values_(),
26    tempValues_(NULL),
27    warm_starter_(NULL),
28    empty_(empty)
29{
30  setSize(numvars,numcont);
31}
32/// Usefull constructor
33IpoptWarmStart::IpoptWarmStart(const IpoptInterface &ipopt,
34    SmartPtr<IpoptInteriorWarmStarter> warm_starter):
35    values_(),
36    tempValues_(NULL),
37    warm_starter_(warm_starter),
38    empty_(false)
39{
40
41  int numcols = ipopt.getNumCols();
42  int numrows = ipopt.getNumRows();
43  setSize(numcols,numrows);
44  values_.reserve(numcols+numrows);
45  // For now, we keep all this in here, but we probably want to remove
46  // it when we are happy with the new warmstarter (AW)
47  double epsilon = 1e-05;//ipopt.getPushFact();
48  const double * primals = ipopt.problem()->x_sol();
49  const double * duals = ipopt.problem()->duals_sol();
50  const double * colLo = ipopt.getColLower();
51  const double * colUp = ipopt.getColUpper();
52  for(int i = 0 ; i < numcols ; i++) {
53    if(primals[i] - colLo[i] < epsilon) {
54      setStructStatus(i, atLowerBound);
55      if(fabs(duals[i + numrows]) > epsilon) {
56        values_.insert(i + numcols + numrows ,duals[i + numrows]);
57      }
58
59//       assert(duals[i +numrows + numcols] <= 100 * epsilon
60//           ||
61//           colUp[i] - colLo[i] <= epsilon
62//             ||
63//           colUp[i] - colLo[i] > 1e50);
64
65    }
66    else if( colUp[i] - primals[i] < epsilon) {
67      setStructStatus(i, atUpperBound);
68      if(fabs(duals[i + numrows + numcols]) > epsilon) {
69        values_.insert(i + 2 * numcols + numrows ,duals[i + numrows + numcols]);
70      }
71//       assert(duals[i + numrows] <= epsilon
72//           ||
73//           colUp[i] - colLo[i] <= epsilon
74//           ||
75//           colUp[i] - colLo[i] > 1e100);
76    }
77    else {
78      setStructStatus(i, basic);
79//       assert((duals[i + numrows] <= epsilon && duals[i+ numrows +numcols] <= epsilon)
80//           ||
81//           colUp[i] - colLo[i] <= epsilon
82//           ||
83//           colUp[i] - colLo[i] > 1e100);
84
85      values_.insert(i , primals[i]);
86    }
87  }
88
89  // int i2 = 2*numcols;
90  for(int i = 0 ; i < numrows ; i++) {
91    if(fabs(duals[i])> epsilon) {
92      values_.insert(i + numcols,duals[i]);
93      setArtifStatus(i, basic);
94    }
95    else {
96      setArtifStatus(i, atLowerBound);
97    }
98
99  }
100  values_.sortIncrIndex();
101}
102
103/// Copy constructor
104IpoptWarmStart::IpoptWarmStart( const IpoptWarmStart &other, bool ownValues):
105    CoinWarmStartBasis(other),
106    values_(other.values_),
107    tempValues_(other.tempValues_),
108    warm_starter_(NULL),//(other.warm_starter_),
109    empty_(other.empty_)
110{
111  //  if(ownValues_ && other.values_ != NULL)
112}
113
114
115CoinWarmStartDiff*
116IpoptWarmStart::generateDiff(const CoinWarmStart *const oldCWS) const
117{
118  CoinWarmStartDiff * diff = CoinWarmStartBasis::generateDiff(oldCWS);
119  CoinWarmStartBasisDiff * basisDiff =
120    dynamic_cast<CoinWarmStartBasisDiff *>(diff);
121
122
123  CoinWarmStartDiff* retval =
124    new IpoptWarmStartDiff(basisDiff, values_, NULL);//warm_starter_);
125  delete diff;
126  return retval;
127}
128
129
130void
131IpoptWarmStart::applyDiff (const CoinWarmStartDiff *const cwsdDiff)
132{
133  CoinWarmStartBasis::applyDiff(cwsdDiff);
134  IpoptWarmStartDiff const * const ipoptDiff =
135    dynamic_cast<IpoptWarmStartDiff const * const > (cwsdDiff);
136
137  tempValues_ = ipoptDiff->diffValues_;
138  //  ownValues_ = 0;
139  warm_starter_ = ipoptDiff->warm_starter();
140}
141
142IpoptWarmStart::~IpoptWarmStart()
143{}
144
145void
146IpoptWarmStart::flushPoint()
147{
148  if(values_.getNumElements() > 0)
149    values_.clear();
150}
151void
152
153IpoptWarmStartDiff::flushPoint()
154{
155  if(diffValues_) {
156    delete diffValues_;
157    diffValues_ = NULL;
158  }
159}
Note: See TracBrowser for help on using the repository browser.