1 #include "CoinHelperFunctions.hpp"
2 #include "OsiClpSolverInterface.hpp"
9 return new OsiClpSolverInterface;
16 std::vector<MCF3_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<MCF3_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) {
119 sprintf(name,
"currlp-%i", cnt++);
122 printf(
"Current LP written in file %s.mps\n", name);
124 printf(
"Current LP written in file %s.lp\n", name);
137 const double*
x = lpres.
x();
138 for (i = vars.
size()-1; i >= 0; --i) {
142 const int vsize = v->
flow.getNumElements();
143 const int* vind = v->
flow.getIndices();
144 const double* vval = v->
flow.getElements();
145 for (j = 0; j < vsize; ++
j) {
146 f[vind[
j]] += vval[
j]*x[i];
150 std::map<int,double>&
f =
flows[i];
151 for (std::map<int,double>::iterator fi=f.begin(); fi != f.end(); ++fi) {
152 const double frac = fabs(fi->second - floor(fi->second) - 0.5);
161 std::map<int,double>&
f =
flows[i];
162 CoinPackedVector flow(
false);
164 for (std::map<int,double>::iterator fi=f.begin();
167 const double val = floor(fi->second + 0.5);
169 flow.insert(fi->first, val);
193 double* cost =
new double[numarcs];
194 const double*
pi = lpres.
pi();
195 const double*
nu = pi + numarcs;
199 for (i = numarcs-1; i >= 0; --i) {
202 cg_lp->setObjective(cost);
205 int* ind =
new int[numarcs];
206 double* val =
new double[numarcs];
213 const std::vector<MCF3_branch_decision>& hist =
branch_history[i];
214 for (j = hist.size() - 1; j >= 0; --
j) {
218 cg_lp->initialSolve();
219 if (
cg_lp->isProvenOptimal() &&
cg_lp->getObjValue() < nu[i] - 1
e-8) {
224 const double*
x =
cg_lp->getColSolution();
227 for (
int j = 0; j < numarcs; ++
j) {
228 const double xval = floor(x[j] + 0.5);
239 for (j = hist.size() - 1; j >= 0; --
j) {
240 const int ind = hist[
j].arc_index;
254 double true_lower_bound = 0.0;
258 true_lower_bound = old_lower_bound;
260 true_lower_bound = lpres.
objval();
269 return true_lower_bound;
278 const bool before_fathom,
295 static const CoinPackedVector emptyVector(
false);
296 const int numvars = vars.
size();
297 for (
int i = 0; i < numvars; ++i) {
299 dynamic_cast<const MCF3_var*
>(vars[i]);
343 std::map<int,double>&
f =
flows[i];
344 int most_frac_ind = -1;
345 double most_frac_val = 0.5-1
e-6;
346 double frac_val = 0.0;
347 for (std::map<int,double>::iterator fi=f.begin(); fi != f.end(); ++fi){
348 if (fi->first >= dummyStart)
350 const double frac = fabs(fi->second - floor(fi->second) - 0.5);
351 if (frac < most_frac_val) {
352 most_frac_ind = fi->first;
353 most_frac_val = frac;
354 frac_val = fi->second;
357 if (most_frac_ind >= 0) {
367 lb = CoinMax(lb, h.
lb);
368 ub = CoinMin(ub, h.
ub);
371 const int mid =
static_cast<int>(floor(frac_val));
389 for (j = child1_pos.
size() - 1; j >= 0; --
j) {
393 for (j = child0_pos.
size() - 1; j >= 0; --
j) {
402 &ivp,NULL,&ivb,NULL));
422 push_back(
new_branch[commodity_branched_on][0]);
427 push_back(
new_branch[commodity_branched_on][1]);
444 cg_lp =
new OsiClpSolverInterface();
448 const int numNz = 2*numCols;
450 double *clb =
new double[numCols];
451 double *cub =
new double[numCols];
452 double *obj =
new double[numCols];
453 double *rlb =
new double[numRows];
454 double *rub =
new double[numRows];
455 CoinBigIndex *start =
new int[numCols+1];
456 int *index =
new int[numNz];
457 double *value =
new double[numNz];
461 CoinZeroN(obj, numCols);
462 CoinZeroN(clb, numCols);
463 for (
int i = numCols - 1; i >= 0; --i) {
468 CoinZeroN(rlb, numRows);
469 CoinZeroN(rub, numRows);
478 start[numCols] = 2*numCols;
480 cg_lp->loadProblem(numCols, numRows, start, index, value,
481 clb, cub, obj, rlb, rub);
BCP_object_origin
This enumerative constant describes the origin (originating process) of an object (variable or cut)...
std::vector< MCF3_branch_decision > * branch_history
This class holds a column in a compressed form.
void unpack(BCP_buffer &buf)
void clear()
Delete every entry.
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...
std::vector< MCF3_branch_decision > * new_branch
virtual void set_user_data_for_children(BCP_presolved_lp_brobj *best, const int selected)
For each child create a user data object and put it into the appropriate entry in best->user_data()...
char entry(const chr_params key) const
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.
BCP_parameter_set< MCF3_par > par
BCP should continue to work on this node.
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the LP process by the Tree Manager.
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.
static const CouNumber pi
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
void MCF3_adjust_bounds(const BCP_vec< BCP_var * > &vars, std::vector< MCF3_branch_decision > *history, BCP_vec< int > &var_changed_pos, BCP_vec< double > &var_new_bd)
void fint fint fint real fint real real real real real real real real real * e
BCP_user_data * get_user_data()
Return a pointer to the BCP_user_data structure the user (may have) stored in this node...
BCP_vec< BCP_user_data * > & user_data()
Return a reference to the user data vector.
BCP_lp_prob * getLpProblemPointer()
Get the pointer.
OsiSolverInterface * lp_solver
A class that holds the methods about how to pack things.
This class describes a generic branching object.
std::map< int, double > * flows
BCP_branching_decision
This enumerative constant is the return value of the select_branching_candidates() method in [BCP_lp_...
OsiSolverInterface * cg_lp
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.
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 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_vec< BCP_var * > gen_vars
std::vector< int > commodities_with_candidate
The node should be fathomed without even trying to branch.
A presolved branching object candidate.
virtual OsiSolverInterface * initialize_solver_interface()
Create LP solver environment.
size_t size() const
Return the current number of entries.
std::vector< MCF3_branch_decision > * branch_history
This class describes the message buffer used for all processes of BCP.
const double * pi() const
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.
This class holds the results after solving an LP relaxation.
This class holds a MIP feasible primal solution.
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.
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.