source: trunk/Couenne/src/main/BonCouenne.cpp @ 12

Last change on this file since 12 was 12, checked in by pbelotti, 12 years ago

fix compilation error

File size: 4.8 KB
Line 
1// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2007
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// Pietro Belotti, Carnegie Mellon University,
7// Pierre Bonami, International Business Machines Corporation
8//
9// Date : 12/19/2006
10
11
12#if defined(_MSC_VER)
13// Turn off compiler warning about long names
14#  pragma warning(disable:4786)
15#endif
16#include <iomanip>
17#include <fstream>
18
19#include <stdlib.h>
20
21#include "CoinTime.hpp"
22#include "BonminConfig.h"
23#include "BonCouenneInterface.hpp"
24#include "BonIpoptSolver.hpp"
25
26#include "BonCouenneSetup.hpp"
27
28#include "BonCbc.hpp"
29#ifdef COIN_HAS_FILTERSQP
30#include "BonFilterSolver.hpp"
31#endif
32
33#include "CbcCutGenerator.hpp"
34#include "CouenneProblem.hpp"
35#include "CouenneCutGenerator.hpp"
36
37using namespace Bonmin;
38
39int main (int argc, char *argv[])
40{
41  using namespace Ipopt;
42
43  char * pbName = NULL;
44  double time_start = CoinCpuTime();
45
46  const int infeasible = 1;
47
48  try {
49
50    Bab bb;
51    bb.setUsingCouenne (true);
52
53    CouenneSetup bonmin;
54    if (!bonmin.InitializeCouenne (argv))
55      throw infeasible;
56
57#if 0
58    CouenneFeasibility feasibility;
59    bb.model().setProblemFeasibility (feasibility);
60#endif
61
62    /// update time limit (read/preprocessing might have taken some)
63    double timeLimit = 0;
64    bonmin.options () -> GetNumericValue ("time_limit", timeLimit, "bonmin.");
65    bonmin.setDoubleParameter (BabSetupBase::MaxTime, 
66                               timeLimit - (time_start = (CoinCpuTime () - time_start)));
67
68    //////////////////////////////////
69
70    bb (bonmin); // do branch and bound
71
72    //////////////////////////////////
73
74    std::cout.precision (10);
75
76    //////////////////////////////
77    CouenneCutGenerator *cg = NULL;
78
79    if (bb.model (). cutGenerators ())
80      cg = dynamic_cast <CouenneCutGenerator *> 
81        (bb.model (). cutGenerators () [0] -> generator ());
82
83    ////////////////////////////////
84    int nr=-1, nt=-1;
85    double st=-1;
86
87    if (cg) cg -> getStats (nr, nt, st);
88    else printf ("Warning, could not get pointer to CouenneCutGenerator\n");
89
90    CouenneProblem *cp = cg ? cg -> Problem () : NULL;
91
92    // retrieve test value to check
93    double global_opt;
94    bonmin.options () -> GetNumericValue ("couenne_check", global_opt, "couenne.");
95
96    if (global_opt < COUENNE_INFINITY) { // some value found in couenne.opt
97
98      double opt = bb.model (). getBestPossibleObjValue ();
99
100      printf ("Test on %-40s: %s\n", cp ? cp -> problemName ().c_str () : "unknown", 
101              (fabs (opt - global_opt) / 
102               (1. + CoinMax (fabs (opt), fabs (global_opt))) < COUENNE_EPS) ? 
103              (char *) "OK", (char *) "FAILED");
104
105    } else // good old statistics
106
107    if (bonmin.displayStats ()) { // print statistics
108
109      // CAUTION: assuming first cut generator is our CouenneCutGenerator
110
111      if (cg && !cp) printf ("Warning, could not get pointer to problem\n");
112      else
113        printf ("Stats: %-15s %4d [var] %4d [int] %4d [con] %4d [aux] "
114                "%6d [root] %8d [tot] %6g [sep] %8g [time] %8g [bb] "
115                "%20e [lower] %20e [upper] %7d [nodes]\n",// %s %s\n",
116                cp ? cp -> problemName ().c_str () : "unknown",
117                (cp) ? cp -> nOrigVars     () : -1, 
118                (cp) ? cp -> nOrigIntVars  () : -1, 
119                (cp) ? cp -> nOrigCons     () : -1,
120                (cp) ? (cp -> nVars     () - 
121                        cp -> nOrigVars ()): -1,
122                nr, nt, st, 
123                CoinCpuTime () - time_start,
124                cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
125                bb.model (). getBestPossibleObjValue (),
126                bb.model (). getObjValue (),
127                //bb.bestBound (),
128                //bb.bestObj (),
129                bb.numNodes ());
130                //bb.iterationCount ());
131                //status.c_str (), message.c_str ());
132    }
133
134//    nlp_and_solver -> writeAmplSolFile (message, bb.bestSolution (), NULL);
135  }
136  catch(TNLPSolver::UnsolvedError *E) {
137     E->writeDiffFiles();
138     E->printError(std::cerr);
139    //There has been a failure to solve a problem with Ipopt.
140    //And we will output file with information on what has been changed in the problem to make it fail.
141    //Now depending on what algorithm has been called (B-BB or other) the failed problem may be at different place.
142    //    const OsiSolverInterface &si1 = (algo > 0) ? nlpSolver : *model.solver();
143  }
144  catch(OsiTMINLPInterface::SimpleError &E) {
145    std::cerr<<E.className()<<"::"<<E.methodName()
146             <<std::endl
147             <<E.message()<<std::endl;
148  }
149  catch(CoinError &E) {
150    std::cerr<<E.className()<<"::"<<E.methodName()
151             <<std::endl
152             <<E.message()<<std::endl;
153  }
154  catch (Ipopt::OPTION_INVALID &E)
155  {
156   std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
157  }
158  catch (int generic_error) {
159    if (generic_error == infeasible)
160      printf ("problem infeasible\n");
161  }
162
163//  catch(...) {
164//    std::cerr<<pbName<<" unrecognized excpetion"<<std::endl;
165//    std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
166//    throw;
167//  }
168
169  delete [] pbName;
170  return 0;
171}
Note: See TracBrowser for help on using the repository browser.