Skip to content

Commit

Permalink
added minrange and maxrange length to get random models
Browse files Browse the repository at this point in the history
  • Loading branch information
william-eiers committed May 25, 2024
1 parent 86db541 commit b9aa15a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/interface/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,23 +590,27 @@ std::vector<std::string> Driver::GetSimpleRegexes(std::string re_var, int num_re
}

// NOTICE: RESTRICTS OUTPUT TO PRINTABLE ASCII
std::vector<std::string> Driver::GetNumRandomModels(std::vector<std::string> model_variables, unsigned long num_random_models) {
std::vector<std::string> Driver::GetNumRandomModels(std::vector<std::string> model_variables, unsigned long num_random_models, int min, int max) {
std::vector<std::string> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/interface/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Driver {
void reset();
// void solveAst();
std::vector<std::string> GetSimpleRegexes(std::string re_var, int num_regexes = 1, int alpha = 0, int omega = 0);
std::vector<std::string> GetNumRandomModels(std::vector<std::string> model_variables, unsigned long num_random_models);
std::vector<std::string> GetNumRandomModels(std::vector<std::string> 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);
Expand Down
11 changes: 7 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ int main(const int argc, const char **argv) {
std::vector<std::string> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -371,7 +374,7 @@ int main(const int argc, const char **argv) {
<< "usage: --get-num-random-models <NUM_MODELS> <VARIABLE_NAME> <OUTFILE_NAME>";
}

std::vector<std::string> random_models = driver.GetNumRandomModels(model_variables,num_random_models);
std::vector<std::string> 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);
Expand Down

0 comments on commit b9aa15a

Please sign in to comment.