| 1 |
// (C) Copyright CNRS and others 2010 |
| 2 |
// All Rights Reserved. |
| 3 |
// This code is published under the Eclipse Public License. |
| 4 |
// |
| 5 |
// Authors : |
| 6 |
// Pierre Bonami, Université de la Méditérannée |
| 7 |
// Hassan Hijazi, Orange Labs |
| 8 |
// |
| 9 |
// Date : 05/22/2010 |
| 10 |
|
| 11 |
#include "BonminConfig.h" |
| 12 |
#include "OsiClpSolverInterface.hpp" |
| 13 |
|
| 14 |
#include "SepaSetup.hpp" |
| 15 |
#include "SepaTMINLP2OsiLP.hpp" |
| 16 |
#include "SepaHeuristicInnerApproximation.hpp" |
| 17 |
#include "BonOuterDescription.hpp" |
| 18 |
|
| 19 |
namespace Sepa |
| 20 |
{ |
| 21 |
SepaSetup::SepaSetup(const CoinMessageHandler * handler):BonminSetup(handler) |
| 22 |
{ |
| 23 |
} |
| 24 |
|
| 25 |
SepaSetup::SepaSetup(const SepaSetup &other):BonminSetup(other) |
| 26 |
{} |
| 27 |
|
| 28 |
SepaSetup::SepaSetup(const SepaSetup &other, |
| 29 |
Bonmin::OsiTMINLPInterface &nlp): |
| 30 |
BonminSetup(other, nlp) |
| 31 |
{ |
| 32 |
} |
| 33 |
|
| 34 |
SepaSetup::SepaSetup(const SepaSetup &other, |
| 35 |
Bonmin::OsiTMINLPInterface &nlp, |
| 36 |
const std::string &prefix): |
| 37 |
BonminSetup(other, nlp, prefix) |
| 38 |
{ |
| 39 |
Bonmin::Algorithm algo = getAlgorithm(); |
| 40 |
if (algo == Bonmin::B_OA) |
| 41 |
initializeSepa(); |
| 42 |
} |
| 43 |
|
| 44 |
void SepaSetup::registerAllOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions) |
| 45 |
{ |
| 46 |
Bonmin::BonminSetup::registerAllOptions(roptions); |
| 47 |
|
| 48 |
Sepa::HeuristicInnerApproximation::registerOptions(roptions); |
| 49 |
|
| 50 |
roptions->SetRegisteringCategory("Initial Approximations descriptions", Bonmin::RegisteredOptions::UndocumentedCategory); |
| 51 |
roptions->AddStringOption2("initial_outer_description", |
| 52 |
"Do we add all Outer Approximation constraints defining the initial Outer Approximation " |
| 53 |
"description of the MINLP. See the number_approximations_initial_outer option for fixing the " |
| 54 |
"number of approximation points", |
| 55 |
"yes", "no","Do not generate the description", "yes","Generate the description", |
| 56 |
""); |
| 57 |
|
| 58 |
roptions->AddUpperBoundedIntegerOption("number_approximations_initial_outer", |
| 59 |
"Number of Outer Approximation points needed for generating the initial Outer Approximation description, maximum value = 500, default value = 50", |
| 60 |
500, 50, ""); |
| 61 |
} |
| 62 |
|
| 63 |
/** Register all the Bonmin options.*/ |
| 64 |
void |
| 65 |
SepaSetup::registerOptions() |
| 66 |
{ |
| 67 |
registerAllOptions(roptions_); |
| 68 |
} |
| 69 |
|
| 70 |
/** Initialize, read options and create appropriate bonmin setup using initialized tminlp.*/ |
| 71 |
void |
| 72 |
SepaSetup::initialize(Ipopt::SmartPtr<Bonmin::TMINLP> tminlp, bool createContinuousSolver /*= false*/) |
| 73 |
{ |
| 74 |
|
| 75 |
int do_outer; |
| 76 |
int n_approx; |
| 77 |
options()->GetEnumValue("initial_outer_description", do_outer, prefix_.c_str()); |
| 78 |
options()->GetIntegerValue("number_approximations_initial_outer", |
| 79 |
n_approx, prefix_.c_str()); |
| 80 |
SepaTMINLP2OsiLP* linearizer = new SepaTMINLP2OsiLP; |
| 81 |
linearizer_ = linearizer; |
| 82 |
if(do_outer) |
| 83 |
linearizer->set_num_approx(n_approx); |
| 84 |
|
| 85 |
Bonmin::BonminSetup::initialize(tminlp, createContinuousSolver); |
| 86 |
|
| 87 |
if (getAlgorithm() == Bonmin::B_OA) |
| 88 |
initializeSepa(); |
| 89 |
} |
| 90 |
|
| 91 |
/** Initialize, read options and create appropriate bonmin setup using initialized tminlp.*/ |
| 92 |
void |
| 93 |
SepaSetup::initialize(const Bonmin::OsiTMINLPInterface &nlpSi, bool createContinuousSolver /*= false*/) |
| 94 |
{ |
| 95 |
int do_outer; |
| 96 |
int n_approx; |
| 97 |
options()->GetEnumValue("initial_outer_description", do_outer, prefix_.c_str()); |
| 98 |
options()->GetIntegerValue("number_approximations_initial_outer", |
| 99 |
n_approx, prefix_.c_str()); |
| 100 |
SepaTMINLP2OsiLP* linearizer = new SepaTMINLP2OsiLP; |
| 101 |
linearizer_ = linearizer; |
| 102 |
if(do_outer) |
| 103 |
linearizer->set_num_approx(n_approx); |
| 104 |
|
| 105 |
BonminSetup::initialize(nlpSi, createContinuousSolver); |
| 106 |
if (getAlgorithm() == Bonmin::B_OA) |
| 107 |
initializeSepa(); |
| 108 |
} |
| 109 |
|
| 110 |
void SepaSetup::initializeSepa() |
| 111 |
{ |
| 112 |
|
| 113 |
|
| 114 |
int doOuter; |
| 115 |
int nbAp = 10; |
| 116 |
options()->GetEnumValue("initial_outer_description", doOuter, prefix_.c_str()); |
| 117 |
options()->GetIntegerValue("number_approximations_initial_outer", |
| 118 |
nbAp, prefix_.c_str()); |
| 119 |
|
| 120 |
#ifdef USE_OLD_FUNC |
| 121 |
if(doOuter) |
| 122 |
addOuterDescription(*nonlinearSolver(), *continuousSolver(), nonlinearSolver()->getColSolution(), nbAp, false); |
| 123 |
#endif |
| 124 |
|
| 125 |
int doInner; |
| 126 |
|
| 127 |
options()->GetEnumValue("heuristic_inner_approximation", doInner, prefix_.c_str()); |
| 128 |
if(doInner){ |
| 129 |
Sepa::HeuristicInnerApproximation * inner = new Sepa::HeuristicInnerApproximation(this); |
| 130 |
HeuristicMethod h; |
| 131 |
h.heuristic = inner; |
| 132 |
h.id = "InnerApproximation"; |
| 133 |
heuristics_.push_back(h); |
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
}/* end namespace Bonmin*/ |
| 139 |
|