Go to the documentation of this file.00001 #include <stdlib.h>
00002 #include <vector>
00003 #include <iostream>
00004 #include <fstream>
00005 #include <string>
00006
00007 #include "../libcnf/libcnf.h"
00008
00009 using namespace cnf;
00010
00011
00016 std::vector< std::vector<int> > assignment2Grid(std::istream * input)
00017 {
00018 std::vector< std::vector<int> > grid;
00019 VariableSet vars(9,9,9);
00020 vars.parseDimacs(input);
00021 if (vars.getCard() < 729)
00022 {
00023 std::cout << "error 400: Not enough variables in the file!" << std::endl;
00024 exit(400);
00025 }
00026 else
00027 {
00028 bool found;
00029 for (unsigned int i=0; i<9; i++)
00030 {
00031 std::vector<int> line;
00032 std::cout << std::endl;
00033 for (unsigned int j=0; j<9; j++)
00034 {
00035 found = false;
00036 for (unsigned int k=0; k<9; k++)
00037 if (vars.getVarValue(0,i,j,k))
00038 {
00039 if (found)
00040 {
00041 std::cout << "error 402: Two values for the"
00042 << "same cell!" <<std::endl;
00043 exit(402);
00044 }
00045 else
00046 {
00047 found=true;
00048 std::cout << k+1;
00049 line.push_back(k+1);
00050 }
00051 }
00052 if (found)
00053 grid.push_back(line);
00054 else
00055 {
00056 std::cout<< "error 401: missing value at point ("
00057 << i << "," << j <<") !" << std::endl;
00058 exit(401);
00059 }
00060 }
00061 }
00062 }
00063 return grid;
00064 }
00065
00066
00067 int main(int argc, char ** argv)
00073 {
00074 if (argc==1)
00075 {
00076 assignment2Grid(&std::cin);
00077 }
00078 else
00079 {
00080 std::string path (argv[1]);
00081 std::cout<< "Opening " << path << std::endl;
00082 std::ifstream infile(path.c_str());
00083 assignment2Grid(&infile);
00084 infile.close();
00085 }
00086 std::cout<<std::endl<<std::endl;
00087 return 0;
00088 }