00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "BonTMINLP.hpp"
00011 #include "IpBlas.hpp"
00012 #include "BonTypes.hpp"
00013
00014 namespace Bonmin{
00015
00017 TMINLP::SosInfo::SosInfo():
00018 num(0),
00019 types(NULL),
00020 priorities(NULL),
00021 numNz(0),
00022 starts(NULL),
00023 indices(NULL),
00024 weights(NULL)
00025 {}
00026
00028 TMINLP::SosInfo::SosInfo(const SosInfo & source):
00029 num(source.num),
00030 types(NULL),
00031 priorities(NULL),
00032 numNz(source.numNz),
00033 starts(NULL),
00034 indices(NULL),
00035 weights(NULL)
00036 {
00037
00038 if(num > 0) {
00039 assert(source.types!=NULL);
00040 assert(source.priorities!=NULL);
00041 assert(source.starts!=NULL);
00042 assert(source.indices!=NULL);
00043 assert(source.weights!=NULL);
00044 types = new char[num];
00045 priorities = new int[num];
00046 starts = new int[num + 1];
00047 indices = new int[numNz];
00048 weights = new double[numNz];
00049 for(int i = 0 ; i < num ; i++) {
00050 source.types[i] = types[i];
00051 source.priorities[i] = priorities[i];
00052 source.starts[i] = starts[i];
00053 }
00054 for(int i = 0 ; i < numNz ; i++) {
00055 source.indices[i] = indices[i];
00056 source.weights[i] = weights[i];
00057 }
00058 }
00059 else {
00060 assert(source.types==NULL);
00061 assert(source.priorities==NULL);
00062 assert(source.starts==NULL);
00063 assert(source.indices==NULL);
00064 assert(source.weights==NULL);
00065 }
00066
00067 }
00068
00069
00071 void
00072 TMINLP::SosInfo::gutsOfDestructor()
00073 {
00074 num = 0;
00075 numNz = 0;
00076 if(types) delete [] types;
00077 types = NULL;
00078 if(starts) delete [] starts;
00079 starts = NULL;
00080 if(indices) delete [] indices;
00081 indices = NULL;
00082 if(priorities) delete [] priorities;
00083 priorities = NULL;
00084 if(weights) delete [] weights;
00085 weights = NULL;
00086 }
00087
00088
00089 void TMINLP::PerturbInfo::SetPerturbationArray(Index numvars, const double* perturb_radius) {
00090 delete [] perturb_radius_;
00091 if (perturb_radius) {
00092 perturb_radius_ = new double[numvars];
00093 for(int i=0; i<numvars; i++) {
00094 perturb_radius_[i] = perturb_radius[i];
00095 }
00096 }
00097 }
00098
00099 TMINLP::TMINLP()
00100 {}
00101
00102 TMINLP::TMINLP(const TMINLP & source)
00103 {
00104 }
00105
00107 TMINLP::~TMINLP()
00108 {
00109 }
00110
00112 bool
00113 TMINLP::hasGeneralInteger(){
00114 int n, m, nnz_j, nnz_h;
00115 Ipopt::TNLP::IndexStyleEnum dummy;
00116 get_nlp_info(n, m, nnz_j, nnz_h, dummy);
00117 vector<double> x_lb(n);
00118 vector<double> x_ub(n);
00119 vector<double> g_lb(m);
00120 vector<double> g_ub(m);
00121 vector<VariableType> v_t(n);
00122 get_variables_types(n, v_t());
00123 get_bounds_info(n, x_lb(), x_ub(), m, g_lb(), g_ub());
00124 for(int i = 0 ; i < n ; i++){
00125 if(v_t[i] == INTEGER &&
00126 (x_lb[i] < - 0.99 || x_lb[i] > 0.99 ||
00127 x_ub[i] <0.01 || x_ub[i] > 1.99) ){
00128 return true;
00129 }
00130 }
00131 return false;
00132 }
00133
00134 }