Skip to content

Commit

Permalink
Minor option fixes and refactoring.
Browse files Browse the repository at this point in the history
* Apply base configuration when setting configuration via setValue().
* Verify config on prepare() if needed.
* Don't use reserved names (names with a double underscore).
* Move Name2Id and option index into unnamed namespace and simplify
  getNode().
* Split execOption() into separate functions and simplify visiting all
  option groups defined in clasp_cli_options.inl.
* Drop ScopeSet and instead store active config in ParseContext.
  • Loading branch information
BenKaufmann committed Jul 4, 2024
1 parent 4182855 commit 439c8a1
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 359 deletions.
39 changes: 32 additions & 7 deletions clasp/cli/clasp_cli_options.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2013-2017 Benjamin Kaufmann
// Copyright (c) 2013-present Benjamin Kaufmann
//
// This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/
//
Expand Down Expand Up @@ -89,7 +89,10 @@
#endif

//! Options for configuring a SharedContext object stored in a Clasp::ContextParams object.
#if defined(CLASP_CONTEXT_OPTIONS)
#if defined(CLASP_CONTEXT_OPTIONS) || defined(CLASP_ALL_GROUPS)
#if !defined(CLASP_CONTEXT_OPTIONS)
#define CLASP_CONTEXT_OPTIONS (*base)
#endif
#define SELF CLASP_CONTEXT_OPTIONS
GROUP_BEGIN(SELF)
OPTION(share, "!,@1", ARG_EXT(defaultsTo("auto")->state(Value::value_defaulted), DEFINE_ENUM_MAPPING(ContextParams::ShareMode, \
Expand Down Expand Up @@ -118,7 +121,10 @@ GROUP_END(SELF)
#endif

//! Global options only valid in facade.
#if defined(CLASP_GLOBAL_OPTIONS)
#if defined(CLASP_GLOBAL_OPTIONS) || defined(CLASP_ALL_GROUPS)
#if !defined(CLASP_GLOBAL_OPTIONS)
#define CLASP_GLOBAL_OPTIONS (*this)
#endif
#define SELF CLASP_GLOBAL_OPTIONS
GROUP_BEGIN(SELF)
OPTION(stats, ",s", ARG(implicit("1")->arg("<n>[,<t>]")), "Enable {1=basic|2=full} statistics (<t> for tester)",\
Expand All @@ -139,7 +145,10 @@ GROUP_END(SELF)
#endif
//! Solver options (see SolverParams).
#if defined(CLASP_SOLVER_OPTIONS)
#if defined(CLASP_SOLVER_OPTIONS) || defined(CLASP_ALL_GROUPS)
#if !defined(CLASP_SOLVER_OPTIONS)
#define CLASP_SOLVER_OPTIONS (*solver)
#endif
#define SELF CLASP_SOLVER_OPTIONS
GROUP_BEGIN(SELF)
OPTION(opt_strategy , "" , ARG_EXT(arg("<arg>"),\
Expand Down Expand Up @@ -318,7 +327,10 @@ GROUP_END(SELF)
#endif
//! Search-related options (see SolveParams).
#if defined(CLASP_SEARCH_OPTIONS)
#if defined(CLASP_SEARCH_OPTIONS) || defined(CLASP_ALL_GROUPS)
#if !defined(CLASP_SEARCH_OPTIONS)
#define CLASP_SEARCH_OPTIONS (*search)
#endif
#define SELF CLASP_SEARCH_OPTIONS
GROUP_BEGIN(SELF)
OPTION(partial_check, "", ARG(implicit("50")), "Configure partial stability tests\n" \
Expand All @@ -338,6 +350,9 @@ OPTION(rand_prob, "", ARG(arg("<n>[,<m>]")), "Do <n> random searches with [<m>=1
GET_IF(SELF.randRuns, SELF.randRuns,SELF.randConf))
#undef SELF
//! Options for configuring the restart strategy of a solver.
#if !defined(CLASP_SEARCH_RESTART_OPTIONS)
#define CLASP_SEARCH_RESTART_OPTIONS (search->restart)
#endif
#define SELF CLASP_SEARCH_RESTART_OPTIONS
#if defined(NOTIFY_SUBGROUPS)
GROUP_BEGIN(SELF)
Expand Down Expand Up @@ -383,6 +398,9 @@ GROUP_END(SELF)
#undef SELF
#undef CLASP_SEARCH_RESTART_OPTIONS
//! Options for configuring the deletion strategy of a solver.
#if !defined(CLASP_SEARCH_REDUCE_OPTIONS)
#define CLASP_SEARCH_REDUCE_OPTIONS (search->reduce)
#endif
#define SELF CLASP_SEARCH_REDUCE_OPTIONS
#if defined(NOTIFY_SUBGROUPS)
GROUP_BEGIN(SELF)
Expand Down Expand Up @@ -439,7 +457,10 @@ GROUP_END(CLASP_SEARCH_OPTIONS)
#endif
//! ASP-front-end options stored in an Clasp::Asp::LogicProgram::AspOptions object.
#if defined(CLASP_ASP_OPTIONS)
#if defined(CLASP_ASP_OPTIONS) || defined(CLASP_ALL_GROUPS)
#if !defined(CLASP_ASP_OPTIONS)
#define CLASP_ASP_OPTIONS (this->asp)
#endif
#define SELF CLASP_ASP_OPTIONS
GROUP_BEGIN(SELF)
OPTION(trans_ext , "!", ARG_EXT(arg("<mode>"), DEFINE_ENUM_MAPPING(Asp::LogicProgram::ExtendedRuleMode,\
Expand Down Expand Up @@ -470,7 +491,10 @@ GROUP_END(SELF)
#endif
//! Options for the solving algorithm (see Clasp::SolveOptions)
#if defined(CLASP_SOLVE_OPTIONS)
#if defined(CLASP_SOLVE_OPTIONS) || defined(CLASP_ALL_GROUPS)
#if !defined(CLASP_SOLVE_OPTIONS)
#define CLASP_SOLVE_OPTIONS (this->solve)
#endif
#define SELF CLASP_SOLVE_OPTIONS
GROUP_BEGIN(SELF)
OPTION(solve_limit , ",@1", ARG(arg("<n>[,<m>]")), "Stop search after <n> conflicts or <m> restarts\n", FUN(arg) {\
Expand Down Expand Up @@ -574,3 +598,4 @@ GROUP_END(SELF)
#undef ARG
#undef ARG_EXT
#undef NO_ARG
#undef CLASP_ALL_GROUPS
37 changes: 12 additions & 25 deletions clasp/cli/clasp_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,45 +258,32 @@ class ClaspCliConfig : public ClaspConfig {
//@}
private:
struct ParseContext;
struct OptIndex;
class ProgOption;
typedef Potassco::ProgramOptions::OptionContext OptionContext;
typedef Potassco::ProgramOptions::OptionGroup Options;
typedef SingleOwnerPtr<Options> OptionsPtr;
typedef Potassco::ProgramOptions::ParsedOptions ParsedOpts;
struct ScopedSet {
ScopedSet(ClaspCliConfig& s, uint8 mode, uint32 sId = 0);
~ScopedSet();
ClaspCliConfig* operator->()const { return self; }
ClaspCliConfig* self;
};
// Operations on active config and solver
int setOption(int option, const char* value, const ParsedOpts* exclude = 0);
int setOption(int option, uint8 mode, uint32 sId, const char* value);
// App interface impl
bool setAppConfig(const std::string& c, ProblemType t);
int setAppOpt(int o, const char* value);
bool setAppDefaults(UserConfig* active, ConfigKey config, const ParsedOpts& exclude, ProblemType t);
bool finalizeAppConfig(UserConfig* active, const ParsedOpts& exclude, ProblemType t, bool defs);
const ParsedOpts& finalizeParsed(UserConfig& active, const ParsedOpts& parsed, ParsedOpts& exclude) const;
int setAppOpt(int o, uint8 mode, const char* value);
bool setAppDefaults(ConfigKey config, uint8 mode, const ParsedOpts& exclude, ProblemType t);
bool finalizeAppConfig(uint8 mode, const ParsedOpts& exclude, ProblemType t, bool defs);
const ParsedOpts& finalizeParsed(uint8 mode, const ParsedOpts& parsed, ParsedOpts& exclude) const;
void createOptions();
ProgOption* createOption(int o);
const std::string&getOptionName(int key, std::string& mem) const;
bool assignDefaults(const ParsedOpts&);
// Configurations
static bool appendConfig(std::string& to, const std::string& line);
static bool loadConfig(std::string& to, const char* fileName);
ConfigIter getConfig(uint8 key, std::string& tempMem);
bool setConfig(const char* name, const char* args, bool allowAppOpt, const ParsedOpts& exclude, ParsedOpts* out);
bool setConfig(const ConfigIter& c, bool allowAppOpt, const ParsedOpts& exclude, ParsedOpts* out);
ConfigIter getConfig(uint8 key, std::string& tempMem) const;
bool setConfig(const char* name, const char* args, uint8 mode, uint32 sId, const ParsedOpts& exclude, ParsedOpts* out);
bool setConfig(const ConfigIter& c, uint8 mode, uint32 sId, const ParsedOpts& exclude, ParsedOpts* out);
// helpers
bool isGenerator() const;
UserConfig* active();
static OptIndex index_g;
OptionsPtr opts_;
std::string config_[2];
uint8 mode_;
uint8 solver_;
bool initTester_;
OptionsPtr opts_;
ParseContext* parseCtx_;
std::string config_[2];
bool validate_;
};
//! Validates the given solver configuration and returns an error string if invalid.
const char* validate(const SolverParams& solver, const SolveParams& search);
Expand Down
Loading

0 comments on commit 439c8a1

Please sign in to comment.