fzn-gecode.cpp
Go to the documentation of this file.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
00028
00029
00030
00031
00032
00033
00034 #include <iostream>
00035 #include <fstream>
00036 #include <gecode/flatzinc.hh>
00037
00038 using namespace std;
00039 using namespace Gecode;
00040
00041 int main(int argc, char** argv) {
00042
00043 Support::Timer t_total;
00044 t_total.start();
00045 FlatZinc::FlatZincOptions opt("Gecode/FlatZinc");
00046 opt.parse(argc, argv);
00047
00048 if (argc!=2) {
00049 cerr << "Usage: " << argv[0] << " [options] <file>" << endl;
00050 cerr << " " << argv[0] << " -help for more information" << endl;
00051 exit(EXIT_FAILURE);
00052 }
00053
00054 const char* filename = argv[1];
00055 opt.name(filename);
00056
00057 FlatZinc::Printer p;
00058 FlatZinc::FlatZincSpace* fg = NULL;
00059 Rnd rnd(opt.seed());
00060 try {
00061 if (!strcmp(filename, "-")) {
00062 fg = FlatZinc::parse(cin, p, std::cerr, NULL, rnd);
00063 } else {
00064 fg = FlatZinc::parse(filename, p, std::cerr, NULL, rnd);
00065 }
00066
00067 if (fg) {
00068 fg->createBranchers(p, fg->solveAnnotations(), opt,
00069 false, std::cerr);
00070 fg->shrinkArrays(p);
00071 if (opt.output()) {
00072 std::ofstream os(opt.output());
00073 if (!os.good()) {
00074 std::cerr << "Could not open file " << opt.output() << " for output."
00075 << std::endl;
00076 exit(EXIT_FAILURE);
00077 }
00078 fg->run(os, p, opt, t_total);
00079 os.close();
00080 } else {
00081 fg->run(std::cout, p, opt, t_total);
00082 }
00083 } else {
00084 exit(EXIT_FAILURE);
00085 }
00086 delete fg;
00087 } catch (FlatZinc::Error& e) {
00088 std::cerr << "Error: " << e.toString() << std::endl;
00089 return 1;
00090 }
00091
00092 return 0;
00093 }
00094
00095