| 1 |
// (C) Copyright International Business Machines (IBM) 2005, 2007 |
| 2 |
// All Rights Reserved. |
| 3 |
// This code is published under the Eclipse Public License. |
| 4 |
// |
| 5 |
// Authors : |
| 6 |
// Pierre Bonami, IBM |
| 7 |
// |
| 8 |
// Date : 26/09/2006 |
| 9 |
|
| 10 |
#include "BonTMINLP.hpp" |
| 11 |
#include "IpBlas.hpp" |
| 12 |
#include "BonTypes.hpp" |
| 13 |
|
| 14 |
namespace Bonmin{ |
| 15 |
|
| 16 |
/** default constructor for Sos constraints */ |
| 17 |
TMINLP::SosInfo::SosInfo(): |
| 18 |
num(0), |
| 19 |
types(NULL), |
| 20 |
priorities(NULL), |
| 21 |
numNz(0), |
| 22 |
starts(NULL), |
| 23 |
indices(NULL), |
| 24 |
weights(NULL) |
| 25 |
{} |
| 26 |
|
| 27 |
/** Copy constructor.*/ |
| 28 |
TMINLP::SosInfo::SosInfo(const SosInfo & source): |
| 29 |
num(source.num), |
| 30 |
types(NULL), |
| 31 |
priorities(NULL), |
| 32 |
numNz(source.numNz), |
| 33 |
starts(NULL), |
| 34 |
indices(NULL), |
| 35 |
weights(NULL) |
| 36 |
{ |
| 37 |
|
| 38 |
if(num > 0) { |
| 39 |
assert(source.types!=NULL); |
| 40 |
assert(source.priorities!=NULL); |
| 41 |
assert(source.starts!=NULL); |
| 42 |
assert(source.indices!=NULL); |
| 43 |
assert(source.weights!=NULL); |
| 44 |
types = new char[num]; |
| 45 |
priorities = new int[num]; |
| 46 |
starts = new int[num + 1]; |
| 47 |
indices = new int[numNz]; |
| 48 |
weights = new double[numNz]; |
| 49 |
for(int i = 0 ; i < num ; i++) { |
| 50 |
source.types[i] = types[i]; |
| 51 |
source.priorities[i] = priorities[i]; |
| 52 |
source.starts[i] = starts[i]; |
| 53 |
} |
| 54 |
for(int i = 0 ; i < numNz ; i++) { |
| 55 |
source.indices[i] = indices[i]; |
| 56 |
source.weights[i] = weights[i]; |
| 57 |
} |
| 58 |
} |
| 59 |
else { |
| 60 |
assert(source.types==NULL); |
| 61 |
assert(source.priorities==NULL); |
| 62 |
assert(source.starts==NULL); |
| 63 |
assert(source.indices==NULL); |
| 64 |
assert(source.weights==NULL); |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
/** Reset information */ |
| 71 |
void |
| 72 |
TMINLP::SosInfo::gutsOfDestructor() |
| 73 |
{ |
| 74 |
num = 0; |
| 75 |
numNz = 0; |
| 76 |
if(types) delete [] types; |
| 77 |
types = NULL; |
| 78 |
if(starts) delete [] starts; |
| 79 |
starts = NULL; |
| 80 |
if(indices) delete [] indices; |
| 81 |
indices = NULL; |
| 82 |
if(priorities) delete [] priorities; |
| 83 |
priorities = NULL; |
| 84 |
if(weights) delete [] weights; |
| 85 |
weights = NULL; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
void TMINLP::PerturbInfo::SetPerturbationArray(Ipopt::Index numvars, const double* perturb_radius) { |
| 90 |
delete [] perturb_radius_; |
| 91 |
if (perturb_radius) { |
| 92 |
perturb_radius_ = new double[numvars]; |
| 93 |
for(int i=0; i<numvars; i++) { |
| 94 |
perturb_radius_[i] = perturb_radius[i]; |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
TMINLP::TMINLP() |
| 100 |
{} |
| 101 |
|
| 102 |
TMINLP::TMINLP(const TMINLP & source) |
| 103 |
{ |
| 104 |
} |
| 105 |
|
| 106 |
/** Default destructor */ |
| 107 |
TMINLP::~TMINLP() |
| 108 |
{ |
| 109 |
} |
| 110 |
|
| 111 |
/** Say if has general integer variables.*/ |
| 112 |
bool |
| 113 |
TMINLP::hasGeneralInteger(){ |
| 114 |
int n, m, nnz_j, nnz_h; |
| 115 |
Ipopt::TNLP::IndexStyleEnum dummy; |
| 116 |
get_nlp_info(n, m, nnz_j, nnz_h, dummy); |
| 117 |
vector<double> x_lb(n); |
| 118 |
vector<double> x_ub(n); |
| 119 |
vector<double> g_lb(m); |
| 120 |
vector<double> g_ub(m); |
| 121 |
vector<VariableType> v_t(n); |
| 122 |
get_variables_types(n, v_t()); |
| 123 |
get_bounds_info(n, x_lb(), x_ub(), m, g_lb(), g_ub()); |
| 124 |
for(int i = 0 ; i < n ; i++){ |
| 125 |
if(v_t[i] == INTEGER && |
| 126 |
(x_lb[i] < - 0.99 || x_lb[i] > 0.99 || |
| 127 |
x_ub[i] <0.01 || x_ub[i] > 1.99) ){ |
| 128 |
return true; |
| 129 |
} |
| 130 |
} |
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 134 |
} |