1 #include "CoinHelperFunctions.hpp"
2 #include "OsiClpSolverInterface.hpp"
9 return new OsiClpSolverInterface;
16 std::vector<MCF2_branch_decision>* history,
20 for (
int i = vars.
size()-1; i >= 0; --i) {
23 const int vsize = v->
flow.getNumElements();
24 const int* vind = v->
flow.getIndices();
25 const double* vval = v->
flow.getElements();
27 bool violated =
false;
28 const std::vector<MCF2_branch_decision>& hist = history[v->
commodity];
29 for (
int j = hist.size()-1; !violated &&
j >= 0; --
j) {
32 for (
int k = 0;
k < vsize; ++
k) {
38 violated = (f < h.
lb || f > h.
ub);
57 for (
int i = vars.
size()-1; i >= 0; --i) {
63 const int vsize = v->
flow.getNumElements();
64 const int* vind = v->
flow.getIndices();
65 const double* vval = v->
flow.getElements();
68 for (
int k = 0;
k < vsize; ++
k) {
74 if (f < decision.lb || f > decision.
ub) {
100 for (i = vars.
size()-1; i >= 0; --i) {
103 if (v->
ub() == 0.0) {
142 sprintf(name,
"currlp-%i", cnt++);
145 printf(
"Current LP written in file %s.mps\n", name);
147 printf(
"Current LP written in file %s.lp\n", name);
160 const double*
x = lpres.
x();
161 for (i = vars.
size()-1; i >= 0; --i) {
165 const int vsize = v->
flow.getNumElements();
166 const int* vind = v->
flow.getIndices();
167 const double* vval = v->
flow.getElements();
168 for (j = 0; j < vsize; ++
j) {
169 f[vind[
j]] += vval[
j]*x[i];
173 std::map<int,double>&
f =
flows[i];
174 for (std::map<int,double>::iterator fi=f.begin(); fi != f.end(); ++fi) {
175 const double frac = fabs(fi->second - floor(fi->second) - 0.5);
184 std::map<int,double>&
f =
flows[i];
185 CoinPackedVector flow(
false);
187 for (std::map<int,double>::iterator fi=f.begin();
190 const double val = floor(fi->second + 0.5);
192 flow.insert(fi->first, val);
216 double* cost =
new double[numarcs];
217 const double*
pi = lpres.
pi();
218 const double*
nu = pi + numarcs;
222 for (i = numarcs-1; i >= 0; --i) {
225 cg_lp->setObjective(cost);
228 int* ind =
new int[numarcs];
229 double* val =
new double[numarcs];
236 const std::vector<MCF2_branch_decision>& hist =
branch_history[i];
237 for (j = hist.size() - 1; j >= 0; --
j) {
241 cg_lp->initialSolve();
242 if (
cg_lp->isProvenOptimal() &&
cg_lp->getObjValue() < nu[i] - 1
e-8) {
247 const double*
x =
cg_lp->getColSolution();
250 for (
int j = 0; j < numarcs; ++
j) {
251 const double xval = floor(x[j] + 0.5);
262 for (j = hist.size() - 1; j >= 0; --
j) {
263 const int ind = hist[
j].arc_index;
277 double true_lower_bound = 0.0;
281 true_lower_bound = old_lower_bound;
283 true_lower_bound = lpres.
objval();
292 return true_lower_bound;
301 const bool before_fathom,
318 static const CoinPackedVector emptyVector(
false);
319 const int numvars = vars.
size();
320 for (
int i = 0; i < numvars; ++i) {
322 dynamic_cast<const MCF2_var*
>(vars[i]);
369 std::map<int,double>&
f =
flows[i];
370 int most_frac_ind = -1;
371 double most_frac_val = 0.5-1
e-6;
372 double frac_val = 0.0;
373 for (std::map<int,double>::iterator fi=f.begin(); fi != f.end(); ++fi){
374 if (fi->first >= dummyStart)
376 const double frac = fabs(fi->second - floor(fi->second) - 0.5);
377 if (frac < most_frac_val) {
378 most_frac_ind = fi->first;
379 most_frac_val = frac;
380 frac_val = fi->second;
383 if (most_frac_ind >= 0) {
396 lb = CoinMax(lb, h.
lb);
397 ub = CoinMin(ub, h.
ub);
400 const int mid =
static_cast<int>(floor(frac_val));
402 lb, mid, mid+1, ub));
423 for (j = child1_pos.
size() - 1; j >= 0; --
j) {
427 for (j = child0_pos.
size() - 1; j >= 0; --
j) {
436 &ivp,NULL,&ivb,NULL));
455 cg_lp =
new OsiClpSolverInterface();
459 const int numNz = 2*numCols;
461 double *clb =
new double[numCols];
462 double *cub =
new double[numCols];
463 double *obj =
new double[numCols];
464 double *rlb =
new double[numRows];
465 double *rub =
new double[numRows];
466 CoinBigIndex *start =
new int[numCols+1];
467 int *index =
new int[numNz];
468 double *value =
new double[numNz];
472 CoinZeroN(obj, numCols);
473 CoinZeroN(clb, numCols);
474 for (
int i = numCols - 1; i >= 0; --i) {
479 CoinZeroN(rlb, numRows);
480 CoinZeroN(rub, numRows);
489 start[numCols] = 2*numCols;
491 cg_lp->loadProblem(numCols, numRows, start, index, value,
492 clb, cub, obj, rlb, rub);
BCP_object_origin
This enumerative constant describes the origin (originating process) of an object (variable or cut)...
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the LP process by the Tree Manager.
This class holds a column in a compressed form.
void clear()
Delete every entry.
void unpack(BCP_buffer &buf)
char entry(const chr_params key) const
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.
BCP should continue to work on this node.
OsiSolverInterface * cg_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.
std::vector< MCF2_branch_decision > * branch_history
static const CouNumber pi
BCP_vec< BCP_var * > gen_vars
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
std::map< int, double > * flows
void fint fint fint real fint real real real real real real real real real * e
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_parameter_set< MCF2_par > par
double ub() const
Return the upper bound.
BCP_lp_prob * getLpProblemPointer()
Get the pointer.
OsiSolverInterface * lp_solver
A class that holds the methods about how to pack things.
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.
This class describes a generic branching object.
BCP_branching_decision
This enumerative constant is the return value of the select_branching_candidates() method in [BCP_lp_...
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)
The node should be fathomed without even trying to branch.
size_t size() const
Return the current number of entries.
void MCF2_adjust_bounds(const BCP_vec< BCP_var * > &vars, std::vector< MCF2_branch_decision > *history, BCP_vec< int > &var_changed_pos, BCP_vec< double > &var_new_bd)
This class describes the message buffer used for all processes of BCP.
const double * pi() const
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.
virtual OsiSolverInterface * initialize_solver_interface()
Create LP solver environment.
This class holds the results after solving an LP relaxation.
This class holds a MIP feasible primal solution.
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.
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.
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.