Generated on Tue May 22 09:40:20 2018 for Gecode by doxygen 1.6.3

fzn-gecode.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2007
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: flatzinc-any