clasp_output.h
Go to the documentation of this file.
00001 // 
00002 // Copyright (c) 2009-2013, Benjamin Kaufmann
00003 // 
00004 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/ 
00005 // 
00006 // Clasp is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // Clasp is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with Clasp; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 #ifndef CLASP_CLI_OUTPUT_H_INCLUDED
00021 #define CLASP_CLI_OUTPUT_H_INCLUDED
00022 #include <clasp/clasp_facade.h>
00023 #include <clasp/dependency_graph.h>
00024 #include <clasp/solver_types.h>
00025 #include <string>
00026 namespace Clasp { namespace Cli {
00027 void format(const Clasp::BasicSolveEvent& ev, char* out, uint32 outSize);
00028 void format(const Clasp::SolveTestEvent&  ev, char* out, uint32 outSize);
00029 #if WITH_THREADS
00030 void format(const Clasp::mt::MessageEvent& ev, char* out, uint32 outSize);
00031 #endif
00032 
00037 class Output : public EventHandler {
00038 public:
00040         enum PrintLevel { 
00041                 print_all  = 0, 
00042                 print_best = 1, 
00043                 print_no   = 2, 
00044         };
00045         explicit Output(uint32 verb = 1);
00046         virtual ~Output();
00048         uint32 verbosity()               const { return verbose_; }
00050         bool   quiet()                   const { return modelQ() == 2 && optQ() == 2; }
00052         int    modelQ()                  const { return static_cast<int>(quiet_[0]); }
00054         int    optQ()                    const { return static_cast<int>(quiet_[1]); }
00056         int    callQ()                   const { return static_cast<int>(quiet_[2]); }
00057         
00058         using  EventHandler::setVerbosity;
00059         void   setVerbosity(uint32 verb);
00060         void   setModelQuiet(PrintLevel model);
00061         void   setOptQuiet(PrintLevel opt);
00062         void   setCallQuiet(PrintLevel call);
00063         void   setHide(char c);
00064 
00066         virtual void run(const char* solver, const char* version, const std::string* begInput, const std::string* endInput) = 0;
00068         virtual void shutdown(const ClaspFacade::Summary& summary);
00069         virtual void shutdown() = 0;
00071         virtual void onEvent(const Event& ev);
00073         virtual bool onModel(const Solver& s, const Model& m);  
00075         virtual void printModel(const SymbolTable& sym, const Model& m, PrintLevel x) = 0;
00077         virtual void startStep(const ClaspFacade&);
00079         virtual void stopStep(const ClaspFacade::Summary& summary);
00081         virtual void printSummary(const ClaspFacade::Summary& summary, bool final)    = 0;
00083         virtual void printStatistics(const ClaspFacade::Summary& summary, bool final) = 0;
00084 protected:
00085         const Model* getModel() const { return saved_.values ? &saved_ : 0; }
00086         void         saveModel(const Model& m);
00087         void         clearModel() { saved_.values = 0; }
00088         bool         doPrint(const SymbolTable::symbol_type& sym) const {
00089                 return !sym.name.empty() && *sym.name.c_str() != hidePref_;
00090         }
00091 private:
00092         Output(const Output&);
00093         Output& operator=(const Output&);
00094         typedef const ClaspFacade::Summary* SumPtr ;
00095         SumPtr    summary_ ; // summary of last step
00096         ValueVec  vals_    ; // saved values from most recent model
00097         Model     saved_   ; // most recent model
00098         uint32    verbose_ ; // verbosity level
00099         uint8     quiet_[3]; // quiet levels for models, optimize, calls
00100         char      hidePref_; // hide printing of symbols starting with this char
00101 };
00102 
00104 class StatsVisitor {
00105 public:
00106         virtual ~StatsVisitor();
00107         virtual void visitStats(const SharedContext& ctx, const Asp::LpStats* lp, bool accu);
00108         // compound
00109         virtual void visitSolverStats(const SolverStats& stats, bool accu);
00110         virtual void visitProblemStats(const ProblemStats& stats, const Asp::LpStats* lp);
00111         virtual void visitThreads(const SharedContext& ctx);
00112         virtual void visitHccs(const SharedContext& ctx);
00113         virtual void visitThread(uint32, const SolverStats& stats) { visitSolverStats(stats, false); }
00114         virtual void visitHcc(uint32, const SharedContext& stats);
00115         // leafs
00116         virtual void visitLogicProgramStats(const Asp::LpStats& stats) = 0;
00117         virtual void visitProblemStats(const ProblemStats& stats) = 0;
00118         virtual void visitCoreSolverStats(double cpuTime, uint64 models, const SolverStats& stats, bool accu) = 0;
00119         virtual void visitExtSolverStats(const ExtendedStats& stats, bool accu) = 0;
00120         virtual void visitJumpStats(const JumpStats& stats, bool accu) = 0;
00121         virtual void accuStats(const SharedContext& ctx, SolverStats& out) const;
00122 
00123         bool accu;
00124 };
00125 
00127 class JsonOutput : public Output, private StatsVisitor {
00128 public:
00129         explicit JsonOutput(uint32 verb);
00130         ~JsonOutput();
00131         virtual void run(const char* solver, const char* version, const std::string* begInput, const std::string* endInput);
00132         virtual void shutdown(const ClaspFacade::Summary& summary);
00133         virtual void shutdown();
00134         virtual void printSummary(const ClaspFacade::Summary&    summary, bool final);
00135         virtual void printStatistics(const ClaspFacade::Summary& summary, bool final);
00136 private:
00137         virtual void startStep(const ClaspFacade&);
00138         virtual void stopStep(const ClaspFacade::Summary& summary);
00139         virtual void visitThreads(const SharedContext& ctx)         { pushObject("Thread", type_array); StatsVisitor::visitThreads(ctx);    popObject(); }
00140         virtual void visitHccs(const SharedContext& ctx)            { pushObject("HCC", type_array);    StatsVisitor::visitHccs(ctx);       popObject(); }
00141         virtual void visitThread(uint32 i, const SolverStats& stats){ pushObject(0, type_object);       StatsVisitor::visitThread(i, stats);popObject(); }
00142         virtual void visitHcc(uint32 i, const SharedContext& ctx)   { pushObject(0, type_object);       StatsVisitor::visitHcc(i, ctx);     popObject(); }
00143         virtual void visitLogicProgramStats(const Asp::LpStats& stats);
00144         virtual void visitProblemStats(const ProblemStats& stats);
00145         virtual void visitCoreSolverStats(double cpuTime, uint64 models, const SolverStats& stats, bool accu);
00146         virtual void visitExtSolverStats(const ExtendedStats& stats, bool accu);
00147         virtual void visitJumpStats(const JumpStats& stats, bool accu);
00148         enum ObjType { type_object, type_array };
00149         void pushObject(const char* k = 0, ObjType t = type_object);
00150         char popObject();
00151         void printKeyValue(const char* k, const char* v) ;
00152         void printKeyValue(const char* k, uint64 v);
00153         void printKeyValue(const char* k, uint32 v);
00154         void printKeyValue(const char* k, double d);
00155         void printString(const char* s, const char* sep);
00156         void printKey(const char* k);
00157         void printModel(const SymbolTable& sym, const Model& m, PrintLevel x);
00158         void printCosts(const SharedMinimizeData& costs);
00159         void startModel();
00160         bool hasWitness() const { return !objStack_.empty() && *objStack_.rbegin() == '['; }
00161         uint32 indent()   const { return static_cast<uint32>(objStack_.size() * 2); }
00162         const char* open_;
00163         std::string objStack_;
00164 };
00165 
00167 
00179 class TextOutput : public Output, private StatsVisitor {
00180 public:
00181         enum Format      { format_asp, format_aspcomp, format_sat09, format_pb09 };
00182         enum ResultStr   { res_unknonw = 0, res_sat = 1, res_unsat = 2, res_opt = 3, num_str };
00183         enum CategoryKey { cat_comment, cat_value, cat_objective, cat_result, cat_value_term, cat_atom, num_cat };
00184         
00185         const char* result[num_str]; 
00186         const char* format[num_cat]; 
00188         TextOutput(uint32 verbosity, Format f, const char* catAtom = 0, char ifs = ' ');
00189         ~TextOutput();
00190 
00192         virtual void run(const char* solver, const char* version, const std::string* begInput, const std::string* endInput);
00193         virtual void shutdown();
00195 
00199         virtual void printModel(const SymbolTable& sym, const Model& m, PrintLevel x);
00201 
00211         virtual void printSummary(const ClaspFacade::Summary& s   , bool final);
00212         virtual void printStatistics(const ClaspFacade::Summary& s, bool final);
00214         virtual void onEvent(const Event& ev);
00216         virtual void startStep(const ClaspFacade&);
00218         void comment(uint32 v, const char* fmt, ...) const;
00219 private:
00220         virtual void printNames(const SymbolTable& sym, const Model& m);
00221         virtual void visitProblemStats(const ProblemStats& stats, const Asp::LpStats* lp);
00222         virtual void visitSolverStats(const Clasp::SolverStats& s, bool accu);
00223         virtual void visitLogicProgramStats(const Asp::LpStats& stats);
00224         virtual void visitProblemStats(const ProblemStats& stats);
00225         virtual void visitCoreSolverStats(double cpuTime, uint64 models, const SolverStats& stats, bool accu);
00226         virtual void visitExtSolverStats(const ExtendedStats& stats, bool accu);
00227         virtual void visitJumpStats(const JumpStats& stats, bool accu);
00228         virtual void visitThreads(const SharedContext& ctx)      { startSection("Thread");   StatsVisitor::visitThreads(ctx); }
00229         virtual void visitThread(uint32 i, const SolverStats& s)  { startObject("Thread", i); StatsVisitor::visitThread(i, s); }
00230         virtual void visitHccs(const SharedContext& ctx)         { startSection("Tester");   StatsVisitor::visitHccs(ctx);    }
00231         virtual void visitHcc(uint32 i, const SharedContext& ctx){ startObject("HCC", i);    StatsVisitor::visitHcc(i, ctx);  }
00232         int  printSep(CategoryKey c) const;
00233         void printCosts(const SharedMinimizeData&) const;
00234         void startSection(const char* n)     const;
00235         void startObject(const char* n, uint32 i) const;
00236         void setState(uint32 state, uint32 verb, const char* st);
00237         void printSolveProgress(const Event& ev);
00238         double             stTime_;// time on state enter
00239         Clasp::atomic<int> ev_;    // last event type
00240         int                width_; // output width
00241         int                line_;  // lines to print until next separator
00242         uint32             state_; // active state
00243         char               ifs_[2];// field separator
00244 };
00245 }}
00246 #endif


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:38