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;
68#ifdef GECODE_HAS_FLOAT_VARS
71 class FloatCutExcludesIncumbent :
public Base {
75 static bool cutBound(
const std::string& source,
79 std::stringstream ss(source);
80 std::unique_ptr<FlatZincSpace>
84 std::unique_ptr<FlatZincSpace>
85 best(
static_cast<FlatZincSpace*
>(fg->clone()));
89 std::unique_ptr<FlatZincSpace>
90 s(
static_cast<FlatZincSpace*
>(fg->clone()));
94 bound = (source.find(
"minimize") != std::string::npos) ?
95 s->fv[0].max() : s->fv[0].min();
99 FloatCutExcludesIncumbent(
void)
100 :
Base(
"FlatZinc::Float::CutExcludesIncumbent") {}
102 virtual bool run(
void) {
105 cutBound(
"var 0.0..1.0: x :: output_var;\nsolve minimize x;\n",
107 cutBound(
"var 0.0..1.0: x :: output_var;\nsolve maximize x;\n",
109 (minBound < 0.5) && (maxBound > 0.5);
113 FloatCutExcludesIncumbent float_cut_excludes_incumbent;
117 class GistStatisticsMode :
public Base {
121 std::string cmd(
"fzn-gecode");
122 int argc =
static_cast<int>(args.size()) + 1;
123 std::vector<char*> argv(argc);
124 argv[0] =
const_cast<char*
>(cmd.data());
125 for (
int i=1; i<argc; i++)
126 argv[i] =
const_cast<char*
>(args[i-1].data());
127 opt.parse(argc,argv.data());
131 GistStatisticsMode(
void)
132 :
Base(
"FlatZinc::Options::GistStatisticsMode",
135 virtual bool run(
void) {
143 GistStatisticsMode gist_statistics_mode;
145#ifndef GECODE_HAS_GIST
149 "Options::GistUnavailable",
150 "var 1..1: x :: output_var;\nsolve satisfy;\n",
151 {
"-mode",
"gist",
"-s"},
152 "Gist mode is unavailable in this build");
158 const std::string& expected,
bool allSolutions,
159 std::vector<std::string> cmdlineOpt,
162 cmdlineOpt,
check, before) {}
165 const std::string& source,
166 const std::string& expected,
bool allSolutions,
167 std::vector<std::string> cmdlineOpt,
175 const std::string& source,
176 std::vector<std::string> cmdlineOpt,
177 std::string expectedMessage)
182 const std::string& source,
183 std::vector<std::string> cmdlineOpt,
184 std::string expectedMessage)
186 _expectedMessage(expectedMessage) {}
195 std::string cmd(
"fzn-gecode");
196 int argc =
static_cast<int>(
_cmdlineOpt.size()) + 1;
197 std::vector<char*> argv(argc);
198 argv[0] =
const_cast<char*
>(cmd.data());
199 for (
int i = 1; i < argc; ++i) {
200 argv[i] =
const_cast<char*
>(
_cmdlineOpt[i-1].data());
202 fznopt.
parse(argc, argv.data());
211 std::unique_ptr<Gecode::FlatZinc::FlatZincSpace> fg(
215 fg->createBranchers(p, fg->solveAnnotations(), fznopt,
218 std::ostringstream os;
219 fg->run(os, p, fznopt, t_total);
221 const std::string output = os.
str();
227 olog <<
"FlatZinc produced the following output:\n" << output <<
"\n";
231 olog <<
"Could not parse input\n";
249 std::string cmd(
"fzn-gecode");
250 int argc =
static_cast<int>(
_cmdlineOpt.size()) + 1;
251 std::vector<char*> argv(argc);
252 argv[0] =
const_cast<char*
>(cmd.data());
253 for (
int i = 1; i < argc; ++i) {
254 argv[i] =
const_cast<char*
>(
_cmdlineOpt[i-1].data());
256 fznopt.
parse(argc, argv.data());
259 std::ostringstream os;
262 std::unique_ptr<Gecode::FlatZinc::FlatZincSpace> fg(
265 fg->createBranchers(p, fg->solveAnnotations(), fznopt,
268 fg->run(os, p, fznopt, t_total);
272 const std::string message = e.
toString();
274 olog <<
ind(2) <<
"Expected FlatZinc error : "
275 << message << std::endl;
276 return (os.str().find(
"----------") == std::string::npos) &&
277 (_expectedMessage.empty() ||
278 (message.find(_expectedMessage) != std::string::npos));
280 const std::string message = e.what();
282 olog <<
ind(2) <<
"Expected Gecode exception : "
283 << message << std::endl;
284 return (os.str().find(
"----------") == std::string::npos) &&
285 (_expectedMessage.empty() ||
286 (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 a standard test with name s.
const std::string & name(void) const
Return name of test.
static std::string str(bool b)
Map bool to string.
TestTags tags(void) const
Return tags for 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.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
double FloatNum
Floating point number base type.
@ SS_FAILED
Space is failed
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.
@ check
Basic integrity tests.
@ standard
Standard test suite.