assignment2slitherlink.cpp
Go to the documentation of this file.
00001 
00010 #include "../libcnf/libcnf.h"
00011 #include "slitherlink.h"
00012 
00013 
00014 #define HORIZONTAL true
00015 #define VERTICAL false
00016 
00017 
00018 int main(void)
00019 {
00020         // reading the current slitherlink instance
00021         std::string path ("current_slitherlink.txt");
00022         std::ifstream infile(path.c_str());
00023         Slitherlink * sl = new Slitherlink();
00024         sl->parseInput(&infile);
00025         unsigned int maxLoopSize = sl->getHeight()*sl->getWidth()*4;
00026 
00027         cnf::VariableSet vars(sl->getHeight()+1,sl->getWidth());
00028         // vertical edges continuity
00029         vars.addVars(sl->getHeight(),sl->getWidth()+1);
00030         // horizontal edges indices
00031         vars.addVars(sl->getHeight()+1,sl->getWidth(),maxLoopSize+1);
00032         // vertical edges continuity
00033         vars.addVars(sl->getHeight(),sl->getWidth()+1,maxLoopSize+1);
00034         // horizontal edges sense
00035         vars.addVars(sl->getHeight()+1,sl->getWidth());
00036         // vertical edges sense
00037         vars.addVars(sl->getHeight(),sl->getWidth()+1);
00038 
00039         // reading the result of minisat
00040         vars.parseDimacs(&std::cin);
00041         
00042         // assigning the horizontal edges accordingly
00043         for (unsigned int i=0; i<=sl->getHeight(); i++)
00044                 for (unsigned int j=0; j<sl->getWidth(); j++)
00045                         sl->setVertex(HORIZONTAL,i,j,
00046                                       vars.getVarValue(0,i,j));
00047         
00048         // assigning the vertical edges accordingly
00049         for (unsigned int i=0; i<sl->getHeight(); i++)
00050                 for (unsigned int j=0; j<=sl->getWidth(); j++)
00051                         sl->setVertex(VERTICAL,i,j,
00052                                       vars.getVarValue(1,i,j));
00053 
00054         // outputing the result
00055         sl->printSolution();
00056         return 0;
00057 }
00058 
 All Classes Files Functions Variables Defines