-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a521d36
commit d5632a4
Showing
6 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef FEATURE_GENERATION_PRUNING_MAXSAT_HPP | ||
#define FEATURE_GENERATION_PRUNING_MAXSAT_HPP | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace feature_generation { | ||
struct MaxSatClause { | ||
std::vector<int> variables; | ||
std::vector<bool> negated; | ||
int weight; | ||
bool hard; | ||
|
||
MaxSatClause(const std::vector<int> &variables, | ||
const std::vector<bool> &negated, | ||
const int weight, | ||
const bool hard); | ||
|
||
int size() const { return variables.size(); } | ||
}; | ||
|
||
class MaxSatProblem { | ||
std::vector<int> variables; | ||
std::vector<MaxSatClause> clauses; | ||
|
||
public: | ||
MaxSatProblem(const std::vector<MaxSatClause> &clauses); | ||
|
||
int get_n_variables() const { return variables.size(); } | ||
int get_n_clauses() const { return clauses.size(); } | ||
|
||
// https://maxsat-evaluations.github.io/2022/rules.html#input | ||
std::string to_string(); | ||
}; | ||
} // namespace feature_generation | ||
|
||
#endif // FEATURE_GENERATION_PRUNING_MAXSAT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "../../../include/feature_generation/pruning/maxsat.hpp" | ||
|
||
#include <iostream> | ||
|
||
namespace feature_generation { | ||
MaxSatClause::MaxSatClause(const std::vector<int> &variables, | ||
const std::vector<bool> &negated, | ||
const int weight, | ||
const bool hard) | ||
: variables(variables), negated(negated), weight(weight), hard(hard) { | ||
if (hard && weight != 0) { | ||
std::cout << "error: hard MaxSAT clauses should have 0 weight!" << std::endl; | ||
exit(-1); | ||
} else if (!hard && weight < 1) { | ||
std::cout << "error: soft MaxSAT clauses should have weight >= 1!" << std::endl; | ||
exit(-1); | ||
} | ||
if (variables.size() != negated.size()) { | ||
std::cout << "error: variables and negated in MaxSatClause should have the same size!" << std::endl; | ||
exit(-1); | ||
} | ||
} | ||
|
||
MaxSatProblem::MaxSatProblem(const std::vector<MaxSatClause> &clauses) : clauses(clauses) { | ||
// preprocess | ||
} | ||
|
||
std::string MaxSatProblem::to_string() { | ||
std::string ret = ""; | ||
for (const MaxSatClause &clause : clauses) { | ||
std::string clause_string = ""; | ||
if (clause.hard) { | ||
clause_string += "h "; | ||
} else { | ||
clause_string += std::to_string(clause.weight) + " "; | ||
} | ||
for (int i = 0; i < clause.size(); i++) { | ||
if (clause.negated[i]) { | ||
clause_string += "-"; | ||
} | ||
clause_string += std::to_string(clause.variables[i]) + " "; | ||
} | ||
clause_string += "0"; | ||
ret += clause_string + "\n"; | ||
} | ||
return ret; | ||
} | ||
} // namespace feature_generation |
2 changes: 1 addition & 1 deletion
2
src/feature_generation/pruning.cpp → ...re_generation/pruning/pruning_options.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters