this repo has no description
at develop 2.8 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 3/* 4 * Main authors: 5 * Guido Tack <guido.tack@monash.edu> 6 * Gleb Belov <gleb.belov@monash.edu> 7 */ 8 9/* This Source Code Form is subject to the terms of the Mozilla Public 10 * License, v. 2.0. If a copy of the MPL was not distributed with this 11 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 12 13/* This (main) file coordinates flattening and solving. 14 * The corresponding modules are flexibly plugged in 15 * as derived classes, prospectively from DLLs. 16 * A flattening module should provide MinZinc::GetFlattener() 17 * A solving module should provide an object of a class derived from SolverFactory. 18 * Need to get more flexible for multi-pass & multi-solving stuff TODO 19 */ 20 21#include <minizinc/solver.hh> 22 23#include <chrono> 24#include <cstdlib> 25#include <ctime> 26#include <fstream> 27#include <iomanip> 28#include <iostream> 29#include <ratio> 30 31using namespace MiniZinc; 32 33#ifdef _WIN32 34#include <minizinc/interrupt.hh> 35 36int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { 37 InterruptListener::run(); 38#else 39int main(int argc, const char** argv) { 40#endif 41 Timer starttime; 42 bool fSuccess = false; 43 44 try { 45 MznSolver slv(std::cout, std::cerr); 46 try { 47 std::vector<std::string> args(argc - 1); 48#ifdef _WIN32 49 for (int i = 1; i < argc; i++) { 50 args[i - 1] = FileUtils::wide_to_utf8(argv[i]); 51 } 52 fSuccess = (slv.run(args, "", FileUtils::wide_to_utf8(argv[0])) != SolverInstance::ERROR); 53#else 54 for (int i = 1; i < argc; i++) { 55 args[i - 1] = argv[i]; 56 } 57 fSuccess = (slv.run(args, "", argv[0]) != SolverInstance::ERROR); 58#endif 59 } catch (const LocationException& e) { 60 if (slv.getFlagVerbose()) { 61 std::cerr << std::endl; 62 } 63 std::cerr << e.loc() << ":" << std::endl; 64 std::cerr << e.what() << ": " << e.msg() << std::endl; 65 } catch (const Exception& e) { 66 if (slv.getFlagVerbose()) { 67 std::cerr << std::endl; 68 } 69 std::string what = e.what(); 70 std::cerr << what << (what.empty() ? "" : ": ") << e.msg() << std::endl; 71 } catch (const std::exception& e) { 72 if (slv.getFlagVerbose()) { 73 std::cerr << std::endl; 74 } 75 std::cerr << e.what() << std::endl; 76 } catch (...) { 77 if (slv.getFlagVerbose()) { 78 std::cerr << std::endl; 79 } 80 std::cerr << " UNKNOWN EXCEPTION." << std::endl; 81 } 82 83 if (slv.getFlagVerbose()) { 84 std::cerr << " Done ("; 85 std::cerr << "overall time " << starttime.stoptime() << ")." << std::endl; 86 } 87 return static_cast<int>(!fSuccess); 88 } catch (const Exception& e) { 89 std::string what = e.what(); 90 std::cerr << what << (what.empty() ? "" : ": ") << e.msg() << std::endl; 91 std::exit(EXIT_FAILURE); 92 } 93} // int main()