diff --git a/src/interface/Driver.cpp b/src/interface/Driver.cpp index 7adb4fb..62298b9 100644 --- a/src/interface/Driver.cpp +++ b/src/interface/Driver.cpp @@ -590,23 +590,27 @@ std::vector Driver::GetSimpleRegexes(std::string re_var, int num_re } // NOTICE: RESTRICTS OUTPUT TO PRINTABLE ASCII -std::vector Driver::GetNumRandomModels(std::vector model_variables, unsigned long num_random_models) { +std::vector Driver::GetNumRandomModels(std::vector model_variables, unsigned long num_random_models, int min, int max) { std::vector random_models; auto var = symbol_table_->get_variable(model_variables[0]); auto var_val = symbol_table_->get_value_at_scope(script_,var); auto var_val_auto = var_val->getStringAutomaton(); auto projected_var_val_auto = var_val_auto->GetAutomatonForVariable(model_variables[0]); - auto regex_auto = Theory::StringAutomaton::MakeRegexAuto("[ -~]*"); + auto regex_auto = Theory::StringAutomaton::MakeRegexAuto("[ -~]{"+std::to_string(min)+","+std::to_string(max)+"}"); auto restricted_auto = projected_var_val_auto->Intersect(regex_auto); delete regex_auto; delete projected_var_val_auto; + - for(unsigned long i = 0; i < num_random_models; i++) { - std::string random_model = restricted_auto->GetAnAcceptingStringRandom(); - random_models.push_back(random_model); + if(not restricted_auto->IsEmptyLanguage()) { + for(unsigned long i = 0; i < num_random_models; i++) { + std::string random_model = restricted_auto->GetAnAcceptingStringRandom(); + random_models.push_back(random_model); + } } + delete restricted_auto; return random_models; } diff --git a/src/interface/Driver.h b/src/interface/Driver.h index 55e2d83..4132671 100644 --- a/src/interface/Driver.h +++ b/src/interface/Driver.h @@ -105,7 +105,7 @@ class Driver { void reset(); // void solveAst(); std::vector GetSimpleRegexes(std::string re_var, int num_regexes = 1, int alpha = 0, int omega = 0); - std::vector GetNumRandomModels(std::vector model_variables, unsigned long num_random_models); + std::vector GetNumRandomModels(std::vector model_variables, unsigned long num_random_models, int min, int max); void set_option(const Option::Name option); void set_option(const Option::Name option, const int value); diff --git a/src/main.cpp b/src/main.cpp index f75e94e..ff947c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,6 +75,7 @@ int main(const int argc, const char **argv) { std::vector model_variables; unsigned long num_random_models = 0; std::string random_models_file = ""; + int minrange = 0, maxrange = 0; bool count_tuple = false; bool count_tuple_variables = false; @@ -155,11 +156,13 @@ int main(const int argc, const char **argv) { ++i; } else if (argv[i] == std::string("--get-num-random-models")) { num_random_models = std::stoul(argv[i+1]); - std::string model_vars {argv[i+2]}; - random_models_file = std::string({argv[i+3]}); + minrange = std::stoi(argv[i+2]); + maxrange = std::stoi(argv[i+3]); + std::string model_vars {argv[i+4]}; + random_models_file = std::string({argv[i+5]}); model_variables = parse_count_vars(model_vars); driver.set_option(Vlab::Option::Name::GET_NUM_RANDOM_MODELS); - i += 3; + i += 5; } else if (argv[i] == std::string("--count-variable")) { std::string count_vars {argv[i+1]}; count_variables = parse_count_vars(count_vars); @@ -371,7 +374,7 @@ int main(const int argc, const char **argv) { << "usage: --get-num-random-models "; } - std::vector random_models = driver.GetNumRandomModels(model_variables,num_random_models); + std::vector random_models = driver.GetNumRandomModels(model_variables,num_random_models, minrange, maxrange); std::ofstream of; of.open(random_models_file.c_str(), std::ofstream::out | std::ofstream::trunc);