source: branches/devel/Bonmin/src/Interfaces/Ipopt/BonIpoptWarmStart.cpp @ 104

Last change on this file since 104 was 86, checked in by pbonami, 13 years ago

New directory layout regroup interfercaces in same subdirectory

  • 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 "BonIpoptWarmStart.hpp"
13#include "CoinHelperFunctions.hpp"
14
15
16
17#include "BonTMINLP2TNLP.hpp"
18#include "BonIpoptInteriorWarmStarter.hpp"
19
20
21namespace Bonmin {
22/// Default constructor
23IpoptWarmStart::IpoptWarmStart
24(bool empty, int numvars, int numcont):
25    CoinWarmStartBasis(),
26    values_(),
27    tempValues_(NULL),
28    warm_starter_(NULL),
29    empty_(empty)
30{
31  setSize(numvars,numcont);
32}
33/// Usefull constructor
34IpoptWarmStart::IpoptWarmStart(const Ipopt::SmartPtr<TMINLP2TNLP> tnlp,
35    SmartPtr<IpoptInteriorWarmStarter> warm_starter):
36    values_(),
37    tempValues_(NULL),
38    warm_starter_(warm_starter),
39    empty_(false)
40{
41
42  int numcols = tnlp->num_variables();
43  int numrows = tnlp->num_constraints();
44  setSize(numcols,numrows);
45  values_.reserve(numcols+numrows);
46  // For now, we keep all this in here, but we probably want to remove
47  // it when we are happy with the new warmstarter (AW)
48  double epsilon = 1e-05;//ipopt.getPushFact();
49  const double * primals = tnlp->x_sol();
50  const double * duals = tnlp->duals_sol();
51  const double * colLo = tnlp->x_l();
52  const double * colUp = tnlp->x_u();
53  for(int i = 0 ; i < numcols ; i++) {
54    if(primals[i] - colLo[i] < epsilon) {
55      setStructStatus(i, atLowerBound);
56      if(fabs(duals[i + numrows]) > epsilon) {
57        values_.insert(i + numcols + numrows ,duals[i + numrows]);
58      }
59
60//       assert(duals[i +numrows + numcols] <= 100 * epsilon
61//           ||
62//           colUp[i] - colLo[i] <= epsilon
63//             ||
64//           colUp[i] - colLo[i] > 1e50);
65
66    }
67    else if( colUp[i] - primals[i] < epsilon) {
68      setStructStatus(i, atUpperBound);
69      if(fabs(duals[i + numrows + numcols]) > epsilon) {
70        values_.insert(i + 2 * numcols + numrows ,duals[i + numrows + numcols]);
71      }
72//       assert(duals[i + numrows] <= epsilon
73//           ||
74//           colUp[i] - colLo[i] <= epsilon
75//           ||
76//           colUp[i] - colLo[i] > 1e100);
77    }
78    else {
79      setStructStatus(i, basic);
80//       assert((duals[i + numrows] <= epsilon && duals[i+ numrows +numcols] <= epsilon)
81//           ||
82//           colUp[i] - colLo[i] <= epsilon
83//           ||
84//           colUp[i] - colLo[i] > 1e100);
85
86      values_.insert(i , primals[i]);
87    }
88  }
89
90  // int i2 = 2*numcols;
91  for(int i = 0 ; i < numrows ; i++) {
92    if(fabs(duals[i])> epsilon) {
93      values_.insert(i + numcols,duals[i]);
94      setArtifStatus(i, basic);
95    }
96    else {
97      setArtifStatus(i, atLowerBound);
98    }
99
100  }
101  values_.sortIncrIndex();
102}
103
104/// Copy constructor
105IpoptWarmStart::IpoptWarmStart( const IpoptWarmStart &other, bool ownValues):
106    CoinWarmStartBasis(other),
107    values_(other.values_),
108    tempValues_(other.tempValues_),
109    warm_starter_(NULL),//(other.warm_starter_),
110    empty_(other.empty_)
111{
112  //  if(ownValues_ && other.values_ != NULL)
113}
114
115
116CoinWarmStartDiff*
117IpoptWarmStart::generateDiff(const CoinWarmStart *const oldCWS) const
118{
119  CoinWarmStartDiff * diff = CoinWarmStartBasis::generateDiff(oldCWS);
120  CoinWarmStartBasisDiff * basisDiff =
121    dynamic_cast<CoinWarmStartBasisDiff *>(diff);
122
123
124  CoinWarmStartDiff* retval =
125    new IpoptWarmStartDiff(basisDiff, values_, NULL);//warm_starter_);
126  delete diff;
127  return retval;
128}
129
130
131void
132IpoptWarmStart::applyDiff (const CoinWarmStartDiff *const cwsdDiff)
133{
134  CoinWarmStartBasis::applyDiff(cwsdDiff);
135  IpoptWarmStartDiff const * const ipoptDiff =
136    dynamic_cast<IpoptWarmStartDiff const * const > (cwsdDiff);
137
138  tempValues_ = ipoptDiff->diffValues_;
139  //  ownValues_ = 0;
140  warm_starter_ = ipoptDiff->warm_starter();
141}
142
143IpoptWarmStart::~IpoptWarmStart()
144{}
145
146void
147IpoptWarmStart::flushPoint()
148{
149  if(values_.getNumElements() > 0)
150    values_.clear();
151}
152void
153
154IpoptWarmStartDiff::flushPoint()
155{
156  if(diffValues_) {
157    delete diffValues_;
158    diffValues_ = NULL;
159  }
160}
161}
Note: See TracBrowser for help on using the repository browser.