def main():
- if len(sys.argv) <= 1:
- print "usage: ./hexiom_solve.py [0-40] [--dump]?"
- exit(1)
+ if len(sys.argv) <= 1:
+ print "usage: ./run.sh csolverHexiom.py [0-40] [--dump/--alloy]?"
+ exit(1)
- level_no = int(sys.argv[1])
+ level_no = int(sys.argv[1])
- input_filename = LEVEL_INPUT_FILENAME_PATTERN(level_no)
+ input_filename = LEVEL_INPUT_FILENAME_PATTERN(level_no)
- with open(input_filename, 'r') as fil:
- board_input = read_input(fil)
-
- print '== Level to solve== '
- board_input.print_to_stdout()
- csolverlb = ps.loadCSolver();
- csolver = csolverlb.createCCSolver()
- formulation = SAT_formulation_from_board_input(board_input, csolverlb, csolver)
-
- print '=== Done! Calling CSolver solver now ==='
- if len(sys.argv) > 2 and sys.argv[-1] == "--dump":
- csolverlb.serialize(csolver)
+ with open(input_filename, 'r') as fil:
+ board_input = read_input(fil)
+
+ print '== Level to solve== '
+ board_input.print_to_stdout()
+ csolverlb = ps.loadCSolver();
+ csolver = csolverlb.createCCSolver()
+ formulation = SAT_formulation_from_board_input(board_input, csolverlb, csolver)
+
+ print '=== Done! Calling CSolver solver now ==='
+ if len(sys.argv) > 2 and sys.argv[-1] == "--dump":
+ csolverlb.serialize(csolver)
+ if len(sys.argv) > 2 and sys.argv[-1] == "--alloy":
+ csolverlb.setAlloyEncoder(csolver)
# csolverlb.printConstraints(csolver)
- if csolverlb.solve(csolver) != 1:
- print '*** Got UNSAT result! ***'
- sys.exit(1)
- else:
- print '** Solution found! ***'
- print_board_from_assignments(csolverlb, csolver, formulation)
+ if csolverlb.solve(csolver) != 1:
+ print '*** Got UNSAT result! ***'
+ sys.exit(1)
+ else:
+ print '** Solution found! ***'
+ print_board_from_assignments(csolverlb, csolver, formulation)
if __name__ == '__main__':
- main()
+ main()
#include "common.h"
#include <algorithm>
#include <ctime>
-
#define NANOSEC 1000000000.0
-
using namespace std;
+enum SolverType {CSOLVER, DUMP, ALLOY};
+
void EqualOneToCNF(vector<int> literals, vector< vector<int> > & cnf){
int N = literals.size();
cnf.push_back(literals);
}
-void csolverNQueens(int N, bool serialize=false){
+void csolverNQueens(int N, SolverType stype = CSOLVER){
if(N <=1){
cout<<"Q" << endl;
return;
diagonallyDifferentConstraintBothDir(solver, N, elems);
symmetryBreakingConstraint(solver, N, elems);
// solver->printConstraints();
- if(serialize){
+ if(stype == DUMP){
solver->serialize();
+ } else if(stype = ALLOY){
+ solver->setAlloyEncoder();
}
if (solver->solve() != 1){
printf("Problem is Unsolvable ...\n");
int main(int argc, char * argv[]){
if(argc < 2){
- printf("Two arguments are needed\n./nqueen <size> [--csolver]\n");
+ printf("Two arguments are needed\n./nqueen <size> [--csolver/--dump/--alloy]\n");
exit(-1);
}
int N = atoi(argv[1]);
csolverNQueens(N);
}else if (strcmp( argv[2], "--dump") == 0){
printf("Running the CSolver encoding ...\n");
- csolverNQueens(N, true);
+ csolverNQueens(N, DUMP);
+ }else if (strcmp( argv[2], "--alloy") == 0){
+ printf("Running the Alloy encoding ...\n");
+ csolverNQueens(N, ALLOY);
}else {
printf("Unknown argument %s", argv[2]);
}