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 #ifndef CLASP_CLASP_APP_H_INCLUDED
00021 #define CLASP_CLASP_APP_H_INCLUDED
00022
00023 #ifdef _MSC_VER
00024 #pragma warning (disable : 4200) // nonstandard extension used : zero-sized array
00025 #pragma once
00026 #endif
00027 #include <program_opts/typed_value.h>
00028 #include <program_opts/application.h>
00029 #include <clasp/util/timer.h>
00030 #include <clasp/cli/clasp_options.h>
00031 #include <clasp/cli/clasp_output.h>
00032 #include <string>
00033 #include <vector>
00034 #include <iosfwd>
00035 #include <memory>
00036 namespace Clasp { namespace Cli {
00038
00040 enum ExitCode {
00041 E_UNKNOWN = 0,
00042 E_INTERRUPT = 1,
00043 E_SAT = 10,
00044 E_EXHAUST = 20,
00045 E_MEMORY = 33,
00046 E_ERROR = 65,
00047 E_NO_RUN = 128
00048 };
00050
00052 class WriteLemmas {
00053 public:
00054 WriteLemmas(std::ostream& os);
00055 ~WriteLemmas();
00056 void attach(SharedContext& ctx);
00057 void detach();
00058 void flush(Constraint_t::Set types, uint32 maxLbd);
00059 bool unary(Literal, Literal) const;
00060 bool binary(Literal, Literal, Literal) const;
00061 private:
00062 WriteLemmas& operator=(const WriteLemmas&);
00063 SharedContext* ctx_;
00064 std::ostream& os_;
00065 mutable uint32 outShort_;
00066 };
00067 class WriteCnf {
00068 public:
00069 WriteCnf(std::ostream& os) : os_(os) {}
00070 void writeHeader(uint32 numVars, uint32 numCons);
00071 void write(Var maxVar, const ShortImplicationsGraph& g);
00072 void write(ClauseHead* h);
00073 void write(Literal unit);
00074 void close();
00075 bool unary(Literal, Literal) const;
00076 bool binary(Literal, Literal, Literal) const;
00077 private:
00078 WriteCnf& operator=(const WriteCnf&);
00079 std::ostream& os_;
00080 LitVec lits_;
00081 };
00083
00085 struct ClaspAppOptions {
00086 ClaspAppOptions();
00087 typedef std::vector<std::string> StringSeq;
00088 static bool mappedOpts(ClaspAppOptions*, const std::string&, const std::string&);
00089 void initOptions(ProgramOptions::OptionContext& root);
00090 bool validateOptions(const ProgramOptions::ParsedOptions& parsed);
00091 StringSeq input;
00092 std::string lemmaOut;
00093 std::string lemmaIn;
00094 std::string hccOut;
00095 std::string outAtom;
00096 uint32 outf;
00097 char ifs;
00098 bool hideAux;
00099 uint8 quiet[3];
00100 bool onlyPre;
00101 bool printPort;
00102 uint8 outLbd;
00103 uint8 inLbd;
00104 enum OutputFormat { out_def = 0, out_comp = 1, out_json = 2, out_none = 3 };
00105 };
00107
00109
00110 class ClaspAppBase : public ProgramOptions::Application, public Clasp::EventHandler {
00111 public:
00112 typedef ClaspFacade::Summary RunSummary;
00113 typedef ProgramOptions::PosOption PosOption;
00114 protected:
00115 using ProgramOptions::Application::run;
00116 ClaspAppBase();
00117 ~ClaspAppBase();
00118
00119
00120 virtual ProblemType getProblemType() = 0;
00121 virtual void run(ClaspFacade& clasp) = 0;
00122 virtual Output* createOutput(ProblemType f);
00123 virtual void storeCommandArgs(const ProgramOptions::ParsedValues& values);
00124
00125
00126 bool handlePostGroundOptions(ProgramBuilder& prg);
00127 bool handlePreSolveOptions(ClaspFacade& clasp);
00128
00129
00130 virtual const int* getSignals() const;
00131 virtual HelpOpt getHelpOption() const { return HelpOpt("Print {1=basic|2=more|3=full} help and exit", 3); }
00132 virtual PosOption getPositional() const { return parsePositional; }
00133 virtual void initOptions(ProgramOptions::OptionContext& root);
00134 virtual void validateOptions(const ProgramOptions::OptionContext& root, const ProgramOptions::ParsedOptions& parsed, const ProgramOptions::ParsedValues& values);
00135 virtual void setup();
00136 virtual void run();
00137 virtual void shutdown();
00138 virtual bool onSignal(int);
00139 virtual void printHelp(const ProgramOptions::OptionContext& root);
00140 virtual void printVersion();
00141 static bool parsePositional(const std::string& s, std::string& out);
00142
00143
00144 virtual void onEvent(const Event& ev);
00145 virtual bool onModel(const Solver& s, const Model& m);
00146
00147
00148 int exitCode(const RunSummary& sol) const;
00149 void printTemplate() const;
00150 void printDefaultConfigs() const;
00151 void printLibClaspVersion() const;
00152 std::istream& getStream();
00153
00154
00155 void readLemmas(SharedContext& ctx);
00156 void writeNonHcfs(const SharedDependencyGraph& graph) const;
00157 typedef SingleOwnerPtr<Output> OutPtr;
00158 typedef SingleOwnerPtr<ClaspFacade> ClaspPtr;
00159 ClaspCliConfig claspConfig_;
00160 ClaspAppOptions claspAppOpts_;
00161 ClaspPtr clasp_;
00162 OutPtr out_;
00163 };
00165
00167
00168 class ClaspApp : public ClaspAppBase {
00169 public:
00170 ClaspApp();
00171 const char* getName() const { return "clasp"; }
00172 const char* getVersion() const { return CLASP_VERSION; }
00173 const char* getUsage() const { return "[number] [options] [file]"; }
00174 protected:
00175 virtual ProblemType getProblemType();
00176 virtual void run(ClaspFacade& clasp);
00177 virtual void printHelp(const ProgramOptions::OptionContext& root);
00178 private:
00179 ClaspApp(const ClaspApp&);
00180 ClaspApp& operator=(const ClaspApp&);
00181 };
00182 }}
00183 #endif