00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "bande.hh"
00028
00029 namespace bande {
00030
00031
00032
00033
00034 Settings::Settings()
00035 : inFile(0)
00036 , outFile(0)
00037 {
00038 }
00039
00040
00041
00042
00043 Settings::~Settings() {
00044 }
00045
00046
00047
00048
00049
00050
00051 const struct option Settings::opts[] = {
00052 {"help", no_argument, NULL, 'h'},
00053 {"output", required_argument, NULL, 'o'},
00054 {"debug", optional_argument, NULL, 'D'},
00055 { 0, 0, 0, 0 }
00056 };
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 void Settings::usage(char* prog, std::ostream& out, int ret) {
00070 out << "Usage: " << prog << " [OPTIONS] FILE\n"
00071 << "Options: \n"
00072 << " -h --help Display this help\n"
00073 << " -o --output=STR Write solutions to this file\n"
00074 << " -D --debug[=INT] Set debug message mask\n"
00075 ;
00076 exit(ret);
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086 unsigned Settings::debug = 0;
00087
00088
00089
00090
00091
00092
00093 void Settings::args(int argc, char** argv) {
00094 int opt;
00095 while ((opt = getopt_long(argc, argv, "ho:D::", opts, NULL)) != -1) {
00096 switch (opt) {
00097
00098 case 'h':
00099 usage(argv[0], std::cout, EXIT_SUCCESS);
00100
00101 case 'o':
00102 outFile = optarg;
00103 break;
00104
00105 case 'D':
00106 #ifdef NDEBUG
00107 std::cerr << "Debug code has been disabled." << std::endl;
00108 #else
00109 if (optarg) debug = atoi(optarg);
00110 else debug = (unsigned)-1;
00111 #endif
00112 break;
00113
00114 default:
00115 usage(argv[0], std::cerr, EXIT_FAILURE);
00116
00117 }
00118 }
00119 switch (argc - optind) {
00120 case 1:
00121 inFile = argv[optind];
00122 break;
00123 case 0:
00124 inFile = "/dev/stdin";
00125 break;
00126 default:
00127 std::cerr << "Invalid number of arguments" << std::endl;
00128 usage(argv[0], std::cerr, EXIT_FAILURE);
00129 }
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 void Settings::run() {
00147 CoinSeedRandom(42);
00148 std::cerr << std::setprecision(std::numeric_limits<double>::digits10+2);
00149 Solutions sols;
00150 if (outFile) sols.writeToFile(outFile);
00151 BranchControl bc(sols);
00152 bc.getIP().readMps(inFile);
00153 bc.getIP().randomizeObjective();
00154 bc.run();
00155 }
00156
00157 }