clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
control.hh
Go to the documentation of this file.
1 // {{{ GPL License
2 
3 // This file is part of gringo - a grounder for logic programs.
4 // Copyright (C) 2013 Roland Kaminski
5 
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 // }}}
20 
21 #ifndef _GRINGO_CONTROL_HH
22 #define _GRINGO_CONTROL_HH
23 
24 #include <gringo/value.hh>
25 
26 namespace Gringo {
27 
28 enum class SolveResult { UNKNOWN=0, SAT=1, UNSAT=2 };
29 
30 // {{{ declaration of Model
31 
32 using Int64Vec = std::vector<int64_t>;
33 
34 struct Model {
35  static const unsigned CSP = 1;
36  static const unsigned SHOWN = 2;
37  static const unsigned ATOMS = 4;
38  static const unsigned TERMS = 8;
39  virtual bool contains(Value atom) const = 0;
40  virtual ValVec atoms(int showset) const = 0;
41  virtual Int64Vec optimization() const = 0;
42  virtual ~Model() { }
43 };
44 
45 // }}}
46 // {{{ declaration of Statistics
47 
48 struct Statistics {
50  struct Quantity {
51  Quantity(double d) : rep(d) { assert(d >= 0.0); }
52  Quantity(Error e) : rep(-double(int(e))) { assert(e != error_none); }
53  bool valid() const { return error() == error_none; }
54  Error error() const { return rep >= 0.0 ? error_none : static_cast<Error>(int(-rep)); }
55  operator bool() const { return valid(); }
56  operator double() const { return valid() ? rep : std::numeric_limits<double>::quiet_NaN(); }
57  private:
58  double rep;
59  };
60  virtual Quantity getStat(char const* key) const = 0;
61  virtual char const *getKeys(char const* key) const = 0;
62  virtual ~Statistics() { }
63 };
64 
65 // }}}
66 // {{{ declaration of SolveFuture
67 
68 struct SolveFuture {
69  virtual SolveResult get() = 0;
70  virtual void wait() = 0;
71  virtual bool wait(double timeout) = 0;
72  virtual void interrupt() = 0;
73  virtual ~SolveFuture() { }
74 };
75 
76 // }}}
77 // {{{ declaration of SolveIter
78 
79 struct SolveIter {
80  virtual Model const *next() = 0;
81  virtual void close() = 0;
82  virtual SolveResult get() = 0;
83  virtual ~SolveIter() { }
84 };
85 
86 // }}}
87 // {{{ declaration of Control
88 
89 using FWStringVec = std::vector<FWString>;
90 
91 struct Control {
92  using ModelHandler = std::function<bool (Model const &)>;
93  using FinishHandler = std::function<void (SolveResult, bool)>;
94  using StringVec = std::vector<std::string>;
95  using Assumptions = std::vector<std::pair<Value, bool>>;
96  virtual void ground(std::string const &name, FWValVec args) = 0;
97  virtual SolveResult solve(ModelHandler h, Assumptions &&assumptions) = 0;
98  virtual SolveFuture *asolve(ModelHandler mh, FinishHandler fh, Assumptions &&assumptions) = 0;
99  virtual SolveIter *iterSolve(Assumptions &&assumptions) = 0;
100  virtual void commit() = 0;
101  virtual void add(std::string const &name, FWStringVec const &params, std::string const &part) = 0;
102  virtual void load(std::string const &filename) = 0;
103  virtual Value getConst(std::string const &name) = 0;
104  virtual bool blocked() = 0;
105  virtual void assignExternal(Value ext, bool val) = 0;
106  virtual void releaseExternal(Value ext) = 0;
107  virtual Statistics *getStats() = 0;
108  virtual void setConf(StringVec &&conf) = 0;
109  virtual void enableEnumAssumption(bool enable) = 0;
110  virtual ~Control() { }
111 };
112 
113 // }}}
114 
115 } // namespace Gringo
116 
117 #endif // _GRINGO_CONTROL_HH
118 
static const unsigned CSP
Definition: control.hh:35
virtual void enableEnumAssumption(bool enable)=0
virtual bool blocked()=0
Error
Definition: control.hh:49
virtual Model const * next()=0
Bound::atom_vec::iterator atom
Definition: output.cc:124
Definition: value.hh:113
Definition: control.hh:68
Error error() const
Definition: control.hh:54
virtual void releaseExternal(Value ext)=0
std::vector< std::pair< Value, bool >> Assumptions
Definition: control.hh:95
virtual Statistics * getStats()=0
virtual void wait()=0
virtual Quantity getStat(char const *key) const =0
static const unsigned TERMS
Definition: control.hh:38
static const unsigned ATOMS
Definition: control.hh:37
virtual void interrupt()=0
SolveResult
Definition: control.hh:28
virtual void load(std::string const &filename)=0
virtual ~Model()
Definition: control.hh:42
std::unique_ptr< ValTerm > val(Value v)
Definition: term_helper.hh:31
std::function< void(SolveResult, bool)> FinishHandler
Definition: control.hh:93
std::function< bool(Model const &)> ModelHandler
Definition: control.hh:92
std::vector< std::string > StringVec
Definition: control.hh:94
virtual ~SolveFuture()
Definition: control.hh:73
virtual void close()=0
Definition: control.hh:50
virtual void add(std::string const &name, FWStringVec const &params, std::string const &part)=0
virtual char const * getKeys(char const *key) const =0
virtual bool contains(Value atom) const =0
Definition: control.hh:79
virtual Int64Vec optimization() const =0
Quantity(Error e)
Definition: control.hh:52
Definition: control.hh:34
virtual ValVec atoms(int showset) const =0
Definition: control.hh:48
std::vector< int64_t > Int64Vec
Definition: control.hh:32
virtual Value getConst(std::string const &name)=0
virtual ~Statistics()
Definition: control.hh:62
static const unsigned SHOWN
Definition: control.hh:36
Definition: control.hh:91
tuple d
Definition: pyclingo.py:49
Quantity(double d)
Definition: control.hh:51
virtual SolveIter * iterSolve(Assumptions &&assumptions)=0
virtual SolveResult solve(ModelHandler h, Assumptions &&assumptions)=0
virtual ~SolveIter()
Definition: control.hh:83
std::vector< Value > ValVec
Definition: value.hh:41
virtual ~Control()
Definition: control.hh:110
Definition: control.hh:49
tuple e
Definition: pyclingo.py:50
virtual void setConf(StringVec &&conf)=0
virtual SolveFuture * asolve(ModelHandler mh, FinishHandler fh, Assumptions &&assumptions)=0
bool valid() const
Definition: control.hh:53
virtual void commit()=0
virtual void assignExternal(Value ext, bool val)=0
std::vector< FWString > FWStringVec
Definition: control.hh:89
virtual void ground(std::string const &name, FWValVec args)=0
Definition: flyweight.hh:116