9 #include "OsiClpSolverInterface.hpp"
36 fseek(ipopt, 0, SEEK_END);
37 int len = ftell(ipopt) + 1;
38 fseek(ipopt, 0, SEEK_SET);
39 char* ipopt_content =
new char[len+1];
40 len = fread(ipopt_content, 1, len, ipopt);
42 delete[] ipopt_content;
49 fseek(nl, 0, SEEK_END);
50 int len = ftell(nl) + 1;
51 fseek(nl, 0, SEEK_SET);
52 char* nl_content =
new char[len+1];
53 len = fread(nl_content, 1, len, nl);
79 #if defined(BM_DISREGARD_SOS)
82 printf(
"There are SOS constraints... disregarding them...\n");
88 const int numCols = clp.getNumCols();
89 const int numRows = clp.getNumRows();
91 const double* clb = clp.getColLower();
92 const double* cub = clp.getColUpper();
94 double* obj =
new double[numCols];
96 std::cout<<
"Doing branch and bound"<<std::endl;
97 CoinFillN(obj, numCols, 0.0);
100 std::cout<<
"Doing hybrid"<<std::endl;
101 CoinDisjointCopyN(clp.getObjCoefficients(), numCols, obj);
103 const double* rlb = clp.getRowLower();
104 const double* rub = clp.getRowUpper();
105 for (
int i = 0; i < numRows; ++i) {
109 matrix->
copyOf(*clp.getMatrixByCol(), obj, clb, cub, rlb, rub);
113 for (
int i = 0; i < numCols; ++i) {
123 for (
int i = 0; i < numCols; ++i) {
128 #if ! defined(BM_DISREGARD_SOS)
148 bool write_file,
bool write_screen)
167 const int numCols = clp.getNumCols();
174 double* dsol =
new double[numCols];
175 for (i = 0; i < numCols; ++i) {
180 const int size = vars.
size();
181 for (i = 0; i < size; ++i) {
182 const int ind = vars[i]->bcpind();
183 const double v = values[i];
184 const BCP_var_t type = vars[i]->var_type();
190 printf(
"bonmin: feasible solution found. Objective value: %f\n",
192 for (i = 0; i < size; ++i) {
193 printf(
" index: %5i value: %f\n",
194 vars[i]->bcpind(), dsol[vars[i]->bcpind()]);
224 bool write_screen =
false;
227 printf(
"TM: Running time: %.3f\n", CoinWallclockTime() - p->
start_time);
228 printf(
"TM: search tree size: %i ( processed %i ) max depth: %i\n",
234 printf(
"TM: No feasible solution is found\n");
236 printf(
"TM: The best solution found has value %f\n",
260 static inline const char*
name() {
return "BMSearchTreeCompareBest"; }
262 const CoinTreeSiblings* y)
const {
263 double allowable_gap = 1
e-8;
264 const double xq = x->currentNode()->getQuality();
265 const double yq = y->currentNode()->getQuality();
266 const int xd = x->currentNode()->getDepth();
267 const int yd = y->currentNode()->getDepth();
268 return ((xq < yq-allowable_gap) ||
269 (xq <= yq+allowable_gap && xd > yd));
279 CoinSearchTreeBase*& candidates)
285 candidates =
new CoinSearchTree<BMSearchTreeCompareBest>;
286 printf(
"Creating candidate list with BMSearchTreeCompareBest\n");
289 candidates =
new CoinSearchTree<CoinSearchTreeCompareBreadth>;
290 printf(
"Creating candidate list with CoinSearchTreeCompareBreadth\n");
293 candidates =
new CoinSearchTree<CoinSearchTreeCompareDepth>;
294 printf(
"Creating candidate list with CoinSearchTreeCompareDepth\n");
297 candidates =
new CoinSearchTree<CoinSearchTreeComparePreferred>;
298 printf(
"Creating candidate list with CoinSearchTreeComparePreferred\n");
309 double* downTotalChange =
pseudoCosts_.downTotalChange();
323 downTotalChange[objInd] += pcChange;
324 ++downNumber[objInd];
326 upTotalChange[objInd] += pcChange;
void initialize(char **&argv)
initialize bonmin with ampl model using the command line arguments.
virtual void display_feasible_solution(const BCP_solution *sol)
Print a feasible solution.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
virtual void create_root(BCP_vec< BCP_var * > &added_vars, BCP_vec< BCP_cut * > &added_cuts, BCP_user_data *&user_data)
Create the set of extra variables and cuts that should be added to the formulation in the root node...
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
virtual double objective_value() const =0
The method returning the objective value of the solution.
int num
Number of SOS constraints.
BCP_vec< BCP_var * > _vars
Vector of variables that are at nonzero level in the solution.
virtual void process_message(BCP_buffer &buf)
Process a message that has been sent by another process' user part to this process' user part...
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
void pack_pseudo_costs(BCP_buffer &buf)
virtual bool isInteger(int columnNumber) const
Return true if column is integer.
virtual const SosInfo * sosConstraints() const =0
void write_AMPL_solution(const BCP_solution *sol, bool write_file, bool write_screen)
auxilliary method for handling output for AMPL
char entry(const chr_params key) const
static const std::string compName
Core cuts are the cuts that always stay in the LP formulation.
Class to store sos constraints for model.
void reserve(const size_t n)
Reallocate the object to make space for n entries.
BCP_vec< double > _values
Values of these variables in the solution.
virtual int getNumCols() const
Get number of columns.
Core variables are the variables that always stay in the LP formulation.
void push_back(const_reference x)
Append x to the end of the vector.
BCP_string & assign(const char *source, const int len)
void copyOf(const CoinPackedMatrix &m, const double *OBJ, const double *CLB, const double *CUB, const double *RLB, const double *RUB)
Set up the LP relaxation by making a copy of the arguments.
void fint fint fint real fint real real real real real real real real real * e
Bonmin::Algorithm getAlgorithm()
Get the algorithm used.
int numNlpFailed_
A counter for how many times in a row did the NLP code fail.
virtual void finalize_solution(TMINLP::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, Ipopt::Number obj_value)=0
This method is called when the algorithm is complete so the TNLP can store/write the solution...
Which search tree enumeration strategy should be used.
static const char * name()
void fint fint fint * phase
virtual void init_new_phase(int phase, BCP_column_generation &colgen, CoinSearchTreeBase *&candidates)
Do whatever initialization is necessary before the phase-th phase.
Currently there isn't any error handling in BCP.
virtual void display_final_information(const BCP_lp_statistics &lp_stat)
Output the final solution.
BCP_string ipopt_file_content
const TMINLP * model() const
void display() const
Print out the statistics.
size_t size() const
Return the current number of entries.
Invoke "display_feasible_solution" user routine for the best feasible solution after the entire tree ...
bool operator()(const CoinTreeSiblings *x, const CoinTreeSiblings *y) const
virtual double objective_value() const
Return the objective value of the solution.
This class describes the message buffer used for all processes of BCP.
BCP_parameter_set< BM_par > par
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
BCP_tm_prob * getTmProblemPointer() const
Get the pointer.
OsiSolverInterface * continuousSolver()
Pointer to the continuous solver to use for relaxations.
Print statistics: running time, tree size, best solution value.
BCP_column_generation
This enumerative constant describes what to do when a search tree node becomes fathomable for the cur...
void receive_pseudo_cost_update(BCP_buffer &buf)
This class holds a MIP feasible primal solution.
virtual void readOptionsFile()
Get the options from default text file (bonmin.opt) if don't already have them.
char param(BCP_tm_par::chr_params key) const
General integer variable.
An object of type BCP_lp_relax holds the description of an lp relaxation.
OsiPseudoCosts pseudoCosts_
virtual void initialize_core(BCP_vec< BCP_var_core * > &vars, BCP_vec< BCP_cut_core * > &cuts, BCP_lp_relax *&matrix)
Pass the core constraints and core variables to bcp.
BCP_var_t
This enumerative constant describes the integrality type of a variable.
void fint fint fint real fint real * x
This is the abstract base class for a solution to a Mixed Integer Programming problem.
BCP_string nl_file_content