Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Signed/Unsigned Integer Comparison Warnings in optimized_WALKSAT.cpp #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions walksat/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added walksat/SAT.exe
Binary file not shown.
13 changes: 7 additions & 6 deletions walksat/optimized_WALKSAT.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -63,7 +64,7 @@ map<int, bool> 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);
Expand Down Expand Up @@ -102,7 +103,7 @@ void load_CNF_file(char* file_path) {
getline(input_file, line);
tokens = split_clause(line, DELIMITER);
vector<int> 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]));
}
Expand Down Expand Up @@ -132,7 +133,7 @@ void display_sat_model(const map<int, bool>& 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] << ", ";
}
Expand Down Expand Up @@ -220,7 +221,7 @@ int count_unsat_change(map<int, bool>& model, int variable)

bool if_symbol_exists(const vector<int>& 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)
{
Expand All @@ -238,7 +239,7 @@ vector<string> 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)
Expand Down Expand Up @@ -267,7 +268,7 @@ vector<string> split_clause(const string& string_, char delimiter)
string convert_clause_to_string(const vector<int>& 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]);
}
Expand Down
Binary file modified walksat/optimized_WALKSAT.o
Binary file not shown.
Binary file modified walksat/walksat_main.o
Binary file not shown.