forked from MiniZinc/libminizinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminizinc.cpp
77 lines (68 loc) · 2.34 KB
/
minizinc.cpp
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
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <[email protected]>
* Gleb Belov <[email protected]>
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This (main) file coordinates flattening and solving.
* The corresponding modules are flexibly plugged in
* as derived classes, prospectively from DLLs.
* A flattening module should provide MinZinc::GetFlattener()
* A solving module should provide an object of a class derived from SolverFactory.
* Need to get more flexible for multi-pass & multi-solving stuff TODO
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <chrono>
#include <ratio>
#include <minizinc/solver.hh>
using namespace std;
using namespace MiniZinc;
int main(int argc, const char** argv) {
Timer starttime;
bool fSuccess = false;
try {
MznSolver slv(std::cout,std::cerr);
try {
std::vector<std::string> args(argc-1);
for (int i=1; i<argc; i++)
args[i-1] = argv[i];
fSuccess = (slv.run(args,"",argv[0]) != SolverInstance::ERROR);
} catch (const LocationException& e) {
if (slv.get_flag_verbose())
std::cerr << std::endl;
std::cerr << e.loc() << ":" << std::endl;
std::cerr << e.what() << ": " << e.msg() << std::endl;
} catch (const Exception& e) {
if (slv.get_flag_verbose())
std::cerr << std::endl;
std::string what = e.what();
std::cerr << what << (what.empty() ? "" : ": ") << e.msg() << std::endl;
}
catch (const exception& e) {
if (slv.get_flag_verbose())
std::cerr << std::endl;
std::cerr << e.what() << std::endl;
}
catch (...) {
if (slv.get_flag_verbose())
std::cerr << std::endl;
std::cerr << " UNKNOWN EXCEPTION." << std::endl;
}
if (slv.get_flag_verbose()) {
std::cerr << " Done (";
cerr << "overall time " << starttime.stoptime() << ")." << std::endl;
}
return !fSuccess;
} catch (const Exception& e) {
std::string what = e.what();
std::cerr << what << (what.empty() ? "" : ": ") << e.msg() << std::endl;
std::exit(EXIT_FAILURE);
}
} // int main()