Skip to content

Commit

Permalink
New verbosity argument added
Browse files Browse the repository at this point in the history
  • Loading branch information
jsego committed May 25, 2023
1 parent d2f952e commit b329d28
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/factory_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ namespace factories {
auto engine = std::make_unique<search::BFS>(std::move(gpp));
//if(arg_parser->get_theory_name() == "bitvec") engine->set_bitvec_theory(true); // ToDo: add it as an argument option?

// Set verbosity
engine->set_verbose(arg_parser->is_verbose());

// Set the theory
engine->set_theory(make_theory(arg_parser));

Expand Down Expand Up @@ -205,7 +208,8 @@ namespace factories {
auto prog_lines = int(prog_ins.size());
auto prog = std::make_unique<Program>(gpp);
auto gd = gpp->get_generalized_domain();
std::cout << gd->to_string(true) << "\n";
if(arg_parser->is_verbose())
std::cout << gd->to_string(true) << "\n";
//auto th = std::make_unique<theory::ActionSchemas>();
//prog->set_instruction(prog_lines-1, gd->get_instruction("end"));
for( int j = 0; j < prog_lines; j++ ){
Expand Down
2 changes: 1 addition & 1 deletion src/search/best_first_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace search {
if (current_evaluations < best_evaluations) {
best_evaluations = current_evaluations;
print_node(current.get());
} else if (_expanded_nodes % PROGRAM_FREQUENCY == 0) {
} else if (_verbose and _expanded_nodes % PROGRAM_FREQUENCY == 0) {
print_node(current.get());
}

Expand Down
11 changes: 10 additions & 1 deletion src/search/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace search{
class Engine{
public:
Engine( std::unique_ptr<GeneralizedPlanningProblem> gpp ) :
_evaluated_nodes(0), _expanded_nodes(0), _gpp(std::move(gpp)){
_evaluated_nodes(0), _expanded_nodes(0), _gpp(std::move(gpp)), _verbose(false){
};

/// Owns _evaluation_functions and _gpp
Expand Down Expand Up @@ -48,6 +48,10 @@ class Engine{
_evaluation_functions.emplace_back(std::move(new_ef) );
}

void set_verbose(bool verbose){
_verbose = verbose;
}

// Set a new theory for the syntactic constraints
void set_theory(std::unique_ptr<theory::Theory> theory){
_theory = std::move(theory);
Expand All @@ -68,13 +72,18 @@ class Engine{
[[nodiscard]] theory::Theory* get_theory() const{
return _theory.get();
}

[[nodiscard]] bool get_verbose() const{
return _verbose;
}

protected:
value_t _evaluated_nodes;
value_t _expanded_nodes;
std::vector<std::unique_ptr<evaluation_functions::EvaluationFunction>> _evaluation_functions;
std::unique_ptr<GeneralizedPlanningProblem> _gpp;
std::unique_ptr<theory::Theory> _theory;
bool _verbose;
};

}
Expand Down
32 changes: 32 additions & 0 deletions src/utils/argument_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ namespace utils {
" activates input instances progressively, where tentative solutions fails; "
" type: boolean (True, False; true, false; 1, 0);"
" default: false\n\n"
" " + _verbosity_stype + ", " + _verbosity_type + " for verbose output; type: boolean"
" (True, False; true, false; 1, 0); default: false\n\n"
"usage examples:\n"
"1. Synthesis: ./main.bin -m synthesis -l 5 -f domains/synthesis/triangular-sum/\n"
"2. Program validation: ./main.bin -m validation-prog -f domains/synthesis/triangular-sum/ -p experiments/synthesis/triangular-sum/triangular-sum_5_ed_ilc.prog\n"
Expand Down Expand Up @@ -172,6 +174,11 @@ namespace utils {
helper("Exactly one output file expected but " + std::to_string(arg_vals.size()) + " found.");
parse_output_file(arg_vals[0]);
}
else if(arg_type == _verbosity_ntype){
if(arg_vals.size() != 1u)
helper("Exactly one boolean expected but " + std::to_string(arg_vals.size()) + " found.");
parse_verbosity(arg_vals[0]);
}
// Check if the argument type is an unrecognized token
else helper("Unrecognized input token: " + arg_type);
}
Expand All @@ -193,6 +200,8 @@ namespace utils {
_num_extra_pointers = 0;
if(arg_map.find(_progressive_ntype) == arg_map.end())
_progressive = false;
if(arg_map.find(_verbosity_ntype) == arg_map.end())
_verbose = false;
}

void parse_validation_arguments(const std::map<std::string, vec_str_t > &arg_map) {
Expand Down Expand Up @@ -223,6 +232,11 @@ namespace utils {
std::to_string(arg_vals.size()) + " found.");
parse_num_extra_pointers(arg_vals[0]);
}
else if(arg_type == _verbosity_ntype){
if(arg_vals.size() != 1u)
helper("Exactly one boolean expected but " + std::to_string(arg_vals.size()) + " found.");
parse_verbosity(arg_vals[0]);
}
// Check if the argument type is an unrecognized token
else helper("Unrecognized input token: " + arg_type);
}
Expand All @@ -240,6 +254,8 @@ namespace utils {
_infinite_detection = false;
if(arg_map.find(_num_extra_pointers_ntype) == arg_map.end())
_num_extra_pointers = 0;
if(arg_map.find(_verbosity_ntype) == arg_map.end())
_verbose = false;

// Parse from _program_file_name the number of _program_lines
_program_lines = utils::count_non_empty_file_lines(_program_file_name);
Expand Down Expand Up @@ -342,6 +358,13 @@ namespace utils {
// helper("Wrong input. The output file \"" + _output_file + "\" is not a valid path.");
}

void parse_verbosity(const std::string &str_verbosity){
auto it = _valid_boolean.find(str_verbosity);
if (it == _valid_boolean.end())
helper("Expected boolean value for verbose argument but " + str_verbosity + " found.");
_infinite_detection = it->second;
}

[[nodiscard]] std::string get_mode() const {
return _mode;
}
Expand Down Expand Up @@ -396,6 +419,10 @@ namespace utils {
return _output_file;
}

[[nodiscard]] bool is_verbose() const{
return _verbose;
}

private:
[[nodiscard]] static std::string normalize_arg_type(const std::string &arg_type) {
if (arg_type == _help_type or arg_type == _help_stype) return _help_ntype;
Expand All @@ -411,6 +438,7 @@ namespace utils {
return _num_extra_pointers_ntype;
if (arg_type == _progressive_type or arg_type == _progressive_stype) return _progressive_ntype;
if (arg_type == _output_file_type or arg_type == _output_file_stype) return _output_file_ntype;
if (arg_type == _verbosity_type or arg_type == _verbosity_stype) return _verbosity_ntype;
return _unrecognized_token;
}

Expand All @@ -427,6 +455,7 @@ namespace utils {
int _num_extra_pointers; // number of extra pointers per argument type
bool _progressive; // optional for synthesis only (default: false)
std::string _output_file; // optional for synthesis only (default: "")
bool _verbose; // optional verbose output

/// Constant argument types (requires C++17)
inline static const std::string _unrecognized_token = ""; // default value for unrecognized tokens
Expand Down Expand Up @@ -463,6 +492,9 @@ namespace utils {
inline static const std::string _output_file_type = "--output-file";
inline static const std::string _output_file_stype = "-o"; // short type
inline static const std::string _output_file_ntype = "output_file"; // normalized type
inline static const std::string _verbosity_type = "--verbosity";
inline static const std::string _verbosity_stype = "-v"; // short type
inline static const std::string _verbosity_ntype = "verbosity"; // normalized type

/// Constant argument values (requires C++17)
inline static const std::set<std::string> _valid_modes = {"synthesis", "validation-prog", "validation-cpp"};
Expand Down

0 comments on commit b329d28

Please sign in to comment.