15 #include <CoinError.hpp>
16 #include <CoinHelperFunctions.hpp>
17 #include <CoinFileIO.hpp>
18 #include <OsiClpSolverInterface.hpp>
32 int main(
int argc,
char* argv[])
34 WindowsErrorPopupBlocker();
36 return bcp_main(argc, argv, &bb_init);
53 bool found_file =
false;
54 CoinFileInput* fi = NULL;
56 OsiClpSolverInterface solver;
62 fi = CoinFileInput::create(
"bac.lp");
64 catch (CoinError& err) {
69 solver.readLp(
"bac.lp");
70 printf(
"Problem read from file bac.lp\n");
95 const int rownum = solver.getNumRows();
96 const int colnum = solver.getNumCols();
102 desc.integer =
new bool[colnum];
103 for (i = 0; i < colnum; ++i) {
104 desc.integer[i] = solver.isInteger(i);
109 desc.clb =
new double[colnum];
110 CoinDisjointCopyN(solver.getColLower(), colnum, desc.clb);
112 desc.cub =
new double[colnum];
113 CoinDisjointCopyN(solver.getColUpper(), colnum, desc.cub);
115 desc.obj =
new double[colnum];
116 CoinDisjointCopyN(solver.getObjCoefficients(), colnum, desc.obj);
118 const CoinPackedMatrix* byRow = solver.getMatrixByRow();
121 int *core_ind =
new int[core_size];
122 desc.rlb_core =
new double[core_size];
123 desc.rub_core =
new double[core_size];
125 int indexed_size = 6;
126 int *indexed_ind =
new int[indexed_size];
127 desc.rlb_indexed =
new double[indexed_size];
128 desc.rub_indexed =
new double[indexed_size];
131 for (i=0; i<core_size; i++) {
134 for (i=core_size; i<rownum; i++) {
135 indexed_ind[i-core_size] = i;
138 cout <<
"readInput(): core size: " << core_size <<
" indexed size: "
139 << indexed_size << endl;
143 const double* solver_rlb = solver.getRowLower();
144 const double* solver_rub = solver.getRowUpper();
146 for (i=0; i<core_size; ++i) {
147 desc.rlb_core[i] = solver_rlb[core_ind[i]];
148 desc.rub_core[i] = solver_rub[core_ind[i]];
151 for (i=0; i<indexed_size; ++i) {
152 desc.rlb_indexed[i] = solver_rlb[indexed_ind[i]];
153 desc.rub_indexed[i] = solver_rub[indexed_ind[i]];
159 desc.core =
new CoinPackedMatrix(
false, 0.0, 0.0);
160 desc.core->submatrixOf(*byRow, core_size, core_ind);
162 desc.indexed =
new CoinPackedMatrix(
false, 0.0, 0.0);
163 desc.indexed->submatrixOf(*byRow, indexed_size, indexed_ind);
166 delete[] indexed_ind;
170 printf(
"Problem created in memory\n");
173 int colnum = desc.colnum;
176 desc.obj =
new double[colnum];
177 desc.clb =
new double[colnum];
178 desc.cub =
new double[colnum];
179 desc.integer =
new bool[colnum];
181 for(i=0; i<colnum; i++) {
185 desc.integer[i] =
true;
188 desc.core =
new CoinPackedMatrix(
false, 0.0, 0.0);
189 desc.rlb_core =
new double[10];
190 desc.rub_core =
new double[10];
192 double* cutcoef =
new double[colnum];
193 int *cutind =
new int[colnum];
202 for(i=0; i<10; i++) {
203 desc.rlb_core[i] = 0;
204 desc.rub_core[i] = 1;
208 desc.core->appendRow(cutnz, cutind, cutcoef);
210 desc.rlb_core[0] = 1;
212 desc.indexed =
new CoinPackedMatrix(
false, 0.0, 0.0);
213 desc.rlb_indexed =
new double[6];
214 desc.rub_indexed =
new double[6];
220 desc.rub_indexed[i] = 1;
231 desc.indexed->appendRow(cutnz, cutind, cutcoef);
235 desc.indexed->appendRow(cutnz, cutind, cutcoef);
239 desc.indexed->appendRow(cutnz, cutind, cutcoef);
243 desc.indexed->appendRow(cutnz, cutind, cutcoef);
247 desc.indexed->appendRow(cutnz, cutind, cutcoef);
251 desc.indexed->appendRow(cutnz, cutind, cutcoef);
288 for (i=0; i<desc.colnum; ++i) {
289 if (desc.integer[i]) {
290 if (desc.clb[i] == 0.0 && desc.cub[i] == 1.0) {
295 desc.clb[i], desc.cub[i]));
300 desc.clb[i], desc.cub[i]));
304 const int corerows = desc.core->getNumRows();
305 for (i=0; i<corerows; ++i) {
311 matrix->
copyOf(*desc.core, desc.obj, desc.clb, desc.cub,
312 desc.rlb_core, desc.rub_core);
337 const int colnum = desc.colnum;
338 double* sol =
new double[colnum];
340 CoinFillN(sol, colnum, 0.0);
343 for (i=0; i<size; ++i) {
347 cout <<
"Customized display of the feasible solution:" << endl << endl;
348 cout.setf(ios::fixed);
351 for(i=0; i<colnum; i++) {
352 cout << sol[i] <<
" ";
361 cout <<
"Default BCP display of the feasible solution:" << endl << endl;
virtual void display_feasible_solution(const BCP_solution *sol)
Display a feasible solution.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
BCP_vec< BCP_var * > _vars
Vector of variables that are at nonzero level in the solution.
int main(int argc, char *argv[])
BCP_process_t
This enumerative constant describes the various process types.
Core cuts are the cuts that always stay in the LP formulation.
BCP_vec< double > _values
Values of these variables in the solution.
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.
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.
int bcp_main(int argc, char *argv[], USER_initialize *user_init)
This is the function the user must invoke when (s)he is ready to turn contrl over to BCP...
virtual void display_feasible_solution(const BCP_solution *sol)
Print a feasible solution.
Class taking care of interaction between user data and Bcp.
void readInput(const char *filename)
Read input and set up data in class BB_prob.
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.
size_t size() const
Return the current number of entries.
This class describes the message buffer used for all processes of BCP.
virtual void create_root(BCP_vec< BCP_var * > &added_vars, BCP_vec< BCP_cut * > &added_cuts, BCP_user_data *&user_data)
Create the root node of the enumeration.
virtual void pack_module_data(BCP_buffer &buf, BCP_process_t ptype)
Pack data into a buffer; will not work in parallel environment as it uses pointer.
This class holds a MIP feasible primal solution.
General integer variable.
An object of type BCP_lp_relax holds the description of an lp relaxation.
This is the abstract base class for a solution to a Mixed Integer Programming problem.