Go to the documentation of this file.00001 #include <stdlib.h>
00002 #include <vector>
00003 #include <iostream>
00004 #include <iomanip>
00005 #include <fstream>
00006 #include <string>
00007 #include <sstream>
00008
00009 #include "../libcnf/libcnf.h"
00010 #include "kakuro.h"
00011
00012 using namespace cnf;
00013
00014
00015 void assignment2Grid(VariableSet * vars, Kakuro * kak)
00016 {
00017 std::vector< std::vector<unsigned int> > gridStruct = kak->getGridStruc();
00018 std::vector< std::vector<unsigned int> > horizontalSum = kak->getHorizontalSum();
00019 std::vector< std::vector<unsigned int> > verticalSum = kak->getVerticalSum();
00020 bool found;
00021 for (unsigned int i=0; i<kak->getNSize(); i++)
00022 {
00023 for (unsigned int j=0; j<kak->getMSize(); j++)
00024 {
00025 if ( gridStruct[i][j] != 0)
00026 {
00027 found = false;
00028 for (unsigned int k=0; k<9; k++)
00029 if (vars->getVarValue(0,i,j,k))
00030 {
00031 if (found)
00032 {
00033 std::cout << "ERROR: Two values for the"
00034 << " same cell!" <<std::endl;
00035 exit(100);
00036 }
00037 else
00038 {
00039 found=true;
00040 kak->assignValue(i,j,k+1);
00041 }
00042 }
00043 if (!found)
00044 {
00045 std::cout<< "ERROR:// missing value at point ("
00046 << i << "," << j <<") !" << std::endl;
00047 exit(100);
00048 }
00049 }
00050 }
00051 }
00052 }
00053
00054
00055 int main(int argc, char ** argv)
00061 {
00062
00063
00064 Kakuro kak;
00065 std::string path ("./currentKakuro.txt");
00066 std::ifstream infile(path.c_str(), std::ifstream::in);
00067 std::cout<<"Parsing grid"<<std::endl;
00068 kak.parseGrid(&infile);
00069 infile.close();
00070 std::cout<<"Interpreting grid"<<std::endl;
00071 kak.grids2sums();
00072
00073
00074 VariableSet * vars = new VariableSet(kak.getNSize(), kak.getMSize(), 9);
00075 vars->addVars(kak.getNHints(),12);
00076 std::cout<<"Parsing dimacs file"<<std::endl;
00077 if (argc==1)
00078 {
00079 vars->parseDimacs(&std::cin);
00080 }
00081 else
00082 {
00083 std::string path2(argv[1]);
00084 std::ifstream assignment(argv[1], std::ifstream::in);
00085
00086 vars->parseDimacs(&assignment);
00087 assignment.close();
00088 }
00089 assignment2Grid(vars,&kak);
00090 std::cout<<"Assignment Parsed..."<<std::endl
00091 <<"Solution:"<<std::endl<<std::endl;
00092 kak.printToStream(std::cout,false);
00093 std::cout<<std::endl<<std::endl;
00094
00095 return 0;
00096 }
00097