flatzinc.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2014
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "test/flatzinc.hh"
namespace Test { namespace FlatZinc {
FlatZincTest::FlatZincTest(const std::string& name, const std::string& source,
const std::string& expected, bool allSolutions)
: Base("FlatZinc::"+name), _name(name), _source(source), _expected(expected),
_allSolutions(allSolutions) {}
bool
FlatZincTest::run(void) {
using namespace Gecode;
Support::Timer t_total;
t_total.start();
Gecode::FlatZinc::FlatZincOptions fznopt("Gecode/FlatZinc");
fznopt.allSolutions(_allSolutions);
Gecode::FlatZinc::Printer p;
Gecode::FlatZinc::FlatZincSpace* fg = NULL;
try {
std::stringstream ss(_source);
fg = Gecode::FlatZinc::parse(ss, p, olog);
if (fg) {
fg->createBranchers(p, fg->solveAnnotations(), fznopt,
false, olog);
fg->shrinkArrays(p);
std::ostringstream os;
fg->run(os, p, fznopt, t_total);
if (_expected == os.str()) {
return true;
} else {
if (opt.log)
olog << "FlatZinc produced the following output:\n" << os.str() << "\n";
return false;
}
} else {
if (opt.log)
olog << "Could not parse input\n";
return false;
}
delete fg;
} catch (Gecode::FlatZinc::Error& e) {
if (opt.log)
olog << ind(2) << "FlatZinc error : " << e.toString() << std::endl;
return false;
}
return true;
}
}}
// STATISTICS: test-flatzinc
Gecode::FlatZinc::Error
Exception class for FlatZinc errors
Definition flatzinc.hh:665
Gecode::FlatZinc::Error::toString
const std::string & toString(void) const
Definition flatzinc.hh:671
Gecode::FlatZinc::FlatZincOptions
Options for running FlatZinc models
Definition flatzinc.hh:226
Gecode::FlatZinc::FlatZincOptions::allSolutions
bool allSolutions(void) const
Script mode to run.
Definition flatzinc.hh:352
Gecode::FlatZinc::FlatZincSpace
A space that can be initialized with a FlatZinc model.
Definition flatzinc.hh:428
Gecode::FlatZinc::FlatZincSpace::createBranchers
void createBranchers(Printer &p, AST::Node *ann, FlatZincOptions &opt, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
Definition flatzinc.cpp:1037
Gecode::FlatZinc::FlatZincSpace::shrinkArrays
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
Definition flatzinc.cpp:2111
Gecode::FlatZinc::FlatZincSpace::run
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
Definition flatzinc.cpp:1967
Gecode::FlatZinc::FlatZincSpace::solveAnnotations
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Definition flatzinc.cpp:1597
Gecode::FlatZinc::Printer
Output support class for FlatZinc interpreter.
Definition flatzinc.hh:107
Gecode::Support::Timer
Timer
Definition timer.hpp:51
Gecode::Support::Timer::start
void start(void)
Start timer.
Definition timer.hpp:66
Test::Base::Base
Base(const std::string &s)
Create and register test with name s.
Definition test.cpp:59
Test::Base::name
const std::string & name(void) const
Return name of test.
Definition test.hpp:50
Test::FlatZinc::FlatZincTest::FlatZincTest
FlatZincTest(const std::string &name, const std::string &source, const std::string &expected, bool allSolutions=false)
Construct and register test.
Definition flatzinc.cpp:38
Test::FlatZinc::FlatZincTest::run
virtual bool run(void)
Perform test.
Definition flatzinc.cpp:44
Test::FlatZinc::FlatZincTest::_source
std::string _source
Definition flatzinc.hh:54
Test::FlatZinc::FlatZincTest::_name
std::string _name
Definition flatzinc.hh:53
Test::FlatZinc::FlatZincTest::_allSolutions
bool _allSolutions
Definition flatzinc.hh:56
Test::FlatZinc::FlatZincTest::_expected
std::string _expected
Definition flatzinc.hh:55
Test::ind
Simple class for describing identation.
Definition test.hh:66
Gecode::FlatZinc::parse
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
Gecode
Gecode toplevel namespace
Test::FlatZinc
Tests for FlatZinc.
Definition flatzinc.cpp:36
Test
General test support.
Definition afc.cpp:39
Test::olog
std::ostringstream olog
Stream used for logging.
Definition test.cpp:53
Test::opt
Options opt
The options.
Definition test.cpp:97
flatzinc.hh