15 #include <CoinPackedMatrix.hpp> 16 #include <OsiSolverInterface.hpp> 20 #include <CoinTime.hpp> 22 using namespace flopc;
30 cout<<
"FlopCpp: Number of constraint blocks: " <<bm<<endl;
31 cout<<
"FlopCpp: Number of individual constraints: " <<m<<endl;
32 cout<<
"FlopCpp: Number of variable blocks: " <<bn<<endl;
33 cout<<
"FlopCpp: Number of individual variables: " <<n<<endl;
34 cout<<
"FlopCpp: Number of non-zeroes (including rhs): " <<nz<<endl;
38 cout<<
"FlopCpp: Generation time: "<<t<<endl;
42 cout<<
"FlopCpp: Constraint "<<name<<endl;
43 for (
unsigned int j=0; j<cfs.size(); j++) {
46 double elm=cfs[j].val;
47 int stage=cfs[j].stage;
48 cout<<row<<
" "<<col<<
" "<<elm<<
" "<<stage<<endl;
53 cout<<
"Objective "<<endl;
54 for (
unsigned int j=0; j<cfs.size(); j++) {
57 double elm=cfs[j].val;
58 cout<<row<<
" "<<col<<
" "<<elm<<endl;
64 m(0),
n(0),
nz(0),
bl(0),
66 MP_model::current_model =
this;
86 m += constraint->
size();
94 return Solver->getInfinity();
105 vector<MP::Coef> cfs;
110 CoinPackedVector newRow;
112 for (
unsigned int j=0; j<cfs.size(); j++) {
115 double elm=cfs[j].val;
118 newRow.insert(col,elm);
119 }
else if (col==-1) {
125 double local_bl = -rhs;
126 double local_bu = -rhs;
128 double inf =
Solver->getInfinity();
129 switch (constraint->sense) {
141 Solver->addRow(newRow,local_bl,local_bu);
152 constraint(s) = v() >= obj;
161 std::vector<MP::Coef>::const_iterator i = v.begin();
168 while (i!=v.end() && c==i->col && r==i->row) {
184 cout<<
"no solver specified"<<endl;
194 cout<<
"no solver specified"<<endl;
203 cout<<
"no solver specified"<<endl;
213 cout<<
"no solver specified"<<endl;
229 double time = CoinCpuTime();
232 vector<MP::Coef> coefs;
233 vector<MP::Coef> cfs;
235 typedef std::set<MP_variable* >::iterator
varIt;
236 typedef std::set<MP_constraint* >::iterator
conIt;
249 (*i)->coefficients(cfs);
252 cfs.erase(cfs.begin(),cfs.end());
259 Elm =
new double[
nz];
273 const double inf =
Solver->getInfinity();
275 for (
int j=0; j<
n; j++) {
281 for (
int j=0; j<=
n; j++) {
284 for (
int i=0; i<
nz; i++) {
285 int col = coefs[i].col;
292 for (
int j=0; j<=
n; j++) {
295 for (
int i=0; i<=
n; i++) {
298 for (
int i=0; i<
nz; i++) {
299 int col = coefs[i].col;
303 int row = coefs[i].row;
304 double elm = coefs[i].val;
306 Rnr[
Cst[col]+Clg[col]] = row;
311 for (
int i=0; i<
m; i++) {
315 for (
int j=
Cst[n]; j<
Cst[n+1]; j++) {
317 bu[Rnr[j]] = -
Elm[j];
321 if ((*i)->left.isDefined() && (*i)->right.isDefined() ) {
322 int begin = (*i)->offset;
323 int end = (*i)->offset+(*i)->size();
324 switch ((*i)->sense) {
326 for (
int k=begin; k<end; k++) {
331 for (
int k=begin; k<end; k++) {
345 coefs.erase(coefs.begin(),coefs.end());
351 for (
int j=0; j<
n; j++) {
354 for (
size_t i=0; i<coefs.size(); i++) {
355 int col = coefs[i].col;
356 double elm = coefs[i].val;
361 for (
int j=0; j<
n; j++) {
367 for (
int k=0; k<(*i)->size(); k++) {
368 l[(*i)->offset+k] = (*i)->lowerLimit.v[k];
369 u[(*i)->offset+k] = (*i)->upperLimit.v[k];
392 int begin = (*i)->offset;
393 int end = (*i)->offset+(*i)->size();
395 for (
int k=begin; k<end; k++) {
426 }
catch (CoinError e) {
427 cout<<e.message()<<endl;
428 cout<<
"Solving the LP relaxation instead."<<endl;
431 }
catch (CoinError e) {
432 cout<<e.message()<<endl;
438 }
catch (CoinError e) {
439 cout<<e.message()<<endl;
443 if (
Solver->isProvenOptimal() ==
true) {
444 cout<<
"FlopCpp: Optimal obj. value = "<<
Solver->getObjValue()<<endl;
445 cout<<
"FlopCpp: Solver(m, n, nz) = "<<
Solver->getNumRows()<<
" "<<
446 Solver->getNumCols()<<
" "<<
Solver->getNumElements()<<endl;
447 }
else if (
Solver->isProvenPrimalInfeasible() ==
true) {
449 cout<<
"FlopCpp: Problem is primal infeasible."<<endl;
450 }
else if (
Solver->isProvenDualInfeasible() ==
true) {
452 cout<<
"FlopCpp: Problem is dual infeasible."<<endl;
455 cout<<
"FlopCpp: Solution process abandoned."<<endl;
468 os<<
"PRIMAL_INFEASIBLE";
471 os<<
"DUAL_INFEASIBLE";
void attach(OsiSolverInterface *solver=0)
attaches the symantic representation of a model and data to a particular OsiSolverInterface ...
static void assemble(vector< MP::Coef > &v, vector< MP::Coef > &av)
MP_model & add(MP_constraint &constraint)
Adds a constrataint block to the model.
virtual void constraintDebug(string name, const vector< MP::Coef > &cfs)
virtual void constraintDebug(string name, const vector< MP::Coef > &cfs)
Symbolic representation of a linear expression.This is one of the main public interface classes...
MP_model(OsiSolverInterface *s, Messenger *m=new NormalMessenger)
Constructs an MP_model from an OsiSolverInterface *.
std::ostream & operator<<(std::ostream &os, const MP_model::MP_status &condition)
allows print of result from call to solve();
double getInfinity() const
static MP_model * getCurrentModel()
std::set< MP_constraint *>::iterator conIt
std::set< MP_variable *>::iterator varIt
Inteface for hooking up to internal flopc++ message handling.In more advanced use of FlopC++...
virtual void statistics(int bm, int m, int bn, int n, int nz)
virtual void generationTime(double t)
void setObjective(const MP_expression &o)
sets the "current objective" to the parameter o
static MP_model * current_model
void addRow(const Constraint &constraint)
Adds a constraint to the MP_model.
A solver is attached, but not yet solved.
MP_status
Reflects the state of the solution from solve()
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
virtual void statistics(int bm, int m, int bn, int n, int nz)
All flopc++ code is contained within the flopc namespace.
OsiSolverInterface * Solver
if solve is called and solver finds model primal infeasible.
MP_model::MP_status solve(const MP_model::MP_direction &dir)
set< MP_variable * > Variables
set< MP_constraint * > Constraints
static const MP_domain & getEmpty()
returns a reference to the "empty" set.
void minimize_max(MP_set &d, const MP_expression &obj)
Symantic representation of a variable.This is one of the main public interface classes. It should be directly declared by clients of the FlopC++. The parametersof construction are MP_set s which specify the indexes over which the variable is defined.
if solve is called and solver finds the model dual infeasible.
Representation of a set for indexing into some other construct.This is one of the main public interfa...
virtual void objectiveDebug(const vector< MP::Coef > &cfs)
static MP_model & default_model
static MP_model & getDefaultModel()
if the solve method is called and the optimal solution found.
virtual void objectiveDebug(const vector< MP::Coef > &cfs)
MP_direction
used when calling the solve() method.
void detach()
detaches an OsiSolverInterface object from the model. In essence, this will clean up any intermediate...
virtual void generationTime(double t)
Semantic representation of a linear constraint.This is one of the main public interface classes...