Commit a73f4b25 authored by Simon de Givry's avatar Simon de Givry Committed by Thomas Schiex
Browse files

[option] read problem compressed in gz and xz format

parent 4baf3271
......@@ -14,7 +14,7 @@ MESSAGE(STATUS " Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
MESSAGE(STATUS " Boost_LIBRARIES: ${Boost_LIBRARIES}")
#SET (all_depends ${all_depends} ${Boost_LIBRARIES} ${ZLIB_LIBRARIES})
SET (all_depends ${all_depends} ${Boost_LIBRARIES} "z")
SET (all_depends ${all_depends} ${Boost_LIBRARIES} "z" "lzma")
IF(NOT Boost_FOUND)
MESSAGE(ERROR "#################################")
......
No preview for this file type
No preview for this file type
......@@ -144,8 +144,9 @@ toulbar2 [option parameters] <file>
and \toulbar2 will start solving the optimization problem described in
its file argument. By default, the extension of the file (either
\texttt{.cfn}, \texttt{.cfn.gz}, \texttt{.wcsp}, \texttt{.wcnf}, \texttt{.cnf}, \texttt{.qpbo},
\texttt{.uai}, \texttt{.LG}, \texttt{.pre} or \texttt{.bep}) is used
\texttt{.cfn}, \texttt{.cfn.gz}, \texttt{.cfn.xz}, \texttt{.wcsp}, \texttt{.wcsp.gz}, \texttt{.wcsp.xz},
\texttt{.wcnf}, \texttt{.wcnf.gz}, \texttt{.wcnf.xz}, \texttt{.cnf}, \texttt{.cnf.gz}, \texttt{.cnf.xz}, \texttt{.qpbo}, \texttt{.qpbo.gz}, \texttt{.qpbo.xz},
\texttt{.uai}, \texttt{.uai.gz}, \texttt{.uai.xz}, \texttt{.LG}, \texttt{.LG.gz}, \texttt{.LG.xz}, \texttt{.pre} or \texttt{.bep}) is used
to determine the nature of the file (see
section~\ref{file-formats}). There is no specific order for the
options or problem file. \toulbar2 comes with decently optimized
......
// Cmake generated version
#define Toulbar_VERSION "1.0.0-70-g170b6dd-master (1542795682)"
#define Toulbar_VERSION "1.0.0-126-g10d7877-master-tainted (1543425235)"
......@@ -417,7 +417,8 @@ public:
static Haplotype* haplotype;
static string map_file;
static bool cfn;
static bool cfngz;
static bool gz;
static bool xz;
static bool bayesian;
static int uai;
static int resolution;
......
......@@ -99,7 +99,8 @@ Pedigree* ToulBar2::pedigree;
Haplotype* ToulBar2::haplotype;
bool ToulBar2::cfn;
bool ToulBar2::cfngz;
bool ToulBar2::gz;
bool ToulBar2::xz;
bool ToulBar2::bayesian;
int ToulBar2::uai;
string ToulBar2::evidence_file;
......@@ -267,7 +268,8 @@ void tb2init()
ToulBar2::haplotype = NULL;
ToulBar2::cfn = false;
ToulBar2::cfngz = false;
ToulBar2::gz = false;
ToulBar2::xz = false;
ToulBar2::bayesian = false;
ToulBar2::uai = 0;
ToulBar2::solution_uai_file = NULL;
......
......@@ -1179,8 +1179,8 @@ void Solver::newSolution()
ToulBar2::pedigree->printGenotype(cout, wcsp->getValue(i));
} else if (ToulBar2::haplotype) {
ToulBar2::haplotype->printHaplotype(cout, wcsp->getValue(i), i);
} else if (ToulBar2::cfn || ToulBar2::cfngz) {
} else if (ToulBar2::cfn) {
// print value name and varname if verbose >1
Value myvalue = ((ToulBar2::sortDomains && ToulBar2::sortedDomains.find(i) != ToulBar2::sortedDomains.end()) ? ToulBar2::sortedDomains[i][wcsp->toIndex(i, wcsp->getValue(i))].value : wcsp->getValue(i));
string valuelabel = ((WCSP*)wcsp)->getVar(i)->getValueName(myvalue);
string varlabel = wcsp->getName(i);
......
......@@ -109,12 +109,19 @@ enum {
// file extension option
OPT_wcsp_ext,
OPT_wcspgz_ext,
OPT_wcspxz_ext,
OPT_wcspXML_ext,
OPT_cfn_ext,
OPT_cfngz_ext,
OPT_cfnxz_ext,
OPT_order_ext,
OPT_uai_ext,
OPT_uaigz_ext,
OPT_uaixz_ext,
OPT_uai_log_ext,
OPT_uaigz_log_ext,
OPT_uaixz_log_ext,
OPT_evid_ext,
OPT_map_ext,
OPT_sol_ext,
......@@ -122,8 +129,14 @@ enum {
OPT_ub_ext,
OPT_pre_ext,
OPT_wcnf_ext,
OPT_wcnfgz_ext,
OPT_wcnfxz_ext,
OPT_cnf_ext,
OPT_cnfgz_ext,
OPT_cnfxz_ext,
OPT_qpbo_ext,
OPT_qpbogz_ext,
OPT_qpboxz_ext,
OPT_treedec_ext,
OPT_clusterdec_ext,
......@@ -277,16 +290,21 @@ CSimpleOpt::SOption g_rgOptions[] = {
{ OPT_debug, (char*)"-Z", SO_OPT }, // debug level
{ OPT_dumpWCSP, (char*)"-z", SO_OPT }, // dump wcsp
//stdin format
{ OPT_stdin, (char*)"--stdin", SO_OPT },
{ OPT_stdin, (char*)"--stdin", SO_REQ_SEP },
// file extension
{ OPT_wcsp_ext, (char*)"--wcsp_ext", SO_REQ_SEP },
{ OPT_wcspXML_ext, (char*)"--wcspXML_ext", SO_REQ_SEP },
{ OPT_cfn_ext, (char*)"--cfn_ext", SO_REQ_SEP },
{ OPT_cfngz_ext, (char*)"--cfngz_ext", SO_REQ_SEP },
{ OPT_cfnxz_ext, (char*)"--cfnxz_ext", SO_REQ_SEP },
{ OPT_order_ext, (char*)"--order_ext", SO_REQ_SEP },
{ OPT_uai_ext, (char*)"--uai_ext", SO_REQ_SEP },
{ OPT_uaigz_ext, (char*)"--uaigz_ext", SO_REQ_SEP },
{ OPT_uaixz_ext, (char*)"--uaixz_ext", SO_REQ_SEP },
{ OPT_uai_log_ext, (char*)"--uai_log_ext", SO_REQ_SEP },
{ OPT_uaigz_log_ext, (char*)"--uaigz_log_ext", SO_REQ_SEP },
{ OPT_uaixz_log_ext, (char*)"--uaixz_log_ext", SO_REQ_SEP },
{ OPT_evid_ext, (char*)"--evid_ext", SO_REQ_SEP },
{ OPT_map_ext, (char*)"--map_ext", SO_REQ_SEP },
{ OPT_sol_ext, (char*)"--sol_ext", SO_REQ_SEP },
......@@ -294,8 +312,14 @@ CSimpleOpt::SOption g_rgOptions[] = {
{ OPT_ub_ext, (char*)"--ub_ext", SO_REQ_SEP },
{ OPT_pre_ext, (char*)"--pre_ext", SO_REQ_SEP },
{ OPT_wcnf_ext, (char*)"--wcnf_ext", SO_REQ_SEP },
{ OPT_wcnfgz_ext, (char*)"--wcnfgz_ext", SO_REQ_SEP },
{ OPT_wcnfxz_ext, (char*)"--wcnfxz_ext", SO_REQ_SEP },
{ OPT_cnf_ext, (char*)"--cnf_ext", SO_REQ_SEP },
{ OPT_cnfgz_ext, (char*)"--cnfgz_ext", SO_REQ_SEP },
{ OPT_cnfxz_ext, (char*)"--cnfxz_ext", SO_REQ_SEP },
{ OPT_qpbo_ext, (char*)"--qpbo_ext", SO_REQ_SEP },
{ OPT_qpbogz_ext, (char*)"--qpbogz_ext", SO_REQ_SEP },
{ OPT_qpboxz_ext, (char*)"--qpboxz_ext", SO_REQ_SEP },
{ OPT_treedec_ext, (char*)"--treedec_ext", SO_REQ_SEP },
{ OPT_clusterdec_ext, (char*)"--clusterdec_ext", SO_REQ_SEP },
......@@ -593,14 +617,15 @@ void help_msg(char* toulbar2filename)
cout << endl;
#ifndef MENDELSOFT
cout << "Available problem formats (specified by the filename extension) are:" << endl;
cout << " *.wcsp : Weighted CSP format (see toulbar2 web site)" << endl;
#ifdef BOOST
cout << " *.cfn : Cost Function Network format (see toulbar2 web site)" << endl;
cout << " *.cfn.gz : gzip'd Cost Function Network format (see toulbar2 web site)" << endl;
#endif
cout << " *.wcsp : Weighted CSP format (see toulbar2 web site)" << endl;
cout << " *.wcnf : Weighted Partial Max-SAT format (see Max-SAT Evaluation)" << endl;
cout << " *.cnf : (Max-)SAT format" << endl;
cout << " *.qpbo : quadratic pseudo-Boolean optimization (unconstrained quadratic programming) format (see also option -qpmult)" << endl;
cout << " *.uai : Bayesian network and Markov Random Field format (see UAI'08 Evaluation) followed by an optional evidence filename (performs MPE task, see -logz for PR task, and write its solution in file .MPE or .PR using the same directory as toulbar2)" << endl;
cout << " *.LG : Bayesian network and Markov Random Field format using logarithms instead of probabilities" << endl;
#ifdef XMLFLAG
cout << " *.xml : CSP and weighted CSP in XML format XCSP 2.1";
#ifdef MAXCSP
......@@ -608,8 +633,6 @@ void help_msg(char* toulbar2filename)
#endif
cout << endl;
#endif
cout << " *.uai : Bayesian network and Markov Random Field format (see UAI'08 Evaluation) followed by an optional evidence filename (performs MPE task, see -logz for PR task, and write its solution in file .MPE or .PR using the same directory as toulbar2)" << endl;
cout << " *.LG : Bayesian network and Markov Random Field format using logarithms instead of probabilities" << endl;
cout << " *.pre : pedigree format (see doc/MendelSoft.txt for Mendelian error correction)" << endl;
cout << " *.pre *.map : pedigree and genetic map formats (see doc/HaplotypeHalfSib.txt for haplotype reconstruction in half-sib families)" << endl;
cout << " *.bep : satellite scheduling format (CHOCO benchmark)" << endl
......@@ -621,7 +644,10 @@ void help_msg(char* toulbar2filename)
cout << " each line contains a list of variable indexes" << endl;
cout << " *.sol : initial solution for the problem (given as initial upperbound plus one and as default value heuristic, or only as initial upperbound if option -x: is added)" << endl
<< endl;
cout << "Warning! File formats are recognized by filename extensions. To change the default file format extension, use option --old_ext=\".new\" Examples: --cfn_ext='.json' --wcsp_ext='.test' --sol_ext='.sol2' " << endl;
#ifdef BOOST
cout << "Note: cfn, cnf, LG, qpbo, uai, wcnf, wcsp formats can be read in gzip'd or xz compressed format, e.g., toulbar2 problem.cfn.xz" << endl;
#endif
cout << "Warning! File formats are recognized by filename extensions. To change the default file format extension, use option --old_ext=\".new\" Examples: --cfn_ext='.json' --wcspgz_ext='.wgz' --sol_ext='.sol2' " << endl;
cout << endl;
#endif
cout << "Available options are (use symbol \":\" after an option to remove a default option):" << endl;
......@@ -658,7 +684,7 @@ void help_msg(char* toulbar2filename)
cout << " -timer=[integer] : CPU time limit in seconds" << endl;
#endif
cout << " -seed=[integer] : random seed non-negative value or use current time if a negative value is given (default value is " << ToulBar2::seed << ")" << endl;
cout << " --stdin=[format] : read file from pipe (default format is cfn) ; e.g., cat example.uai | toulbar2 --stdin=uai" << endl;
cout << " --stdin=[format] : read file from pipe ; e.g., cat example.wcsp | toulbar2 --stdin=wcsp" << endl;
cout << " -var=[integer] : searches by branching only on the first -the given value- decision variables, assuming the remaining variables are intermediate variables completely assigned by the decision variables (use a zero if all variables are decision variables) (default value is " << ToulBar2::nbDecisionVars << ")" << endl;
cout << " -b : searches using binary branching always instead of binary branching for interval domains and n-ary branching for enumerated domains";
if (ToulBar2::binaryBranching)
......@@ -867,21 +893,34 @@ int _tmain(int argc, TCHAR* argv[])
std::map<std::string, string> file_extension_map;
file_extension_map["wcsp_ext"] = ".wcsp";
file_extension_map["wcspgz_ext"] = ".wcsp.gz";
file_extension_map["wcspxz_ext"] = ".wcsp.xz";
file_extension_map["cfn_ext"] = ".cfn";
file_extension_map["cfngz_ext"] = ".cfn.gz";
file_extension_map["cfnxz_ext"] = ".cfn.xz";
file_extension_map["wcspXML_ext"] = ".xml";
file_extension_map["order_ext"] = ".order";
file_extension_map["ub_ext"] = ".ub";
file_extension_map["sol_ext"] = ".sol";
file_extension_map["uai_ext"] = ".uai";
file_extension_map["uaigz_ext"] = ".uai.gz";
file_extension_map["uaixz_ext"] = ".uai.xz";
file_extension_map["uai_log_ext"] = ".LG";
file_extension_map["uaigz_log_ext"] = ".LG.gz";
file_extension_map["uaixz_log_ext"] = ".LG.xz";
file_extension_map["evid_ext"] = ".evid";
file_extension_map["bep_ext"] = ".bep";
file_extension_map["pre_ext"] = ".pre";
file_extension_map["map_ext"] = ".map";
file_extension_map["wcnf_ext"] = ".wcnf";
file_extension_map["wcnfgz_ext"] = ".wcnf.gz";
file_extension_map["wcnfxz_ext"] = ".wcnf.xz";
file_extension_map["cnf_ext"] = ".cnf";
file_extension_map["cnfgz_ext"] = ".cnf.gz";
file_extension_map["cnfxz_ext"] = ".cnf.xz";
file_extension_map["qpbo_ext"] = ".qpbo";
file_extension_map["qpbogz_ext"] = ".qpbo.gz";
file_extension_map["qpboxz_ext"] = ".qpbo.xz";
file_extension_map["treedec_ext"] = ".cov";
file_extension_map["clusterdec_ext"] = ".dec";
......@@ -1857,6 +1896,20 @@ int _tmain(int argc, TCHAR* argv[])
strext = ".wcsp";
strfile = problem;
}
if (check_file_ext(problem, file_extension_map["wcspgz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading gzip'd wcsp file: " << problem << endl;
strext = ".wcsp.gz";
strfile = problem;
ToulBar2::gz = true;
}
if (check_file_ext(problem, file_extension_map["wcspxz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed wcsp file: " << problem << endl;
strext = ".wcsp.xz";
strfile = problem;
ToulBar2::xz = true;
}
// CFN file
if (check_file_ext(problem, file_extension_map["cfn_ext"]) || ToulBar2::stdin_format.compare("cfn") == 0) {
if (ToulBar2::verbose >= 0)
......@@ -1866,12 +1919,22 @@ int _tmain(int argc, TCHAR* argv[])
ToulBar2::cfn = true;
}
// CFN gzip'd file
if (check_file_ext(problem, file_extension_map["cfngz_ext"]) || ToulBar2::stdin_format.compare("cfn.gz") == 0) {
if (check_file_ext(problem, file_extension_map["cfngz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading compressed cfn file: " << problem << endl;
cout << "loading gzip'd cfn file: " << problem << endl;
strext = ".cfn.gz";
strfile = problem;
ToulBar2::cfngz = true;
ToulBar2::cfn = true;
ToulBar2::gz = true;
}
// CFN xz file
if (check_file_ext(problem, file_extension_map["cfnxz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed cfn file: " << problem << endl;
strext = ".cfn.xz";
strfile = problem;
ToulBar2::cfn = true;
ToulBar2::xz = true;
}
// uai file
if (check_file_ext(problem, file_extension_map["uai_ext"]) || ToulBar2::stdin_format.compare("uai") == 0) {
......@@ -1882,6 +1945,26 @@ int _tmain(int argc, TCHAR* argv[])
ToulBar2::uai = 1;
ToulBar2::bayesian = true;
}
// uai gzip'd file
if (check_file_ext(problem, file_extension_map["uaigz_ext"])) {
strfile = problem;
strext = ".uai.gz";
if (ToulBar2::verbose >= 0)
cout << "loading gzip'd uai file: " << problem << endl;
ToulBar2::uai = 1;
ToulBar2::bayesian = true;
ToulBar2::gz = true;
}
// uai xz compressed file
if (check_file_ext(problem, file_extension_map["uaixz_ext"])) {
strfile = problem;
strext = ".uai.xz";
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed uai file: " << problem << endl;
ToulBar2::uai = 1;
ToulBar2::bayesian = true;
ToulBar2::xz = true;
}
// uai log file
if (check_file_ext(problem, file_extension_map["uai_log_ext"]) || ToulBar2::stdin_format.compare("LG") == 0) {
strfile = problem;
......@@ -1891,6 +1974,26 @@ int _tmain(int argc, TCHAR* argv[])
ToulBar2::uai = 2;
ToulBar2::bayesian = true;
}
// uai log file
if (check_file_ext(problem, file_extension_map["uaigz_log_ext"])) {
strfile = problem;
strext = ".LG.gz";
if (ToulBar2::verbose >= 0)
cout << "loading gzip'd uai log file: " << problem << endl;
ToulBar2::uai = 2;
ToulBar2::bayesian = true;
ToulBar2::gz = true;
}
// uai log file
if (check_file_ext(problem, file_extension_map["uaixz_log_ext"])) {
strfile = problem;
strext = ".LG.xz";
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed uai log file: " << problem << endl;
ToulBar2::uai = 2;
ToulBar2::bayesian = true;
ToulBar2::xz = true;
}
// UAI evidence file
if (check_file_ext(problem, file_extension_map["evid_ext"])) {
if (ToulBar2::verbose >= 0)
......@@ -1911,7 +2014,6 @@ int _tmain(int argc, TCHAR* argv[])
}
// wcnf or cnf file
if (check_file_ext(problem, file_extension_map["wcnf_ext"]) || ToulBar2::stdin_format.compare("wcnf") == 0 || ToulBar2::stdin_format.compare("cnf") == 0) {
if (ToulBar2::verbose >= 0)
cout << "loading wcnf file:" << problem << endl;
......@@ -1925,9 +2027,38 @@ int _tmain(int argc, TCHAR* argv[])
strext = ".cnf";
strfile = problem;
}
if (check_file_ext(problem, file_extension_map["wcnfgz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading gzip'd wcnf file:" << problem << endl;
ToulBar2::wcnf = true;
strext = ".wcnf.gz";
strfile = problem;
ToulBar2::gz = true;
} else if (check_file_ext(problem, file_extension_map["cnfgz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading gzip'd cnf file:" << problem << endl;
ToulBar2::wcnf = true;
strext = ".cnf.gz";
strfile = problem;
ToulBar2::gz = true;
}
if (check_file_ext(problem, file_extension_map["wcnfxz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed wcnf file:" << problem << endl;
ToulBar2::wcnf = true;
strext = ".wcnf.xz";
strfile = problem;
ToulBar2::xz = true;
} else if (check_file_ext(problem, file_extension_map["cnfxz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed cnf file:" << problem << endl;
ToulBar2::wcnf = true;
strext = ".cnf.xz";
strfile = problem;
ToulBar2::xz = true;
}
// unconstrained quadratic programming file
if (check_file_ext(problem, file_extension_map["qpbo_ext"]) || ToulBar2::stdin_format.compare("qpbo") == 0) {
if (ToulBar2::verbose >= 0)
cout << "loading quadratic pseudo-Boolean optimization file:" << problem << endl;
......@@ -1935,6 +2066,22 @@ int _tmain(int argc, TCHAR* argv[])
strext = ".qpbo";
strfile = problem;
}
if (check_file_ext(problem, file_extension_map["qpbogz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading gzip'd quadratic pseudo-Boolean optimization file:" << problem << endl;
ToulBar2::qpbo = true;
strext = ".qpbo.gz";
strfile = problem;
ToulBar2::gz = true;
}
if (check_file_ext(problem, file_extension_map["qpboxz_ext"])) {
if (ToulBar2::verbose >= 0)
cout << "loading xz compressed quadratic pseudo-Boolean optimization file:" << problem << endl;
ToulBar2::qpbo = true;
strext = ".qpbo.xz";
strfile = problem;
ToulBar2::xz = true;
}
// upperbound file
......
......@@ -1976,7 +1976,7 @@ Cost WCSP::read_wcsp(const char* fileName)
name = string(basename(Nfile2));
free(Nfile2);
if (ToulBar2::cfn || (ToulBar2::stdin_format.compare("cfn") == 0)) {
if (ToulBar2::cfn && !ToulBar2::gz && !ToulBar2::xz) {
#ifdef BOOST
ifstream Rfile;
istream& stream = (ToulBar2::stdin_format.length() > 0) ? cin : Rfile;
......@@ -1984,7 +1984,7 @@ Cost WCSP::read_wcsp(const char* fileName)
CFNStreamReader fileReader(stream, this);
return getUb();
} else if (to_string(fileName).length() > 0) {
} else {
Rfile.open(fileName);
if (!stream) {
cerr << "Error: could not open file '" << fileName << "'." << endl;
......@@ -1999,41 +1999,48 @@ Cost WCSP::read_wcsp(const char* fileName)
cerr << "Error: compiling with Boost library is needed to allow to read CFN format files." << endl;
exit(EXIT_FAILURE);
#endif
} else if (ToulBar2::cfngz) {
} else if (ToulBar2::cfn && ToulBar2::gz) {
#ifdef BOOST
ifstream Rfile(fileName, std::ios_base::in | std::ios_base::binary);
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : Rfile;
istream& file = Rfile;
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::gzip_decompressor());
inbuf.push(file);
std::istream stream(&inbuf);
if (ToulBar2::stdin_format.compare("cfn.gz") == 0) {
// read from instance from pipe todo doesn work with pipe D. ALLouche
// inbuf.push(file);
if (!file) {
cerr << "Could not open cfn.gz file : " << fileName << endl;
exit(EXIT_FAILURE);
} else {
// inbuf.push(file);
CFNStreamReader fileReader(stream, this);
return getUb();
}
#else
cerr << "Error: compiling with Boost iostreams library is needed to allow to read gzip'd CFN format files." << endl;
exit(EXIT_FAILURE);
#endif
} else if (ToulBar2::cfn && ToulBar2::xz) {
#ifdef BOOST
ifstream Rfile(fileName, std::ios_base::in | std::ios_base::binary);
istream& file = Rfile;
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::lzma_decompressor());
inbuf.push(file);
std::istream stream(&inbuf);
} else if (to_string(fileName).length() > 0) {
// read instance from real file
// inbuf.push(file);
// std::istream stream(&inbuf);
// Rfile.open(fileName);
cout << "file: " << fileName << endl;
if (!file) {
cerr << "Could not open cfn.gz file : " << fileName << endl;
exit(EXIT_FAILURE);
} else {
if (!file) {
cerr << "Could not open cfn.xz file : " << fileName << endl;
exit(EXIT_FAILURE);
} else {
// inbuf.push(file);
CFNStreamReader fileReader(stream, this);
return getUb();
}
// inbuf.push(file);
CFNStreamReader fileReader(stream, this);
return getUb();
}
#else
cerr << "Error: compiling with Boost iostreams library is needed to allow to read gzip'd CF format files." << endl;
cerr << "Error: compiling with Boost iostreams library is needed to allow to read xz compressed CFN format files." << endl;
exit(EXIT_FAILURE);
#endif
}
......@@ -2111,17 +2118,30 @@ Cost WCSP::read_wcsp(const char* fileName)
vector<vector<String> > sharedTuples;
vector<String> emptyTuples;
ifstream Rfile;
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : Rfile;
if (ToulBar2::stdin_format.compare("wcsp") == 0) {
// cout << "pipe reading: " << ToulBar2::stdin_format << endl;
} else if (to_string(fileName).length() > 0 and ToulBar2::stdin_format.length() == 0) {
Rfile.open(fileName);
if (!file) {
cerr << "Could not open wcsp file : " << fileName << endl;
exit(EXIT_FAILURE);
}
ifstream rfile(fileName, (ToulBar2::gz || ToulBar2::xz)?(std::ios_base::in | std::ios_base::binary):(std::ios_base::in));
#ifdef BOOST
boost::iostreams::filtering_streambuf<boost::iostreams::input> zfile;
if (ToulBar2::gz) zfile.push(boost::iostreams::gzip_decompressor());
else if (ToulBar2::xz) zfile.push(boost::iostreams::lzma_decompressor());
zfile.push(rfile);
istream ifile(&zfile);
if (ToulBar2::stdin_format.length() == 0 && !rfile) {
cerr << "Could not open wcsp file : " << fileName << endl;
exit(EXIT_FAILURE);
}
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : ifile;
#else
if (ToulBar2::gz || ToulBar2::xz) {
cerr << "Error: compiling with Boost iostreams library is needed to allow to read compressed wcsp format files." << endl;
exit(EXIT_FAILURE);
}
if (ToulBar2::stdin_format.length() == 0 && !rfile) {
cerr << "Could not open wcsp file : " << fileName << endl;
exit(EXIT_FAILURE);
}
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : rfile;
#endif
// ---------- PROBLEM HEADER ----------
// read problem name and sizes
......@@ -2638,17 +2658,30 @@ void WCSP::read_uai2008(const char* fileName)
// Cost inclowerbound = MIN_COST;
string uaitype;
ifstream Rfile;
istream& file = (ToulBar2::stdin_format.compare("uai") == 0) ? cin : Rfile;
if (ToulBar2::stdin_format.compare("uai") == 0) {
// cout << "pipe reading: " << ToulBar2::stdin_format << endl;
} else {
Rfile.open(fileName);
if (!file) {
cerr << "Could not open file uai: " << fileName << endl;
exit(EXIT_FAILURE);
}
ifstream rfile(fileName, (ToulBar2::gz || ToulBar2::xz)?(std::ios_base::in | std::ios_base::binary):(std::ios_base::in));
#ifdef BOOST
boost::iostreams::filtering_streambuf<boost::iostreams::input> zfile;
if (ToulBar2::gz) zfile.push(boost::iostreams::gzip_decompressor());
else if (ToulBar2::xz) zfile.push(boost::iostreams::lzma_decompressor());
zfile.push(rfile);
istream ifile(&zfile);
if (ToulBar2::stdin_format.length() == 0 && !rfile) {
cerr << "Could not open uai file : " << fileName << endl;
exit(EXIT_FAILURE);
}
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : ifile;
#else
if (ToulBar2::gz || ToulBar2::xz) {
cerr << "Error: compiling with Boost iostreams library is needed to allow to read compressed uai format files." << endl;
exit(EXIT_FAILURE);
}
if (ToulBar2::stdin_format.length() == 0 && !rfile) {
cerr << "Could not open uai file : " << fileName << endl;
exit(EXIT_FAILURE);
}
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : rfile;
#endif
Cost inclowerbound = MIN_COST;
updateUb((MAX_COST - UNIT_COST) / MEDIUM_COST / MEDIUM_COST / MEDIUM_COST / MEDIUM_COST);
......@@ -3087,17 +3120,30 @@ void WCSP::solution_XML(bool opt)
void WCSP::read_wcnf(const char* fileName)
{
ifstream Rfile;
istream& file = (ToulBar2::stdin_format.compare("wcnf") == 0 || ToulBar2::stdin_format.compare("cnf") == 0) ? cin : Rfile;
if (ToulBar2::stdin_format.compare("wcnf") == 0 || ToulBar2::stdin_format.compare("cnf") == 0) {
// cout << "pipe reading: " << ToulBar2::stdin_format << endl;
} else {
Rfile.open(fileName);
if (!file) {
cerr << "Could not open file :: " << fileName << endl;
exit(EXIT_FAILURE);
}
ifstream rfile(fileName, (ToulBar2::gz || ToulBar2::xz)?(std::ios_base::in | std::ios_base::binary):(std::ios_base::in));
#ifdef BOOST
boost::iostreams::filtering_streambuf<boost::iostreams::input> zfile;
if (ToulBar2::gz) zfile.push(boost::iostreams::gzip_decompressor());
else if (ToulBar2::xz) zfile.push(boost::iostreams::lzma_decompressor());
zfile.push(rfile);
istream ifile(&zfile);
if (ToulBar2::stdin_format.length() == 0 && !rfile) {
cerr << "Could not open wcnf file : " << fileName << endl;
exit(EXIT_FAILURE);
}
istream& file = (ToulBar2::stdin_format.length() > 0) ? cin : ifile;
#else
if (ToulBar2::gz || ToulBar2::xz) {
cerr << "Error: compiling with Boost iostreams library is needed to allow to read compressed wcnf format files." << endl;
exit(EXIT_FAILURE);