Generated on for Gecode by doxygen 1.17.0
issue166.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
5 *
6 * Copyright:
7 * Mikael Zayenz Lagerkvist, 2026
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 */
32
33#include "test/flatzinc.hh"
34
35namespace Test { namespace FlatZinc {
36
37 namespace {
39 bool check(const std::string& output, int expected,
40 const std::string& representative) {
41 const std::string separator = "----------\n";
42 int solutions = 0;
43 for (std::string::size_type p = 0;
44 (p = output.find(separator,p)) != std::string::npos;
45 p += separator.size())
46 solutions++;
47 return (solutions == expected) &&
48 (output.find(representative) != std::string::npos);
49 }
50
52 class Create {
53 public:
55 Create(void) {
56 (void) new FlatZincTest("Issue166::Original",
57"predicate gecode_global_cardinality(array [int] of var int: x, array [int] of int: cover, array [int] of var int: counts);\n\
58var {1,3}: A :: output_var;\n\
59var 2..3: B :: output_var;\n\
60var 2..3: C :: output_var;\n\
61var 2..3: D :: output_var;\n\
62var 2..5: E :: output_var;\n\
63var 1..4: F :: output_var;\n\
64var 2..3: G :: output_var;\n\
65var 2..3: H :: output_var;\n\
66constraint gecode_global_cardinality([A,D,1,3,3,C,1,H,B],[1,2,3],[G,F,E]) :: domain;\n\
67solve :: int_search([A,B,C,D,E,F,G,H],anti_first_fail,indomain_min,complete) satisfy;\n",
68 "", true, {"-a"}, [] (const std::string& output) {
69 return check(output, 26,
70 "A = 1;\nB = 2;\nC = 3;\nD = 3;\nE = 5;\n"
71 "F = 1;\nG = 3;\nH = 3;\n");
72 });
73 (void) new FlatZincTest("Issue166::Minimized",
74"predicate gecode_global_cardinality(array [int] of var int: x, array [int] of int: cover, array [int] of var int: counts);\n\
75var 1..3: A :: output_var;\n\
76var 1..3: B :: output_var;\n\
77var 1..3: C :: output_var;\n\
78var 1..2: D :: output_var;\n\
79var 2..3: E :: output_var;\n\
80var 2..3: G :: output_var;\n\
81constraint gecode_global_cardinality([3,A,D,G,E],[1,2,3],[1,B,C]) :: domain;\n\
82solve :: int_search([D,A,E,B],input_order,indomain_random,complete) satisfy;\n",
83 "", true, {"-a", "-r", "0", "-c-d", "8"},
84 [] (const std::string& output) {
85 return check(output, 11,
86 "A = 3;\nB = 1;\nC = 3;\nD = 1;\nE = 2;\nG = 3;\n");
87 });
88 }
89 };
90
91 Create c;
92 }
93
94}}
95
96// STATISTICS: test-flatzinc
int solutions(TestSpace *c, Gecode::Search::Options &o, Gecode::Support::RandomGenerator &rand, int maxNbSol=-1)
Find number of solutions.
Definition branch.cpp:412
Tests for FlatZinc.
Definition flatzinc.cpp:38
Case output("Data::Output", [](void) { Data d=read("n: int f: float w: word m[2][2]: int repeat n { k: int x[k]: int }", "2 20 a 1 2 3 4 1 5 2 6 7");std::ostringstream z;d.dzn(z);CHECK(z.str().find("f = 20.0;") !=std::string::npos);CHECK(z.str().find("m = [| 1, 2\n | 3, 4 |];") !=std::string::npos);CHECK(z.str().find("% x: array[int] of tuple(array[int] of int)\n" "x = [([5],), ([6, 7],)];") !=std::string::npos);CHECK(z.str().find("w = \"a\";") !=std::string::npos);std::ostringstream zq;read("var: int w: word", "3 a\033b").dzn(zq);CHECK(zq.str().find("'var' = 3;") !=std::string::npos);CHECK(zq.str().find("w = \"a\\x1bb\";") !=std::string::npos);Data e=read("e[2][0]: int repeat 2 { k: int repeat k { list y: int until 0 } }", "1 7 0 2 8 9 0 0");std::ostringstream ze;e.dzn(ze);CHECK(ze.str().find("e = array2d(1..2, 1..0, []);") !=std::string::npos);CHECK(ze.str().find("y = [([([7],)],), ([([8, 9],), ([],)],)];") !=std::string::npos);std::ostringstream z7;read("a[1][1][1][1][1][1][1]: int", "5").dzn(z7);CHECK(z7.str().find("a = [([([([([([([5],)],)],)],)],)],)];") !=std::string::npos);return true;})
General test support.
Definition afc.cpp:41
@ check
Basic integrity tests.
Definition test.hh:99