21 #include "OsiClpSolverInterface.hpp"
22 #include "CglSimpleRounding.hpp"
23 #include "CglKnapsackCover.hpp"
37 EPS = os_prob->EPSILON;
46 std::cout <<
"number of variables " << os_prob->osinstance->getVariableNumber() << std::endl;
57 OsiClpSolverInterface * clp =
new OsiClpSolverInterface;
58 clp->messageHandler()->setLogLevel(0);
81 std::cout << relSol << std::endl;
92 std::cout << relSol << std::endl;
170 std::cout <<
"INSIDE BRANCHING DECISION: TESTING VARIABLE TYPES " << std::endl;
171 std::cout <<
"SIZE OF VARS = " << vars.
size() << std::endl;
172 std::cout <<
"SIZE OF LOCAL VAR POOL = " << local_var_pool.
size() << std::endl;
173 std::cout <<
"CANDS SIZE = " << cands.
size() << std::endl;
178 int num_vars = vars.
size();
193 if( local_cut_pool.
size() > 0 ) {
195 cout <<
"select_branching_candidates() returns BCP_DoNotBranch" << endl;
202 const double *
x = lpres.
x();
205 for(i = 0; i < num_vars; i++) {
212 if( vars[ i]->var_type() < 2) {
213 if((x[i] -floor( x[i]) > intTol) && (ceil( x[i]) - x[i] > intTol)) {
218 append_branching_vars( lpres.
x(), vars, select_pos, cands);
220 cout <<
"Branching on variable: " << i <<
" (" << x[i] <<
") depth: " << current_level() << endl;
226 if (cands.
size() == 0 && local_var_pool.
size() == 0) {
227 throw BCP_fatal_error(
"select_banching_candidate() : No cut in pool but couldn't select branching variable.\n");
231 if (cands.
size() == 0 && local_var_pool.
size() > 0) {
236 cout <<
"select_branching_candidates() returns BCP_DoBranch" << endl;
296 std::cout <<
"Execute cuts_to_rows" << std::endl;
297 const int cutnum = cuts.
size();
298 for (
int i=0; i<cutnum; ++i) {
299 const OsiRowCut* bcut =
dynamic_cast<const OS_cut*
>(cuts[i]);
318 std::cout <<
"EXECUTE vars_to_cols **************" << std::endl;
319 static const CoinPackedVector emptyVector(
false);
320 const int numvars = vars.
size();
322 for (i = 0; i < numvars; ++i) {
342 const double old_lower_bound,
343 double& true_lower_bound,
351 generated_cuts =
false;
352 generated_vars =
false;
359 OsiClpSolverInterface* my_lp_solver;
361 my_lp_solver =
dynamic_cast<OsiClpSolverInterface *
>(getLpProblemPointer()->lp_solver);
366 CglKnapsackCover knapCover;
369 OsiSolverInterface::ApplyCutsReturnCode acRc;
378 knapCover.generateCuts(*my_lp_solver, my_cuts);
379 const double *
x = lpres.
x();
382 int *pvIndexes = NULL;
383 double *pvElements = NULL;
387 int ncuts = my_cuts.sizeRowCuts();
388 const OsiRowCut **newRowCuts =
new const OsiRowCut * [ncuts];
389 std::cout <<
"sizeRowCuts() = " << ncuts << std::endl;
390 for(i = 0; i < ncuts; i++) {
391 newRowCuts[i] = &my_cuts.rowCut(i);
392 cut =
new OS_cut( *newRowCuts[i]);
395 cout <<
" sense = " << newRowCuts[i]->sense() << endl;
396 pv = newRowCuts[i]->row();
397 pvIndexes = pv.getIndices();
398 pvElements = pv.getElements();
399 numElem = pv.getNumElements();
402 for(k = 0; k < numElem; k++){
403 lhs += pvElements[
k]*x[ pvIndexes[
k] ];
407 if( (newRowCuts[i]->sense() ==
'L') && (lhs > newRowCuts[i]->rhs() +epsilon ) ){
408 cout <<
" lhs - rhs = " << lhs - newRowCuts[i]->rhs() << endl;
409 std::cout <<
"PUSHING BACK KNAPSACK COVER ROUNDING CUT" << std::endl;
410 algo_cuts.push_back( cut);
414 generated_cuts = (algo_cuts.size() > 0);
415 for(i = 0; i < ncuts; i++){
427 int num_vars = vars.
size();
428 const double *
x = lpres.
x();
429 OsiRowCut* rcut =
new OsiRowCut();
431 int *cutind =
new int[ num_vars];
436 double cutrhs = 503.77;
439 double *cutcoef =
new double[ num_vars];
441 for(i=0; i < num_vars; i++) {
447 std::cout <<
"The LHS IS EQUAL TO === " << lhs << std::endl;
450 if(lhs > cutrhs + EPS) {
454 rcut->setUb( cutrhs);
455 rcut->setRow( cut_nz, cutind, cutcoef);
457 algo_cuts.push_back( cut);
458 std::cout <<
"WE ARE ADDING A CUT!!!!!!!! " << std::endl;
463 generated_cuts = (algo_cuts.size() > 0);
470 const double*
pi = lpres.
pi();
472 int varIdx = vars.
size();
473 int* ind =
new int[ numNonz];
474 double* val =
new double[ numNonz];
475 double objVal = -13.0;
476 double reducedCost = 0.0;
489 for(i = 0 ; i < numNonz; i++){
490 reducedCost += -pi[ i]*val[ i];
492 reducedCost += objVal;
493 std::cout <<
"REDUCED COST = ************** " << reducedCost << std::endl;
495 if(reducedCost < -.01 && vars.
size() < 3) {
496 std::cout <<
"CALL OS_var CONSTRUCTOR " << std::endl;
497 algo_vars.push_back(
new OS_var(varIdx, CoinPackedVector(numNonz, ind, val,
true), objVal));
498 std::cout <<
"DONE WITH CALL OS_var CONSTRUCTOR " << std::endl;
505 generated_vars = (algo_vars.size() > 0);
515 if( (generated_vars ==
false) && (generated_cuts ==
false) ){
517 old_lower_bound, true_lower_bound, sol, new_cuts,
518 new_rows, new_vars, new_cols);
525 if (generated_cuts) {
526 new_cuts.
append( algo_cuts);
530 int cutnum = algo_cuts.size();
532 for (i = 0; i < cutnum; ++i) {
535 const OsiRowCut* bcut =
dynamic_cast<const OS_cut*
>(algo_cuts[i]);
554 if (generated_vars) {
555 new_vars.
append( algo_vars);
561 static const CoinPackedVector emptyVector(
false);
562 const int numvars = algo_vars.size();
563 for (i = 0; i < numvars; ++i) {
564 const OS_var* v =
dynamic_cast<const OS_var*
>(algo_vars[i]);
580 std::cout <<
"GENERATED VARS IS TRUE ************** " << std::endl;
581 true_lower_bound = old_lower_bound;
583 std::cout <<
"GENERATED VARS IS FALSE ************** " << std::endl;
584 true_lower_bound = lpres.
objval();
586 std::cout <<
"TRUE LOWER BOUND ************** " << true_lower_bound << std::endl;
597 const bool final_lp_solution){
610 const double *
x = lpres.
x();
612 for (i = 0; i < vars.
size(); ++i) {
613 if(x[ i] > ietol) std::cout << x[ i] << std::endl;
BCP_object_origin
This enumerative constant describes the origin (originating process) of an object (variable or cut)...
char get_param(const BCP_lp_par::chr_params key) const
Simple representation of a cut by storing non zero coefficients only.
Values not further from an integer value than the value of this parameter are considered to be intege...
This class holds a column in a compressed form.
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 process_lp_result(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const double old_lower_bound, double &true_lower_bound, BCP_solution *&sol, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows, BCP_vec< BCP_var * > &new_vars, BCP_vec< BCP_col * > &new_cols)
Process the result of an iteration.
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
void set_param(const BCP_lp_par::chr_params key, const bool val)
Turn on the user hook "display_lp_solution".
BCP should continue to work on this node.
int * set_zero
Variables that have been set to zero by branching decisions.
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_vec< double > * forced_var_bd
Contains the actual bounds for the variables indexed by forced_var_pos.
static const CouNumber pi
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 process_lp_result(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const double old_lower_bound, double &true_lower_bound, BCP_solution *&sol, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows, BCP_vec< BCP_var * > &new_vars, BCP_vec< BCP_col * > &new_cols)
Process the result of an iteration.
void fint fint fint real fint real real real real real real real real real fint real fint * lp
virtual void display_lp_solution(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const bool final_lp_solution)
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_...
Class taking care of interaction between user data and Bcp.
virtual void unpack_module_data(BCP_buffer &buf)
Unpack data sent from the tree manager.
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.
BCP_vec< int > * forced_var_pos
Positions of variables whose bounds change ("forcibly", by branching) in the children.
Currently there isn't any error handling in BCP.
virtual void display_lp_solution(const BCP_lp_result &lp_result, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const bool final_lp_solution)
Display the result of most recent LP optimization.
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.
virtual OsiSolverInterface * initialize_solver_interface()
Pack algorithmic cuts.
This class describes the message buffer used for all processes of BCP.
const double * pi() const
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.
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.
int max_card_set_zero
Maximum number of variables that may be set to zero by branching decisions.
CoinPackedVector coinPackedVec
This class holds the results after solving an LP relaxation.
virtual void modify_lp_parameters(OsiSolverInterface *lp, bool in_strong_branching)
Modify the parameters of the LP solver.
BCP_lp_branching_object * candidate()
Return a pointer to the candidate.
void append(const BCP_vec< T > &x)
Append the entries in x to the end of the vector.
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 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.