43 class TupleSetAutoRepresentation :
public Base {
45 TupleSetAutoRepresentation(
void)
46 :
Base(
"FlatZinc::TupleSet::AutoRepresentation") {}
48 virtual bool run(
void) {
53 for (
int i=0; i<n; i++) {
66 TupleSetAutoRepresentation tuple_set_auto_representation;
69 class GistStatisticsMode :
public Base {
73 std::string cmd(
"fzn-gecode");
74 int argc =
static_cast<int>(args.size()) + 1;
75 std::vector<char*> argv(argc);
76 argv[0] =
const_cast<char*
>(cmd.data());
77 for (
int i=1; i<argc; i++)
78 argv[i] =
const_cast<char*
>(args[i-1].data());
79 opt.parse(argc,argv.data());
83 GistStatisticsMode(
void)
84 :
Base(
"FlatZinc::Options::GistStatisticsMode") {}
86 virtual bool run(
void) {
94 GistStatisticsMode gist_statistics_mode;
96#ifndef GECODE_HAS_GIST
99 "Options::GistUnavailable",
100 "var 1..1: x :: output_var;\nsolve satisfy;\n",
101 {
"-mode",
"gist",
"-s"},
102 "Gist mode is unavailable in this build");
108 const std::string& expected,
bool allSolutions,
109 std::vector<std::string> cmdlineOpt,
116 const std::string& source,
117 std::vector<std::string> cmdlineOpt,
118 std::string expectedMessage)
120 _expectedMessage(expectedMessage) {}
129 std::string cmd(
"fzn-gecode");
130 int argc =
static_cast<int>(
_cmdlineOpt.size()) + 1;
131 std::vector<char*> argv(argc);
132 argv[0] =
const_cast<char*
>(cmd.data());
133 for (
int i = 1; i < argc; ++i) {
134 argv[i] =
const_cast<char*
>(
_cmdlineOpt[i-1].data());
136 fznopt.
parse(argc, argv.data());
145 std::unique_ptr<Gecode::FlatZinc::FlatZincSpace> fg(
149 fg->createBranchers(p, fg->solveAnnotations(), fznopt,
152 std::ostringstream os;
153 fg->run(os, p, fznopt, t_total);
155 const std::string output = os.str();
161 olog <<
"FlatZinc produced the following output:\n" << output <<
"\n";
165 olog <<
"Could not parse input\n";
183 std::string cmd(
"fzn-gecode");
184 int argc =
static_cast<int>(
_cmdlineOpt.size()) + 1;
185 std::vector<char*> argv(argc);
186 argv[0] =
const_cast<char*
>(cmd.data());
187 for (
int i = 1; i < argc; ++i) {
188 argv[i] =
const_cast<char*
>(
_cmdlineOpt[i-1].data());
190 fznopt.
parse(argc, argv.data());
193 std::ostringstream os;
196 std::unique_ptr<Gecode::FlatZinc::FlatZincSpace> fg(
199 fg->createBranchers(p, fg->solveAnnotations(), fznopt,
202 fg->run(os, p, fznopt, t_total);
206 const std::string message = e.
toString();
208 olog <<
ind(2) <<
"Expected FlatZinc error : "
209 << message << std::endl;
210 return (os.str().find(
"----------") == std::string::npos) &&
211 (_expectedMessage.empty() ||
212 (message.find(_expectedMessage) != std::string::npos));
214 const std::string message = e.what();
216 olog <<
ind(2) <<
"Expected Gecode exception : "
217 << message << std::endl;
218 return (os.str().find(
"----------") == std::string::npos) &&
219 (_expectedMessage.empty() ||
220 (message.find(_expectedMessage) != std::string::npos));
Exception: Base-class for exceptions
Exception class for FlatZinc errors
const std::string & toString(void) const
Options for running FlatZinc models
bool allSolutions(void) const
Script mode to run.
void parse(int &argc, char *argv[])
Script mode to run.
A space that can be initialized with a FlatZinc model.
TupleSet arg2tupleset(const IntArgs &a, int noOfVars)
Convert a to TupleSet.
Output support class for FlatZinc interpreter.
Passing integer arguments.
void start(void)
Start timer.
Class representing a set of tuples.
int tuples(void) const
Number of tuples.
bool finalized(void) const
Is tuple set successfully finalized.
ExtensionalPropKind representation(void) const
Return materialized tuple-set representation.
Base class for all tests to be run
Base(std::string s)
Create and register test with name s.
const std::string & name(void) const
Return name of test.
virtual bool run(void)
Perform test.
FlatZincErrorTest(const std::string &name, const std::string &source, std::vector< std::string > cmdlineOpt={}, std::string expectedMessage="")
Construct and register test.
virtual bool run(void)
Perform test.
FlatZincTest(const std::string &name, const std::string &source, const std::string &expected, bool allSolutions=false, std::vector< std::string > cmdlineOpt={}, OutputCheck check=OutputCheck(), BeforeRun before=BeforeRun())
Construct and register test.
std::function< void(void)> BeforeRun
std::vector< std::string > _cmdlineOpt
std::function< bool(const std::string &)> OutputCheck
Simple class for describing indentation.
ScriptMode
Different modes for executing scripts.
@ SM_STAT
Print statistics for script.
@ SM_GIST
Run script in Gist.
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=nullptr, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
Gecode toplevel namespace
std::ostringstream olog
Stream used for logging.