clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
clasp_options.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2006-2013, Benjamin Kaufmann
3 //
4 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/
5 //
6 // Clasp 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 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Clasp 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 Clasp; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 #ifndef CLASP_CLI_CLASP_OPTIONS_H_INCLUDED
21 #define CLASP_CLI_CLASP_OPTIONS_H_INCLUDED
22 
23 #ifdef _MSC_VER
24 #pragma warning (disable : 4200) // nonstandard extension used : zero-sized array
25 #pragma once
26 #endif
27 
28 #include <clasp/clasp_facade.h>
29 #include <string>
30 #include <iosfwd>
31 namespace ProgramOptions {
32 class OptionContext;
33 class OptionGroup;
34 class ParsedOptions;
35 }
36 namespace Clasp { namespace Cli {
37 
39 enum ConfigKey {
40 #define CONFIG(k,g,c) config_##k,
41 #define CLASP_CLI_DEFAULT_CONFIGS config_default = 0,
42 #define CLASP_CLI_AUX_CONFIGS config_default_max_value,
48  config_asp_default = config_tweety,
49  config_sat_default = config_trendy,
50  config_tester_default= config_frumpy,
51 };
52 
54 enum OptionKey {
55 #define OPTION(n,k,...) opt_##k,
56 #define GROUP_BEGIN(X) X
57 #define CLASP_SOLVER_BASIC_OPTIONS option_category_solver,
58 #define CLASP_SOLVER_LOOKBACK_OPTIONS
59 #define CLASP_SEARCH_BASIC_OPTIONS option_category_search,
60 #define CLASP_SEARCH_RESTART_OPTIONS
61 #define CLASP_SEARCH_REDUCE_OPTIONS
62 #define CLASP_CONTEXT_OPTIONS option_category_context,
63 #define CLASP_ASP_OPTIONS option_category_generator,
64 #define CLASP_ENUM_OPTIONS
65 #define CLASP_SOLVE_OPTIONS
68 };
69 class ClaspCliConfig;
70 class ConfigIter {
71 public:
72  const char* name() const;
73  const char* args() const;
74  bool valid()const;
75  bool next();
76 private:
77  friend class ClaspCliConfig;
78  ConfigIter(const char* x);
79  const char* base_;
80 };
81 class ClaspCliConfig : public ClaspConfig {
82 public:
84  static ConfigKey allocConfig();
86 
92  static void appendConfig(ConfigKey k, const char* name, const char* cmd);
94  static ConfigKey loadConfig(const char* fileName);
96  static ConfigIter getConfig(ConfigKey key);
98  static bool releaseConfig(ConfigKey key);
100  static const char* getDefaults(ProblemType f);
101 
102  ClaspCliConfig();
103  ~ClaspCliConfig();
104 
109  void init(uint32 solverId, ConfigKey config = config_asp_default);
112  void initTester(uint32 solverId, ConfigKey config = config_default);
114  bool set(OptionKey o, const char* value);
116  bool set(uint32 solverId, OptionKey o, const char* value);
118  bool setTester(uint32 solverId, OptionKey o, const char* value);
120  bool finalize();
122 
127 
136  bool finalize(const ProgramOptions::ParsedOptions& parsed, ProblemType type, bool applyDefaults);
137 
139 
142  template <class IT>
143  bool setConfig(IT first, IT last, ProblemType t) {
144  RawConfig config("setConfig");
145  while (first != last) { config.addArg(*first++); }
146  return setConfig(config, t);
147  }
149 private:
150  enum ConfigOption { opt_configuration = -1, opt_tester = -2 };
151  static const uint8 mode_solver = 1u;
152  static const uint8 mode_tester = 2u;
153  static const uint8 mode_relaxed= 4u;
154  static const uint8 opt_applied = 0x80u;
155  struct ParseContext;
156  typedef ProgramOptions::OptionContext OptionContext;
157  typedef SingleOwnerPtr<ParseContext> CtxPtr;
158  typedef SingleOwnerPtr<OptionContext> RootPtr;
159  typedef PodVector<std::string>::type ConfigVec;
160  typedef ProgramOptions::ParsedOptions ParsedOpts;
161  struct ScopedSet {
162  ScopedSet(ClaspCliConfig& s, uint8 mode, uint32 sId = 0);
163  ~ScopedSet();
164  ClaspCliConfig* operator->()const { return self; }
165  ClaspCliConfig* self;
166  };
167  struct RawConfig {
168  std::string raw;
169  explicit RawConfig(const char* name);
170  void addArg(const char* arg);
171  void addArg(const std::string& arg);
172  ConfigIter iterator() const { return ConfigIter(raw.data()); }
173  };
174  class ProgOption;
175  void init(OptionContext* ctx, bool owned);
176  int get(OptionKey o, CtxOpts*& ctx, SolverParams*& solver, SolveParams*& solve);
177  bool set(ConfigOption o, const char* value);
178  bool set(const ConfigIter& it, bool allowConfig, const ParsedOpts& exclude, ParsedOpts* out);
179  bool setDefaults(UserConfig* active, uint32 sId, const ParsedOpts& exclude, ProblemType t);
180  bool setConfig(const RawConfig& c, ProblemType t);
181  void error(int opt) const;
182  bool isGenerator() const { return (cliMode & mode_tester) == 0; }
183  const UserConfig*active()const { return isGenerator() ? this : testerConfig(); }
184  UserConfig* active() { return isGenerator() ? this : testerConfig(); }
185  ProgOption* createOption(int o);
186  bool finalizeTester(bool defs);
187  bool finalizeSolvers(UserConfig* active, const ParsedOpts& exclude, ProblemType t, bool defs);
188  const ParsedOpts&finalizeParsed(UserConfig* active, const ParsedOpts& parsed, ParsedOpts& exclude) const;
189 
190  static ConfigVec configs_g;
191  CtxPtr opts_;
192 };
193 void validate(const char* ctx, const SolverParams& solver, const SolveParams& search);
194 
195 }}
196 #endif
BinderType type
Definition: statements.cc:1283
SolveOptions solve
Definition: clasp_facade.h:81
void initTester(uint32 solverId, ConfigKey config=config_default)
Initializes the i'th tester solver with the given configuration.
Definition: clasp_options.cpp:391
ClaspCliConfig()
Definition: clasp_options.cpp:309
static void appendConfig(ConfigKey k, const char *name, const char *cmd)
Appends cmd to the given configuration.
Definition: clasp_options.cpp:204
static const char * getDefaults(ProblemType f)
Returns defaults for the given problem type.
Definition: clasp_options.cpp:279
const char * name() const
Definition: clasp_options.cpp:284
Type
Definition: claspfwd.h:30
bool next()
Definition: clasp_options.cpp:287
Set of options holding a parsed value.
Definition: program_options.h:286
A (logically grouped) list of unique options.
Definition: program_options.h:167
Problem_t::Type ProblemType
Definition: claspfwd.h:34
tuple s
Definition: server.py:45
void addDisabled(ProgramOptions::ParsedOptions &parsed)
Adds options that are disabled by the options contained in parsed to parsed.
Definition: clasp_options.cpp:502
auto f
Definition: statements.cc:122
static ConfigIter getConfig(ConfigKey key)
Returns the configuration with the given key as a double-null-terminated string list.
Definition: clasp_options.cpp:261
void init(uint32 solverId, ConfigKey config=config_asp_default)
Initializes the i'th solver with the given configuration.
Definition: clasp_options.cpp:386
Definition: clasp_options.h:44
UserConfig * testerConfig() const
Definition: clasp_facade.h:77
ContextParams CtxOpts
Definition: solver_strategies.h:393
~ClaspCliConfig()
Definition: clasp_options.cpp:310
Definition: clasp_options.h:70
ConfigKey
Valid configuration keys.
Definition: clasp_options.h:39
static ConfigKey loadConfig(const char *fileName)
Loads the configuration file with the given name and returns a configuration key for accessing it...
Definition: clasp_options.cpp:228
bool set(OptionKey o, const char *value)
Sets the given option in the master configuration.
Definition: clasp_options.cpp:404
bool setTester(uint32 solverId, OptionKey o, const char *value)
Sets the given option in the i'th tester solver.
Definition: clasp_options.cpp:397
Definition: clasp_facade.h:66
static bool releaseConfig(ConfigKey key)
Discards the configuration with the given key.
Definition: clasp_options.cpp:252
bool valid() const
Definition: clasp_options.cpp:286
void addOptions(ProgramOptions::OptionContext &root)
Adds all available options to root.
Definition: clasp_options.cpp:369
Definition: clasp_options.h:47
uint8 cliMode
Definition: solver_strategies.h:385
OptionKey
Valid option keys.
Definition: clasp_options.h:54
tuple c
Definition: visualize.py:132
static ConfigKey allocConfig()
Registers a new empty configuration and returns its key.
Definition: clasp_options.cpp:218
const char * args() const
Definition: clasp_options.cpp:285
int x
Definition: utility.cc:65
BasicSatConfig UserConfig
Definition: clasp_facade.h:68
Definition: clasp_options.h:48
bool setConfig(IT first, IT last, ProblemType t)
Populates this configuration with the options given in [first, last) and finalizes it...
Definition: clasp_options.h:143
Definition: clasp_options.h:50
Definition: clasp_options.h:49
Definition: clasp_options.h:46
void validate(const char *ctx, const SolverParams &solver, const SolveParams &search)
Definition: clasp_options.cpp:595
DefinedBy defs
Definition: dependency.cc:118
Definition: clasp_options.h:45
Definition: clasp_options.h:67
A std::vector-replacement for POD-Types.
Definition: pod_vector.h:115
ParsedValues parsed
Definition: program_options.cpp:852
bool finalize()
Validates and finalizes this configuration.
Definition: clasp_options.cpp:466
A list of options logically grouped under a caption.
Definition: program_options.h:88
LparseOutputter & out
Definition: output.cc:685
Definition: clasp_options.h:81
const SolverOpts & solver(uint32 i) const
Returns the solver options for the i'th solver to be attached to the SharedContext.
Definition: solver_strategies.h:445