Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
143 lines (112 loc) · 4.7 KB
/
Copy pathmain.cpp
File metadata and controls
143 lines (112 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*--------------------------------------------------------------------------*/
/*----------------------------- File main.cpp ------------------------------*/
/*--------------------------------------------------------------------------*/
/** @file
* Small main() for testing SimpleMILPBlock. It just creates one and loads it
* from a stream; little more than a compilation check.
*
* \author Antonio Frangioni \n
* Dipartimento di Informatica \n
* Universita' di Pisa \n
*
* \author Enrico Gorgone \n
* Dipartimento di Matematica ed Informatica \n
* Universita' di Cagliari \n
*
* \copyright © by Antonio Frangioni
*/
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include <iostream>
#include <fstream>
#include "BlockSolverConfig.h"
/*--------------------------------------------------------------------------*/
/*-------------------------------- USING -----------------------------------*/
/*--------------------------------------------------------------------------*/
using namespace std;
using namespace SMSpp_di_unipi_it;
/*--------------------------------------------------------------------------*/
/*----------------------------- CONSTANTS ----------------------------------*/
/*--------------------------------------------------------------------------*/
const char *const logF = "log.bn";
/*--------------------------------------------------------------------------*/
/*------------------------------ FUNCTIONS ---------------------------------*/
/*--------------------------------------------------------------------------*/
/// Custom terminate function to print the exception message
void smspp_terminate( void ) {
std::cerr << "Uncaught exception in executing SMS++:\n";
try {
std::rethrow_exception( std::current_exception() );
}
catch( const std::exception & e ) {
std::cerr << "\tException type: " << typeid( e ).name() << "\n";
std::cerr << "\tException message: " << e.what() << "\n";
} catch( ... ) {
std::cerr << "\tUnknown exception" << std::endl;
}
std::abort(); // or exit(1)
}
/*--------------------------------------------------------------------------*/
/*--------------------------------- Main -----------------------------------*/
/*--------------------------------------------------------------------------*/
int main( int argc , char **argv )
{
// override the default terminate handler to print the exception message
std::set_terminate( smspp_terminate );
// reading command line parameters - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if( argc > 3 ) {
cerr << "Usage: " << argv[ 0 ]
<< " [LukFi_file_name BlockSolverConfig_file_name]" << endl;
return( 1 );
}
ifstream ProbFile( argc < 2 ? "LukFiB.txt" : argv[ 1 ] );
if( ! ProbFile.is_open() ) {
cerr << "Error: cannot open input file "
<< ( argc < 2 ? "LukFiB.txt" : argv[ 1 ] ) << endl;
return( 1 );
}
auto sLukFi = Block::new_Block( "LukFiBlock" );
ProbFile >> *sLukFi;
ProbFile.close();
cout << *sLukFi;
ProbFile.open( argc < 3 ? "BSCfg.txt" : argv[ 2 ] );
if( ! ProbFile.is_open() ) {
cerr << "Error: cannot open file " << ( argc < 3 ? "BSCfg.txt" : argv[ 2 ] )
<< endl;
return( 1 );
}
BlockSolverConfig * bsc = new BlockSolverConfig;
ProbFile >> *( bsc );
ProbFile.close();
bsc->apply( sLukFi );
bsc->clear();
// a BlockSolverConfig that attaches no Solver (e.g., one read from an
// empty or malformed file, or a "differential" one) leaves nothing to run
if( sLukFi->get_registered_solvers().empty() ) {
cerr << "Error: no Solver attached to the LukFiBlock by "
<< ( argc < 3 ? "BSCfg.txt" : argv[ 2 ] ) << endl;
delete bsc;
delete sLukFi;
return( 1 );
}
auto slvr = ( sLukFi->get_registered_solvers() ).front();
// open log-file - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ofstream LOGFile( logF , ofstream::out );
if( ! LOGFile.is_open() )
cerr << "Warning: cannot open log file """ << logF << """" << endl;
else
slvr->set_log( &LOGFile );
int rtrn = slvr->compute( false );
LOGFile << std::endl << std::endl << "f* = "
<< slvr->get_lb() << " (optimal value)" << std::endl;
bsc->apply( sLukFi );
delete bsc;
delete sLukFi;
return( 0 );
}
/*--------------------------------------------------------------------------*/
/*------------------------- End File main.cpp ------------------------------*/
/*--------------------------------------------------------------------------*/