1 #include "CoinHelperFunctions.hpp"
2 #include "OsiClpSolverInterface.hpp"
10 return new OsiClpSolverInterface;
17 std::vector<MCF1_branch_decision>* history,
21 for (
int i = vars.
size()-1; i >= 0; --i) {
24 const int vsize = v->
flow.getNumElements();
25 const int* vind = v->
flow.getIndices();
26 const double* vval = v->
flow.getElements();
28 bool violated =
false;
29 const std::vector<MCF1_branch_decision>& hist = history[v->
commodity];
30 for (
int j = hist.size()-1; !violated &&
j >= 0; --
j) {
33 for (
int k = 0;
k < vsize; ++
k) {
39 violated = (f < h.
lb || f > h.
ub);
58 for (
int i = vars.
size()-1; i >= 0; --i) {
64 const int vsize = v->
flow.getNumElements();
65 const int* vind = v->
flow.getIndices();
66 const double* vval = v->
flow.getElements();
69 for (
int k = 0;
k < vsize; ++
k) {
75 if (f < decision.lb || f > decision.
ub) {
101 for (i = vars.
size()-1; i >= 0; --i) {
104 if (v->
ub() == 0.0) {
136 sprintf(name,
"currlp-%i", cnt++);
139 printf(
"Current LP written in file %s.mps\n", name);
141 printf(
"Current LP written in file %s.lp\n", name);
154 const double*
x = lpres.
x();
155 for (i = vars.
size()-1; i >= 0; --i) {
159 const int vsize = v->
flow.getNumElements();
160 const int* vind = v->
flow.getIndices();
161 const double* vval = v->
flow.getElements();
162 for (j = 0; j < vsize; ++
j) {
163 f[vind[
j]] += vval[
j]*x[i];
167 std::map<int,double>&
f =
flows[i];
168 for (std::map<int,double>::iterator fi=f.begin(); fi != f.end(); ++fi) {
169 const double frac = fabs(fi->second - floor(fi->second) - 0.5);
178 std::map<int,double>&
f =
flows[i];
179 CoinPackedVector flow(
false);
181 for (std::map<int,double>::iterator fi=f.begin();
184 const double val = floor(fi->second + 0.5);
186 flow.insert(fi->first, val);
210 double* cost =
new double[numarcs];
211 const double*
pi = lpres.
pi();
212 const double*
nu = pi + numarcs;
216 for (i = numarcs-1; i >= 0; --i) {
219 cg_lp->setObjective(cost);
222 int* ind =
new int[numarcs];
223 double* val =
new double[numarcs];
230 const std::vector<MCF1_branch_decision>& hist =
branch_history[i];
231 for (j = hist.size() - 1; j >= 0; --
j) {
235 cg_lp->initialSolve();
236 if (
cg_lp->isProvenOptimal() &&
cg_lp->getObjValue() < nu[i] - 1
e-8) {
241 const double*
x =
cg_lp->getColSolution();
244 for (
int j = 0; j < numarcs; ++
j) {
245 const double xval = floor(x[j] + 0.5);
256 for (j = hist.size() - 1; j >= 0; --
j) {
257 const int ind = hist[
j].arc_index;
271 double true_lower_bound = 0.0;
275 true_lower_bound = old_lower_bound;
277 true_lower_bound = lpres.
objval();
286 return true_lower_bound;
295 const bool before_fathom,
312 static const CoinPackedVector emptyVector(
false);
313 const int numvars = vars.
size();
314 for (
int i = 0; i < numvars; ++i) {
316 dynamic_cast<const MCF1_var*
>(vars[i]);
363 std::map<int,double>&
f =
flows[i];
364 int most_frac_ind = -1;
365 double most_frac_val = 0.5-1
e-6;
366 double frac_val = 0.0;
367 for (std::map<int,double>::iterator fi=f.begin(); fi != f.end(); ++fi){
368 if (fi->first >= dummyStart)
370 const double frac = fabs(fi->second - floor(fi->second) - 0.5);
371 if (frac < most_frac_val) {
372 most_frac_ind = fi->first;
373 most_frac_val = frac;
374 frac_val = fi->second;
377 if (most_frac_ind >= 0) {
388 lb = CoinMax(lb, h.
lb);
389 ub = CoinMin(ub, h.
ub);
392 const int mid =
static_cast<int>(floor(frac_val));
394 lb, mid, mid+1, ub));
412 for (j = child1_pos.
size() - 1; j >= 0; --
j) {
418 for (j = child0_pos.
size() - 1; j >= 0; --
j) {
427 NULL,NULL,NULL,NULL));
446 cg_lp =
new OsiClpSolverInterface();
450 const int numNz = 2*numCols;
452 double *clb =
new double[numCols];
453 double *cub =
new double[numCols];
454 double *obj =
new double[numCols];
455 double *rlb =
new double[numRows];
456 double *rub =
new double[numRows];
457 CoinBigIndex *start =
new int[numCols+1];
458 int *index =
new int[numNz];
459 double *value =
new double[numNz];
463 CoinZeroN(obj, numCols);
464 CoinZeroN(clb, numCols);
465 for (
int i = numCols - 1; i >= 0; --i) {
470 CoinZeroN(rlb, numRows);
471 CoinZeroN(rub, numRows);
480 start[numCols] = 2*numCols;
482 cg_lp->loadProblem(numCols, numRows, start, index, value,
483 clb, cub, obj, rlb, rub);
OsiSolverInterface * cg_lp
BCP_object_origin
This enumerative constant describes the origin (originating process) of an object (variable or cut)...
This class holds a column in a compressed form.
std::vector< MCF1_branch_decision > * branch_history
void clear()
Delete every entry.
void unpack(BCP_buffer &buf)
char entry(const chr_params key) const
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the LP process by the Tree Manager.
BCP should continue to work on this node.
static const CouNumber pi
virtual OsiSolverInterface * initialize_solver_interface()
Create LP solver environment.
void push_back(const_reference x)
Append x to the end of the vector.
void fint fint fint real fint real real real real * f
virtual void generate_vars_in_lp(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const bool before_fathom, BCP_vec< BCP_var * > &new_vars, BCP_vec< BCP_col * > &new_cols)
Generate variables within the LP process.
void fint fint fint real fint real real real real real real real real real * e
double ub() const
Return the upper bound.
virtual BCP_branching_decision select_branching_candidates(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_lp_var_pool &local_var_pool, const BCP_lp_cut_pool &local_cut_pool, BCP_vec< BCP_lp_branching_object * > &cands, bool force_branch=false)
Decide whether to branch or not and select a set of branching candidates if branching is decided upon...
BCP_lp_prob * getLpProblemPointer()
Get the pointer.
OsiSolverInterface * lp_solver
A class that holds the methods about how to pack things.
BCP_vec< BCP_var * > gen_vars
This class describes a generic branching object.
void MCF1_adjust_bounds(const BCP_vec< BCP_var * > &vars, std::vector< MCF1_branch_decision > *history, BCP_vec< int > &var_changed_pos, BCP_vec< double > &var_new_bd)
BCP_branching_decision
This enumerative constant is the return value of the select_branching_candidates() method in [BCP_lp_...
virtual BCP_solution * test_feasibility(const BCP_lp_result &lp_result, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Evaluate and return MIP feasibility of the current solution.
void add_entry(BCP_var *var, double value)
Append a variable and the corresponding value to the end of the appropriate vectors.
double upper_bound() const
Return what is the best known upper bound (might be BCP_DBL_MAX)
virtual void vars_to_cols(const BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_var * > &vars, BCP_vec< BCP_col * > &cols, const BCP_lp_result &lpres, BCP_object_origin origin, bool allow_multiple)
Convert a set of variables into corresponding columns for the current LP relaxation.
The node should be fathomed without even trying to branch.
size_t size() const
Return the current number of entries.
This class describes the message buffer used for all processes of BCP.
const double * pi() const
virtual double compute_lower_bound(const double old_lower_bound, const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Compute a true lower bound for the subproblem.
virtual void initialize_new_search_tree_node(const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_vec< BCP_obj_status > &var_status, const BCP_vec< BCP_obj_status > &cut_status, BCP_vec< int > &var_changed_pos, BCP_vec< double > &var_new_bd, BCP_vec< int > &cut_changed_pos, BCP_vec< double > &cut_new_bd)
Initializing a new search tree node.
double lb() const
Return the lower bound.
void purge_ptr_vector(BCP_vec< T * > &pvec, typename BCP_vec< T * >::iterator first, typename BCP_vec< T * >::iterator last)
This function purges the entries [first,last) from the vector of pointers pvec.
void unpack(BCP_buffer &buf)
Unpack the parameter set from the buffer.
std::map< int, double > * flows
This class holds the results after solving an LP relaxation.
BCP_parameter_set< MCF1_par > par
This class holds a MIP feasible primal solution.
void append(const BCP_vec< T > &x)
Append the entries in x to the end of the vector.
void fint fint fint real fint real * x
This is the abstract base class for a solution to a Mixed Integer Programming problem.