diff --git a/walksat/Readme.txt b/walksat/Readme.txt index e06010d..f90715b 100644 --- a/walksat/Readme.txt +++ b/walksat/Readme.txt @@ -8,6 +8,13 @@ $ ./SAT (filename) Example: --------- +NEW (2023 MinGW): +g++ -Wall -g -O2 -c optimized_WALKSAT.cpp +g++ -Wall -g -O2 -c walksat_main.cpp +g++ -o SAT walksat_main.o optimized_WALKSAT.o -static-libgcc + +OLD: + 9000s@LAPTOP-GVVCJ91D MINGW64 ~/Documents/CMPT310/A5_project $ mingw32-make all g++ -c walksat_main.cpp diff --git a/walksat/SAT.exe b/walksat/SAT.exe new file mode 100644 index 0000000..b49c68d Binary files /dev/null and b/walksat/SAT.exe differ diff --git a/walksat/optimized_WALKSAT.cpp b/walksat/optimized_WALKSAT.cpp index 8d3ddce..897257f 100644 --- a/walksat/optimized_WALKSAT.cpp +++ b/walksat/optimized_WALKSAT.cpp @@ -1,4 +1,5 @@ //Shahriar Arefin +//Daniel A. Espinosa Gonzalez , bugfixed your int types being in the wrong places to size_ts #include "optimized_WALKSAT.h" @@ -63,7 +64,7 @@ map walk_sat(float probability_, int max_flips) //flip the variable that maximizes the number of satisfied clauses overall int var; int least_unsat_count = total_clauses; - for (int i = 0; i < choosen_clause.size(); i++) + for (size_t i = 0; i < choosen_clause.size(); i++) { var = abs(choosen_clause[i]); int total_unsat_change = count_unsat_change(model, var); @@ -102,7 +103,7 @@ void load_CNF_file(char* file_path) { getline(input_file, line); tokens = split_clause(line, DELIMITER); vector clause; - for (int j = 0; j < tokens.size()-1; j++) + for (size_t j = 0; j < tokens.size()-1; j++) { clause.push_back( stoi(tokens[j])); } @@ -132,7 +133,7 @@ void display_sat_model(const map& model) } cout << "Therefore solution = " ; - for (int i = 0; i < solution.size(); ++i) + for (size_t i = 0; i < solution.size(); ++i) { cout << "X" << i+1 << ":" << solution[i] << ", "; } @@ -220,7 +221,7 @@ int count_unsat_change(map& model, int variable) bool if_symbol_exists(const vector& clause, int symbol) { - for (int i = 0; i < clause.size(); i++) + for (size_t i = 0; i < clause.size(); i++) { if (abs(clause[i]) == symbol) { @@ -238,7 +239,7 @@ vector split_clause(const string& string_, char delimiter) int word_length = 0; bool inword_ = false; - for (int i = 0; i < string_.length(); i++) + for (size_t i = 0; i < string_.length(); i++) { if (string_[i] == delimiter) { if (inword_ == true) @@ -267,7 +268,7 @@ vector split_clause(const string& string_, char delimiter) string convert_clause_to_string(const vector& clause) { string encoding = "C"; - for (int i = 0; i < clause.size(); i++) + for (size_t i = 0; i < clause.size(); i++) { encoding = encoding + " " + to_string(clause[i]); } diff --git a/walksat/optimized_WALKSAT.o b/walksat/optimized_WALKSAT.o index fe016b6..63116c4 100644 Binary files a/walksat/optimized_WALKSAT.o and b/walksat/optimized_WALKSAT.o differ diff --git a/walksat/walksat_main.o b/walksat/walksat_main.o index 906e75a..9b2e416 100644 Binary files a/walksat/walksat_main.o and b/walksat/walksat_main.o differ