17 #include "OsiClpSolverInterface.hpp"
30 EPS = p_desc->EPSILON;
40 OsiClpSolverInterface * clp =
new OsiClpSolverInterface;
41 clp->messageHandler()->setLogLevel(0);
44 clp->getModelPtr()->messageHandler()->setLogLevel(0);
47 clp->setHintParam(OsiDoDualInResolve,
true, OsiHintTry);
79 bool in_strong_branching)
84 if (in_strong_branching) {
86 lp->setIntParam(OsiMaxNumIterationHotStart, 50);
90 lp->writeLp(
"lpnode",
"lp");
91 cout <<
"LP node written in file lpnode.lp" << endl;
119 if(getLpProblemPointer()->lp_solver->isAbandoned() ||
120 getLpProblemPointer()->lp_solver->isProvenPrimalInfeasible() ||
121 getLpProblemPointer()->lp_solver->isDualObjectiveLimitReached() ||
122 getLpProblemPointer()->lp_solver->isIterationLimitReached()) {
126 int i,
j,
k, cn = p_desc->colnum;;
127 const double *
x = lp_result.
x();
128 double *check_lhs =
new double[p_desc->indexed->getNumRows()];
132 violated_cuts.clear();
133 p_desc->indexed->times(lp_result.
x(), check_lhs);
134 for (i=0; i<p_desc->indexed->getNumRows(); ++i) {
135 if ((check_lhs[i] < p_desc->rlb_indexed[i] - EPS) ||
136 (check_lhs[i] > p_desc->rub_indexed[i] + EPS))
137 violated_cuts.push_back(i);
142 OsiRowCut* rcut =
new OsiRowCut();
143 int *cutind =
new int[cn], cut_nz;
144 double* cutcoef =
new double[cn], cutrhs = 1;
148 for(i=0; i<cn; i++) {
157 if(x[i] + x[j] + x[k] > 1 + EPS) {
167 rcut->setRow(cut_nz, cutind, cutcoef);
170 algo_cuts.push_back(cut);
181 return (violated_cuts.empty() + algo_cuts.empty() == 2 ?
192 const int var_bound_changes_since_logical_fixing,
215 for (i=violated_cuts.size()-1; i>=0; --i) {
216 const int ind = violated_cuts[i];
218 p_desc->rub_indexed[ind]));
220 cout <<
"generate_cuts_in_lp(): found " << new_cuts.
size()
221 <<
" indexed cuts" << endl;
223 for(i=algo_cuts.size()-1; i>=0; --i) {
226 cout <<
"generate_cuts_in_lp(): found " << algo_cuts.size()
227 <<
" algorithmic cuts" << endl;
242 int i,
j,
k, cn = p_desc->colnum;
243 const double *
x = lpres.
x();
244 double *rounded_x =
new double[cn];
246 for(i=0; i<cn; i++) {
247 if(x[i] > 0.5 + EPS) {
257 int nb_rows_core = p_desc->core->getNumRows();
258 int nb_rows_indexed = p_desc->indexed->getNumRows();
259 int max_core_indexed;
261 if(nb_rows_indexed > nb_rows_core) {
262 max_core_indexed = nb_rows_indexed;
265 max_core_indexed = nb_rows_core;
268 double *check_lhs =
new double[max_core_indexed];
272 p_desc->core->times(rounded_x, check_lhs);
274 for (i=0; i<nb_rows_core; ++i) {
275 if ((check_lhs[i] < p_desc->rlb_core[i] - EPS) ||
276 (check_lhs[i] > p_desc->rub_core[i] + EPS)) {
280 cout <<
"generate_heuristic_solution() returns nothing.\n"
288 p_desc->indexed->times(rounded_x, check_lhs);
289 for (i=0; i<nb_rows_indexed; ++i) {
290 if ((check_lhs[i] < p_desc->rlb_indexed[i] - EPS) ||
291 (check_lhs[i] > p_desc->rub_indexed[i] + EPS)) {
295 cout <<
"generate_heuristic_solution() returns nothing.\n"
305 for(i=0; i<cn; i++) {
309 if(x[i] + x[j] + x[k] > 1 + EPS) {
312 cout <<
"generate_heuristic_solution() returns nothing.\n"
327 for(i=0; i<cn; i++) {
328 ind = core_vars[i]->bcpind();
329 if(rounded_x[ind] > EPS) {
330 heur_sol->
add_entry(core_vars[i], rounded_x[ind]);
335 cout <<
"generate_heuristic_solution() returns a solution.\n"
361 const int cutnum = cuts.
size();
362 for (
int i=0; i<cutnum; ++i) {
366 const int ind = icut->
index();
368 p_desc->rlb_indexed[ind],
369 p_desc->rub_indexed[ind]));
373 const OsiRowCut* bcut =
dynamic_cast<const BB_cut*
>(cuts[i]);
407 if(local_cut_pool.
size() > 0) {
409 cout <<
"select_branching_candidates() returns BCP_DoNotBranch"
419 const double *
x = lpres.
x();
422 for(i=0; i<p_desc->colnum; i++) {
424 if((x[i] > EPS) && (x[i] < 1-EPS)) {
429 append_branching_vars(lpres.
x(), vars, select_pos, cands);
431 cout <<
"Branching on variable: " << i <<
" (" << x[i]
432 <<
") depth: " << current_level() << endl;
437 if (cands.
size() == 0) {
438 throw BCP_fatal_error(
"select_banching_candidate() : No cut in pool but couldn't select branching variable.\n");
442 cout <<
"select_branching_candidates() returns BCP_DoBranch" << endl;
450 local_cut_pool, cands,
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)
Called at the end of each iteration.
BCP_object_origin
This enumerative constant describes the origin (originating process) of an object (variable or cut)...
virtual OsiSolverInterface * initialize_solver_interface()
Called only once at the beginning, from the root node.
int index() const
Constructor from content of buffer.
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
virtual void generate_cuts_in_lp(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows)
Cut generation.
bool _delete_vars
An indicator to show whether the pointers in _vars should be deleted upon destruction or not...
virtual void logical_fixing(const BCP_lp_result &lpres, 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, const int var_bound_changes_since_logical_fixing, BCP_vec< int > &changed_pos, BCP_vec< double > &new_bd)
Perform fixing of variables.
virtual void unpack_module_data(BCP_buffer &buf)
Unpack data sent from the tree manager.
When doing a sprint sort of algorithm on the cuts (i.e., leave out a number of cuts at the beginning ...
BCP should continue to work on this node.
int * set_zero
Variables that have been set to zero by branching decisions.
BCP_vec< double > * forced_var_bd
Contains the actual bounds for the variables indexed by forced_var_pos.
virtual void cuts_to_rows(const BCP_vec< BCP_var * > &vars, BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_row * > &rows, const BCP_lp_result &lpres, BCP_object_origin origin, bool allow_multiple)
Describes how to get a row of the matrix from the representation of the cut.
void push_back(const_reference x)
Append x to the end of the vector.
real_user_data * p_rud
Pointer on an object holding the user data itself.
BCP_vec< BCP_user_data * > & user_data()
Return a reference to the user data vector.
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)
Initialize data members at the start of processing a new subproblem.
void fint fint fint real fint real real real real real real real real real fint real fint * lp
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...
virtual BCP_solution * test_feasibility(const BCP_lp_result &lp_result, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Test feasibility of the LP solution.
int card_set_zero
Number of variables set to zero by branching descisions.
int child_num
The number of children for this branching object.
Class handling user data.
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_...
Simple representation of a cut by storing non zero coefficients only.
Class taking care of interaction between user data and Bcp.
void add_entry(BCP_var *var, double value)
Append a variable and the corresponding value to the end of the appropriate vectors.
virtual BCP_solution * generate_heuristic_solution(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Simple rounding heuristic.
virtual void modify_lp_parameters(OsiSolverInterface *lp, const int changeType, bool in_strong_branching)
Modify the parameters of the LP solver.
BCP_vec< int > * forced_var_pos
Positions of variables whose bounds change ("forcibly", by branching) in the children.
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.
Currently there isn't any error handling in BCP.
int is_processed
Indicator for mmory management: If is_processed = 1, the associated user data may be erased...
A presolved branching object candidate.
size_t size() const
Return the current number of entries.
This class describes the message buffer used for all processes of BCP.
int max_card_set_zero
Maximum number of variables that may be set to zero by branching decisions.
This class holds the results after solving an LP relaxation.
virtual void set_user_data_for_children(BCP_presolved_lp_brobj *best, const int selected)
Set up the user data for the children according to the chosen branching object.
BCP_lp_branching_object * candidate()
Return a pointer to the candidate.
This class holds a MIP feasible primal solution.
void fint fint fint real fint real * x
This class holds a row in a compressed form.
This is the abstract base class for a solution to a Mixed Integer Programming problem.