00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOXFIND_H
00009 #define BOXFIND_H
00010
00011 #include "standard.h"
00012 #include "param.h"
00013 #include "problem.h"
00014 #include "opt.h"
00015 #include "relax.h"
00016 #include "graph.h"
00017
00032 class BoundsFinder {
00033 private:
00036 Pointer<Param> param;
00037
00040 int method;
00041
00051 double compute_bound(MinlpProblem& conv_prob, int& ret, int index, int block, bool low);
00052
00053 public:
00054 bool low, up, known;
00055
00059 BoundsFinder(Pointer<Param> param_=NULL);
00060
00067 pair<int,int> compute_bounds(MinlpProblem& prob, vector<bool>& discr);
00068
00076 pair<int,int> compute_bounds_guess(MinlpProblem& prob);
00077
00093 pair<int,int> compute_bounds_expensive(MinlpProblem& conv_prob, dvector& lower, dvector& upper, vector<bool>& discr);
00094
00103 pair<int,int> compute_bounds_expensive2(MinlpProblem& conv_prob, dvector& lower, dvector& upper, vector<bool>& discr);
00104
00109 void compute_linbounds(MinlpProblem& prob);
00110 };
00111
00114 class DualBounds {
00115 private:
00116 Pointer<Param> param;
00117
00118 Pointer<MinlpProblem> S, C, R;
00119 vector<Pointer<MinlpProblem> > lag_prob;
00120
00124 vector<list<int> > lin_con;
00127 vector<bool> lin_con2;
00128
00129 int type;
00130
00131 double dual_bound(UserVector<double>& a);
00132
00133 public:
00134 DualBounds(Pointer<MinlpProblem> S_, Pointer<MinlpProblem> C_, Pointer<Param> param_, int type_=1);
00135
00136 int update_box(int n);
00137 int update_box() { return update_box(S->dim()); }
00138
00139 double obj_bound();
00140 };
00141
00142
00143 class IntervalReduction {
00144 public:
00145 typedef enum {LOWER, UPPER, WHATEVER} which_bound_type;
00146 private:
00147 class NodeData {
00148 friend ostream& operator<<(ostream& out, const NodeData& nd) {
00149 if (nd.block_nr>=0) out << nd.block_nr << ',' << nd.block_index;
00150 return out;
00151 }
00152 public:
00153 int block_nr, block_index;
00154
00155 NodeData(int block_nr_=-1, int block_index_=-1)
00156 : block_nr(block_nr_), block_index(block_index_)
00157 { }
00158
00159 NodeData& operator+=(const NodeData& nd) { return *this; }
00160 };
00161
00162 class EdgeData {
00163 friend ostream& operator<<(ostream& out, const EdgeData& ed);
00164 public:
00165 which_bound_type which_bound;
00166 int con_nr;
00167 double coeff;
00168
00169 EdgeData(int con_nr_, which_bound_type which_bound_, double coeff_)
00170 : con_nr(con_nr_), which_bound(which_bound_), coeff(coeff_)
00171 { }
00172
00173 bool operator<(const EdgeData& ed) const { return con_nr<ed.con_nr; }
00174
00175 const EdgeData& operator+=(const EdgeData& ed) const;
00176 };
00177 friend ostream& operator<<(ostream& out, const EdgeData& ed);
00178
00179 Pointer<MinlpProblem> prob;
00180
00181 typedef Graph<NodeData,EdgeData,true,true> DependencyGraph;
00182 DependencyGraph dependency_graph;
00183
00184 void run(dvector& newlow, dvector& newup, const dvector& oldlow, const dvector& oldup, set<pair<const DependencyGraph::NodeType*, which_bound_type> >& nodeset);
00185
00186 public:
00187 bool do_print;
00188 bool empty_boxes;
00189 double min_impr;
00190 set<pair<int, int> > reduced_integer;
00191
00194 dvector reduction_by_block;
00195 double reduction;
00196
00197 IntervalReduction(Pointer<MinlpProblem> prob_=NULL)
00198 : do_print(false), empty_boxes(false), min_impr(.01)
00199 { if (prob_) set_problem(prob_);
00200 }
00201
00202 void set_problem(Pointer<MinlpProblem> prob_);
00203
00204 void compute(dvector& newlow, dvector& newup, const dvector& oldlow, const dvector& oldup);
00205 void compute(dvector& newlow, dvector& newup, const dvector& oldlow, const dvector& oldup, set<pair<int, which_bound_type> >& startset);
00206
00207 void print_small_boxes(dvector& low, dvector& up);
00208 };
00209
00210
00213 class BoundsFinderLinear {
00214 private:
00215 Pointer<Param> param;
00216
00217 Pointer<MinlpProblem> prob;
00218
00219 Pointer<MIPSolver> solver;
00220
00221 MIPSolver::SolutionStatus compute_bound(double& bound, int index, bool low);
00222
00223 public:
00224 bool low, up, known;
00225
00226 BoundsFinderLinear(Pointer<MinlpProblem> prob_, Pointer<Param> param_);
00227
00228 int compute(dvector& newlow, dvector& newup, set<pair<int, IntervalReduction::which_bound_type> >* changed_var=NULL, double min_impr=0.01);
00229
00230 };
00231
00232 #endif