CouTight.cpp
Go to the documentation of this file.
1 /* $Id: CouTight.cpp 530 2011-03-12 16:52:06Z pbelotti $ */
2 /*
3  * Name: CouTight.cpp
4  * Authors: Leo Liberti, LIX, Ecole Polytechnique.
5  * Pietro Belotti, Carnegie Mellon University
6  * Purpose: Just applies bound tightening to a problem and saves new bounds as AMPL suffixed fields
7  *
8  * (C) Carnegie-Mellon University, 2008.
9  * This file is licensed under the Eclipse Public License (EPL)
10  */
11 
12 
13 #if defined(_MSC_VER)
14 // Turn off compiler warning about long names
15 # pragma warning(disable:4786)
16 #endif
17 #include <iomanip>
18 #include <fstream>
19 
20 #include <stdlib.h>
21 
22 #include "CoinTime.hpp"
23 #include "CoinError.hpp"
24 //#include "BonminConfig.h"
25 #include "BonCouenneInterface.hpp"
26 #include "BonIpoptSolver.hpp"
27 
28 #include "CoinHelperFunctions.hpp"
29 #include "BonCouenneSetup.hpp"
30 
31 #include "BonCbc.hpp"
32 
33 #include "CbcCutGenerator.hpp"
34 #include "CouenneProblem.hpp"
35 #include "CouenneCutGenerator.hpp"
36 
37 #include "asl.h"
38 #include "nlp.h"
39 #include "getstub.h"
40 #include "r_opn.hd" // for N_OPS
41 #include "opcode.hd"
42 
43 using namespace Couenne;
44 
45 static int empty_int = 0;
46 
47 static keyword keywds[] = { /* must be sorted */
48  KW(const_cast<char*>("empty"),
49  I_val,
50  empty_int,
51  const_cast<char*>("nothing")),
52 };
53 
54 extern Option_Info Oinfo;
55 
56 using namespace Bonmin;
57 
58 
60 int main (int argc, char *argv[]) {
61  WindowsErrorPopupBlocker();
62  using namespace Ipopt;
63 
64  Bonmin::Bab bb;
65  bb.setUsingCouenne (true);
66 
67  CouenneSetup bonmin;
68  bonmin.InitializeCouenne (argv);
69 
70  SmartAsl *aslfg = new SmartAsl;
71  aslfg -> asl = readASLfg (argv);
72 
73  int NumberOfVariables = bonmin.couennePtr () -> Problem () -> nOrigVars ();
74 
75  typedef struct {char *msg; int code, wantsol;} Sol_info;
76 
77  static SufDecl suftab [] = {
78  {const_cast<char*>("newlb"), 0,
79  ASL_Sufkind_var | ASL_Sufkind_real | ASL_Sufkind_output, 0},
80  {const_cast<char*>("newub"), 0,
81  ASL_Sufkind_var | ASL_Sufkind_real | ASL_Sufkind_output, 0}};
82 
83  suf_declare_ASL (aslfg -> asl, suftab, sizeof (suftab) / sizeof (SufDecl));
84 
85  // add an AMPL suffix
86  SufDesc* vnewLb = suf_get_ASL(aslfg -> asl, "newlb", ASL_Sufkind_var);
87  SufDesc* vnewUb = suf_get_ASL(aslfg -> asl, "newub", ASL_Sufkind_var);
88 
89  vnewLb -> u.r = (real*)M1zapalloc_ASL(&aslfg -> asl->i, NumberOfVariables * sizeof(real));
90  vnewUb -> u.r = (real*)M1zapalloc_ASL(&aslfg -> asl->i, NumberOfVariables * sizeof(real));
91 
92  const double
93  *newL = bonmin.couennePtr () -> Problem () -> Lb (),
94  *newU = bonmin.couennePtr () -> Problem () -> Ub ();
95 
96  //printf ("New bounds:");
97  //for (int i=0; i<bonmin.couennePtr () -> Problem () -> nVars(); i++)
98  // printf ("x_%05d %e %e\n", i, newL [i], newU [i]);
99 
100  // return variable integrality
101  for(int i = 0; i < NumberOfVariables; i++) {
102  vnewLb->u.r[i] = newL [i];
103  vnewUb->u.r[i] = newU [i];
104  }
105 
106  write_sol_ASL (aslfg -> asl, const_cast<char*>("tightened bounds"), 0, 0, &Oinfo);
107  return 0;
108 }
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
ASL * readASLfg(char **argv)
Definition: readASLfg.cpp:27
static int empty_int
Definition: CouTight.cpp:45
Option_Info Oinfo
Definition: readASLfg.cpp:24
Bonmin::BqpdSolver::real real
bool InitializeCouenne(char **argv=NULL, CouenneProblem *couenneProb=NULL, Ipopt::SmartPtr< Bonmin::TMINLP > tminlp=NULL, CouenneInterface *ci=NULL, Bonmin::Bab *bb=NULL)
Initialize from command line arguments.
static keyword keywds[]
Definition: CouTight.cpp:47