OSDip_Main.cpp
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the Decomp Solver Framework. //
3 // //
4 // Decomp is distributed under the Common Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Author: Matthew Galati, Lehigh University
8 // Modified by Kipp Martin
9 //
10 // //
11 // Copyright (C) 2002-2009, Lehigh University, Matthew Galati, and Ted Ralphs//
12 // All Rights Reserved. //
13 //===========================================================================//
14 
15 //===========================================================================//
16 #include "UtilParameters.h"
17 //===========================================================================//
18 #include "OSDipApp.h"
19 //===========================================================================//
20 #include "AlpsDecompModel.h"
21 //===========================================================================//
22 #include "DecompAlgoC.h"
23 #include "DecompAlgoPC.h"
24 #include "DecompAlgoRC.h"
25 //===========================================================================//
26 #include "UtilTimer.h"
27 #include<map>
28 
29 //===========================================================================//
30 int main(int argc, char ** argv){
31  try{
32 
33  //---
34  //--- create the utility class for parsing parameters
35  //---
36  UtilParameters utilParam(argc, argv);
37 
38  bool doCut = utilParam.GetSetting("doCut", false);
39  bool doPriceCut = utilParam.GetSetting("doPriceCut", true);
40  bool doDirect = utilParam.GetSetting("doDirect", false);
41 
42 
43  UtilTimer timer;
44  double timeSetupReal = 0.0;
45  double timeSetupCpu = 0.0;
46  double timeSolveReal = 0.0;
47  double timeSolveCpu = 0.0;
48 
49  //---
50  //--- start overall timer
51  //---
52  timer.start();
53 
54  //---
55  //--- create the user application (a DecompApp)
56  //---
57 
58  OSDipApp osdip( utilParam);
59 
60  //return 0;
61 
62 
63  //---
64  //--- create the algorithm (a DecompAlgo)
65  //---
66  DecompAlgo *algo = NULL;
67  assert(doCut + doPriceCut == 1);
68 
69  //---
70  //--- create the CPM algorithm object
71  //---
72  if(doCut)
73  algo = new DecompAlgoC(&osdip, &utilParam);
74 
75  //---
76  //--- create the PC algorithm object
77  //---
78  if(doPriceCut){
79  std::cout << "CREATE NEW DecompAlgoPC" << std::endl;
80  algo = new DecompAlgoPC(&osdip, &utilParam);
81  std::cout << "DONE CREATE NEW DecompAlgoPC" << std::endl;
82  //delete algo;
83  //return 0;
84 
85  }
86 
87  if(doCut && doDirect){
88  timer.stop();
89  timeSetupCpu = timer.getCpuTime();
90  timeSetupReal = timer.getRealTime();
91 
92  //---
93  //--- solve
94  //---
95  timer.start();
96  // algo->solveDirect(timeLimit);
97  algo->solveDirect();
98  timer.stop();
99  timeSolveCpu = timer.getCpuTime();
100  timeSolveReal = timer.getRealTime();
101  }
102  else{
103  timer.stop();
104  timeSetupCpu = timer.getCpuTime();
105  timeSetupReal = timer.getRealTime();
106 
107  //---
108  //--- create the driver AlpsDecomp model
109  //---
110  int status = 0;
111  AlpsDecompModel alpsModel(utilParam, algo);
112 
113  //---
114  //--- solve
115  //---
116  timer.start();
117  std::cout << std::endl << std::endl << std::endl << std::endl;
118  std::cout << "***************START SOLVE***************" << std::endl;
119 
120 
121 
122  status = alpsModel.solve();
123  std::cout << "FINISH SOLVE" << std::endl;
124  timer.stop();
125  timeSolveCpu = timer.getCpuTime();
126  timeSolveReal = timer.getRealTime();
127 
128  //---
129  //--- sanity check
130  //---
131  //cout << setiosflags(std::ios::fixedl std::ios::showpoint);
132  std::cout << "Status= " << status
133  << " BestLB= " << std::setw(10)
134  << UtilDblToStr(alpsModel.getGlobalLB(),5)
135  << " BestUB= " << std::setw(10)
136  << UtilDblToStr(alpsModel.getGlobalUB(),5)
137  << " Nodes= " << std::setw(6)
138  << alpsModel.getNumNodesProcessed()
139  << " SetupCPU= " << timeSetupCpu
140  << " SolveCPU= " << timeSolveCpu
141  << " TotalCPU= " << timeSetupCpu + timeSolveCpu
142  << " SetupReal= " << timeSetupReal
143  << " SetupReal= " << timeSolveReal
144  << " TotalReal= " << timeSetupReal + timeSetupReal
145  << std::endl;
146 
147 
148  const DecompSolution * solution = alpsModel.getBestSolution();
149  std::cout << "Optimal Solution" << std::endl;
150  solution->print();
151  //print final solution
152  algo->getMasterOSI()->writeLp("finalRestrictedMaster", "lp", 1e-30, 5, 10);
153 
154  }
155  //---
156  //--- free local memory
157  //---
158  delete algo;
159 
160  }
161  catch(const ErrorClass& eclass){
162  std::cout << "Something went wrong:" << std::endl;
163  std::cout << eclass.errormsg << std::endl;
164 
165  return 1;
166  }
167  std::cout << "Program terminates normally" << std::endl;
168  return 0;
169 }
170 
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Definition: OSErrorClass.h:42
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
void fint fint fint real fint real real real real real real real real real * e
used for throwing exceptions.
Definition: OSErrorClass.h:31