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

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

improved output level (unified output level). Undoing a change by Jim that triggers a compilation error (Compute_Symmetry() is already executed within setupSymmetry()). Changed Find_Orbit to avoid copying std::vector. Cut some symmetry output.

  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1// $Id: BonCouenne.cpp 424 2010-10-18 20:20:06Z pbelotti $
2//
3// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2007
4// All Rights Reserved.
5// This code is published under the Common Public License.
6//
7// Authors :
8// Pietro Belotti, Carnegie Mellon University,
9// Pierre Bonami, International Business Machines Corporation
10//
11// Date : 12/19/2006
12
13
14#if defined(_MSC_VER)
15// Turn off compiler warning about long names
16#  pragma warning(disable:4786)
17#endif
18#include <iomanip>
19#include <fstream>
20
21#include <stdlib.h>
22
23#include "CoinTime.hpp"
24#include "CoinError.hpp"
25#include "BonCouenneInterface.hpp"
26
27#include "BonCouenneSetup.hpp"
28
29#include "BonCbc.hpp"
30#ifdef COIN_HAS_FILTERSQP
31#include "BonFilterSolver.hpp"
32#endif
33
34#include "CbcCutGenerator.hpp"
35#include "CouenneProblem.hpp"
36#include "CouenneCutGenerator.hpp"
37
38using namespace Couenne;
39
40// the maximum difference between a printed optimum and a CouNumber
41#define PRINTED_PRECISION 1e-5
42
43#include "CouenneExprVar.hpp"
44#include "CouenneExprConst.hpp"
45#include "CouenneExprSum.hpp"
46#include "CouenneExprClone.hpp"
47#include "CouenneProblemElem.hpp"
48#include "CouenneProblem.hpp"
49#include "CouenneJournalist.hpp"
50
51#include "config_couenne.h"
52
53int main (int argc, char *argv[]) {
54
55  //WindowsErrorPopupBlocker();
56  using namespace Ipopt;
57
58  char * pbName = NULL;
59
60  const int infeasible = 1;
61
62  try {
63
64    Bonmin::Bab bb;
65    bb.setUsingCouenne (true);
66
67    CouenneProblem *p = NULL;
68    CouenneInterface *ci = NULL;
69
70#if 0
71    //ci = new CouenneInterface;
72    p = new CouenneProblem;
73
74    p -> addVariable (false, p -> domain ());
75    p -> addVariable (false, p -> domain ());
76    p -> addVariable (false, p -> domain ());
77    p -> addVariable (false, p -> domain ());
78
79    p -> addObjective    (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))), "min");
80    p -> addLEConstraint (new exprSum (new exprClone (p->Var (0)), new exprClone (p->Var (2))),
81                          new exprConst (1));
82    p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))),
83                          new exprConst (1));
84    p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (3))),
85                          new exprConst (1));
86    p -> addEQConstraint (new exprSum (new exprClone (p->Var (2)), new exprClone (p->Var (3))),
87                          new exprConst (1));
88#endif
89
90    CouenneSetup couenne;
91    if (!couenne.InitializeCouenne (argv, p, NULL, ci, &bb))
92      throw infeasible;
93
94    // initial printout
95
96    ConstJnlstPtr jnlst = couenne. couennePtr () -> Jnlst ();
97
98    jnlst -> Printf (J_INSUPPRESSIBLE, J_COUENNE, "Couenne %s --  an Open-Source exact solver for MINLP\n", strcmp (PACKAGE_VERSION, "trunk") ? PACKAGE_VERSION : "");
99
100    jnlst -> Printf (J_ERROR, J_COUENNE, "\
101Mailing list: %s\n\
102Instructions: http://www.coin-or.org/Couenne\n",
103            PACKAGE_BUGREPORT);
104
105    CouenneProblem *prob = couenne. couennePtr () -> Problem ();
106
107    jnlst -> Printf (J_ERROR, J_COUENNE, "\n\
108Loaded instance \"%s\"\n\
109Variables:       %8d (%d integer)\n\
110Constraints:     %8d\n\
111Auxiliaries:     %8d\n\n",
112                     prob -> problemName ().c_str (),
113                     prob -> nOrigVars (),
114                     prob -> nOrigIntVars (),
115                     prob -> nOrigCons (),
116                     prob -> nVars () - prob -> nOrigVars ());
117
118    double time_start = CoinCpuTime();
119
120#if 0
121    CouenneFeasibility feasibility;
122    bb.model().setProblemFeasibility (feasibility);
123#endif
124
125    /// update time limit (read/preprocessing might have taken some)
126    double timeLimit = 0;
127    couenne.options () -> GetNumericValue ("time_limit", timeLimit, "couenne.");
128    couenne.setDoubleParameter (Bonmin::BabSetupBase::MaxTime, 
129                                CoinMax (0., timeLimit - time_start));
130
131    //////////////////////////////////
132
133    jnlst -> Printf (J_ERROR, J_COUENNE, "Starting branch-and-bound\n");
134    bb (couenne); // do branch and bound
135
136    //////////////////////////////////
137
138    std::cout.precision (10);
139
140    //////////////////////////////
141    CouenneCutGenerator *cg = NULL;
142
143    // there is only one cut generator, so scan array until
144    // dynamic_cast returns non-NULL
145
146    if (bb.model (). cutGenerators ()) {
147
148      int nGen = bb.model (). numberCutGenerators ();
149     
150      for (int i=0; !cg && i < nGen; i++)
151        cg = dynamic_cast <CouenneCutGenerator *> 
152          (bb.model (). cutGenerators () [i] -> generator ());
153    }
154
155    ////////////////////////////////
156    int nr=-1, nt=-1;
157    double st=-1;
158
159    if (cg) cg -> getStats (nr, nt, st);
160    else printf ("Warning, could not get pointer to CouenneCutGenerator\n");
161
162    CouenneProblem *cp = cg ? cg -> Problem () : NULL;
163
164    // retrieve test value to check
165    double global_opt;
166    couenne.options () -> GetNumericValue ("couenne_check", global_opt, "couenne.");
167
168    jnlst -> Printf (J_ERROR, J_COUENNE, "\n\
169Linearization cuts added at root node:   %8d\n\
170Linearization cuts added in total        %8d  (separation time: %gs)\n\
171Total solving time:                      %8gs (%gs in branch-and-bound)\n\
172Lower bound:                           %10g\n\
173Upper bound:                           %10g  (gap: %.2f%%)\n\
174Branch-and-bound nodes:                  %8d\n\n",
175                     nr, nt, st, 
176                     CoinCpuTime () - time_start,
177                     cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
178                     bb.model (). getBestPossibleObjValue (),
179                     bb.model (). getObjValue (),
180                     100. * (bb.model (). getObjValue () -
181                             bb.model (). getBestPossibleObjValue ()) / (1. + fabs (bb.model (). getBestPossibleObjValue ())),
182                     bb.numNodes ());
183
184    if (global_opt < COUENNE_INFINITY) { // some value found in couenne.opt
185
186      double opt = bb.model (). getBestPossibleObjValue ();
187
188      printf ("Global Optimum Test on %-40s %s\n", 
189              cp ? cp -> problemName ().c_str () : "unknown", 
190              (fabs (opt - global_opt) / 
191               (1. + CoinMax (fabs (opt), fabs (global_opt))) < PRINTED_PRECISION) ? 
192              (const char *) "OK" : (const char *) "FAILED");
193              //opt, global_opt,
194              //fabs (opt - global_opt));
195
196    } else // good old statistics
197
198    if (couenne.displayStats ()) { // print statistics
199
200      // CAUTION: assuming first cut generator is our CouenneCutGenerator
201
202      if (cg && !cp) printf ("Warning, could not get pointer to problem\n");
203      else
204        printf ("Stats: %-15s %4d [var] %4d [int] %4d [con] %4d [aux] "
205                "%6d [root] %8d [tot] %6g [sep] %8g [time] %8g [bb] "
206                "%20e [lower] %20e [upper] %7d [nodes]\n",// %s %s\n",
207                cp ? cp -> problemName (). c_str () : "unknown",
208                (cp) ? cp -> nOrigVars     () : -1, 
209                (cp) ? cp -> nOrigIntVars  () : -1, 
210                (cp) ? cp -> nOrigCons     () : -1,
211                (cp) ? (cp -> nVars     () - 
212                        cp -> nOrigVars ()): -1,
213                nr, nt, st, 
214                CoinCpuTime () - time_start,
215                cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
216                bb.model (). getBestPossibleObjValue (),
217                bb.model (). getObjValue (),
218                //bb.bestBound (),
219                //bb.bestObj (),
220                bb.numNodes ());
221                //bb.iterationCount ());
222                //status.c_str (), message.c_str ());
223    }
224
225//    nlp_and_solver -> writeAmplSolFile (message, bb.bestSolution (), NULL);
226  }
227  catch(Bonmin::TNLPSolver::UnsolvedError *E) {
228     E->writeDiffFiles();
229     E->printError(std::cerr);
230    //There has been a failure to solve a problem with Ipopt.
231    //And we will output file with information on what has been changed in the problem to make it fail.
232    //Now depending on what algorithm has been called (B-BB or other) the failed problem may be at different place.
233    //    const OsiSolverInterface &si1 = (algo > 0) ? nlpSolver : *model.solver();
234  }
235  catch (Bonmin::OsiTMINLPInterface::SimpleError &E) {
236    std::cerr<<E.className()<<"::"<<E.methodName()
237             <<std::endl
238             <<E.message()<<std::endl;
239  }
240  catch (CoinError &E) {
241    std::cerr<<E.className()<<"::"<<E.methodName()
242             <<std::endl
243             <<E.message()<<std::endl;
244  }
245  catch (Ipopt::OPTION_INVALID &E)
246  {
247   std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
248  }
249  catch (int generic_error) {
250    if (generic_error == infeasible)
251      printf ("problem infeasible\n");
252  }
253
254//  catch(...) {
255//    std::cerr<<pbName<<" unrecognized excpetion"<<std::endl;
256//    std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
257//    throw;
258//  }
259
260  delete [] pbName;
261  return 0;
262}
Note: See TracBrowser for help on using the repository browser.