diff --git a/.clang-tidy b/.clang-tidy index 78d5e41ef6..a3bff09bca 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,24 +1,61 @@ # Use clang-tidy 22. Keep checks focused on correctness and useful modernization. Checks: >- -*, + clang-analyzer-core.*, bugprone-assert-side-effect, bugprone-dangling-handle, + bugprone-inaccurate-erase, bugprone-integer-division, bugprone-macro-repeated-side-effects, bugprone-misplaced-widening-cast, bugprone-move-forwarding-reference, bugprone-sizeof-expression, + bugprone-suspicious-memory-comparison, bugprone-suspicious-memset-usage, bugprone-unused-raii, + bugprone-unused-return-value, + bugprone-use-after-move, + bugprone-virtual-near-miss, modernize-deprecated-headers, modernize-use-nullptr, modernize-use-override, + performance-avoid-endl, + performance-faster-string-find, performance-for-range-copy, + performance-implicit-conversion-in-loop, + performance-inefficient-algorithm, performance-inefficient-string-concatenation, + performance-inefficient-vector-operation, performance-move-const-arg, + performance-move-constructor-init, + performance-no-automatic-move, performance-unnecessary-copy-initialization, - performance-unnecessary-value-param + readability-identifier-naming WarningsAsErrors: '*' HeaderFilterRegex: '(gecode|test|examples|tools)/' ExcludeHeaderFilterRegex: 'gecode/third-party/|gecode/flatzinc/(parser\.tab\.(cpp|hpp)|lexer\.yy\.cpp)$' FormatStyle: file + +CheckOptions: + # Explicit discards document intentional ownership handoffs. + bugprone-unused-return-value.AllowCastToVoid: true + readability-identifier-naming.FunctionCase: lower_case + readability-identifier-naming.MethodCase: lower_case + readability-identifier-naming.VariableCase: lower_case + readability-identifier-naming.MemberCase: lower_case + readability-identifier-naming.ParameterCase: lower_case + readability-identifier-naming.EnumConstantCase: UPPER_CASE + readability-identifier-naming.ConstantCase: lower_case + # Constants and functions standing for constant values, such as + # ME_INT_VAL, ES_SUBSUMED, and INT_VAR_SIZE_MIN, may use UPPER_CASE. + readability-identifier-naming.ConstantIgnoredRegexp: '^(_?[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_|[A-Z][A-Z0-9_]*)$' + readability-identifier-naming.FunctionIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[A-Z][A-Z0-9_]*)$' + readability-identifier-naming.MethodIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[A-Z][A-Z0-9_]*)$' + readability-identifier-naming.VariableIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_)$' + readability-identifier-naming.MemberIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_)$' + readability-identifier-naming.ParameterIgnoredRegexp: '^(_[a-z][a-z0-9_]*|[a-z][a-z0-9_]*_)$' + readability-identifier-naming.EnumConstantIgnoredRegexp: '^[A-Z][A-Z0-9_]*_$' + # New scoped enums name their constants in PascalCase, as EndReason::Limit; + # scoped enums converted from plain enums keep UPPER_CASE. + readability-identifier-naming.ScopedEnumConstantCase: UPPER_CASE + readability-identifier-naming.ScopedEnumConstantIgnoredRegexp: '^([A-Z][a-zA-Z0-9]*|[A-Z][A-Z0-9_]*_)$' diff --git a/.github/ci/generated-source-freshness.sh b/.github/ci/generated-source-freshness.sh index 4ee175d19d..58e6d37482 100755 --- a/.github/ci/generated-source-freshness.sh +++ b/.github/ci/generated-source-freshness.sh @@ -119,14 +119,11 @@ vis_files=( # Copy generator inputs with their source-relative paths. Generated outputs stay # isolated until --update explicitly copies them back to the source tree. -# The copy goes through an archive file: in a pipe, bsdtar may stop reading -# at the end-of-archive marker before the writer has written its final -# padding, which fails the writer with a write error. -tar -C "$repo_root" -cf "$workspace/source.tar" \ - .clang-format misc/genvarimp.py "${vis_files[@]}" \ - gecode/flatzinc/parser.yxx gecode/flatzinc/lexer.lxx -tar -C "$source_copy" -xf "$workspace/source.tar" -rm -f -- "$workspace/source.tar" +for input in .clang-format misc/genvarimp.py "${vis_files[@]}" \ + gecode/flatzinc/parser.yxx gecode/flatzinc/lexer.lxx; do + mkdir -p "$source_copy/$(dirname "$input")" + cp "$repo_root/$input" "$source_copy/$input" +done mkdir -p "$source_copy/gecode/kernel" normalize_generated_whitespace() { diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45592e7387..4377a94739 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,56 @@ jobs: shell: bash run: uv run misc/tidy.py --check + check-extended: + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + + - name: Install uv + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 + with: + enable-cache: false + + - name: Install LLVM 22 and check dependencies + shell: bash + run: | + curl --fail --location --retry 3 https://apt.llvm.org/llvm-snapshot.gpg.key -o "$RUNNER_TEMP/llvm.asc" + sudo install -m 644 "$RUNNER_TEMP/llvm.asc" /usr/share/keyrings/llvm.asc + echo 'deb [signed-by=/usr/share/keyrings/llvm.asc] https://apt.llvm.org/noble/ llvm-toolchain-noble-22 main' | sudo tee /etc/apt/sources.list.d/llvm.list + sudo apt-get update + sudo apt-get install -y clang-22 clang-format-22 clang-tidy-22 clang-tools-22 \ + ninja-build bison flex graphviz libgmp-dev libmpfr-dev \ + qt6-base-dev qt6-base-dev-tools libgl1-mesa-dev + + - name: Install Doxygen 1.18.0 + shell: bash + run: | + archive="$RUNNER_TEMP/doxygen-1.18.0.linux.bin.tar.gz" + curl --fail --location --retry 3 https://www.doxygen.nl/files/doxygen-1.18.0.linux.bin.tar.gz -o "$archive" + printf '%s %s\n' 14fa81bdc34171edb5f1f02b1d60e74802f0439b77fa44e592565d517d72df90 "$archive" | sha256sum --check + mkdir -p "$RUNNER_TEMP/doxygen" + tar -xzf "$archive" -C "$RUNNER_TEMP/doxygen" --strip-components=1 + doxygen_bin="$(find "$RUNNER_TEMP/doxygen" -type f -name doxygen -print -quit)" + "$doxygen_bin" --version + dirname "$doxygen_bin" >> "$GITHUB_PATH" + + - name: Configure full Debug checks + shell: bash + run: > + cmake -S . -B build/check-extended -G Ninja + -DCMAKE_BUILD_TYPE=Debug + -DCMAKE_C_COMPILER=clang-22 -DCMAKE_CXX_COMPILER=clang++-22 + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DGECODE_ENABLE_EXPERIMENTAL=ON -DGECODE_ENABLE_CBS=ON + -DGECODE_ENABLE_AUDIT=ON -DGECODE_ENABLE_FAULT_INJECTION=ON + -DGECODE_ENABLE_QT=ON -DGECODE_ENABLE_GIST=ON -DGECODE_ENABLE_MPFR=ON + -DGECODE_ENABLE_EXAMPLES=ON -DGECODE_REGENERATE_VARIMP=ON + + - name: Run all checks + shell: bash + run: uv run misc/check.py all --build-dir build/check-extended --jobs 4 + build-cmake-unix: runs-on: ${{ matrix.os }} strategy: diff --git a/CMakeLists.txt b/CMakeLists.txt index c878a733b6..1f023b91ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1611,6 +1611,12 @@ endif() if(GECODE_ENABLE_EXAMPLES) add_subdirectory(examples) + if(GECODE_BUILD_GIST_TARGET) + add_subdirectory(gecode/gist/standalone-example) + endif() + if(GECODE_ENABLE_FLATZINC AND GECODE_HAS_QT_RUNTIME AND GECODE_BUILD_SHARED) + add_subdirectory(gecode/flatzinc/exampleplugin) + endif() endif() # --------------------------------------------------------------------------- diff --git a/changelog.in b/changelog.in index ac7003bafb..eda8ed76ed 100644 --- a/changelog.in +++ b/changelog.in @@ -117,6 +117,46 @@ Rank: minor Define the GECODE_FREELIST32_SIZE_MAX and GECODE_FREELIST64_SIZE_MAX build options as numbers in config.hpp. A quoted value broke compilation. +[ENTRY] +Module: other +What: performance +Rank: minor +[DESCRIPTION] +Move owned branching and open-variable-list callbacks through constructors +instead of copying them repeatedly. Avoid copying read-only argument arrays +in examples, reserve worker-control thread storage, and buffer multi-line +output while flushing complete solutions, progress, and protocol messages. +[MORE] +Expand clang-tidy checks for hidden copies, container operations, missed moves, +stream flushing, and correctness errors. + +[ENTRY] +Module: other +What: change +Rank: major +[DESCRIPTION] +Rename the strict-less relation constants IRT_LE, FRT_LE, and SRT_LE to +IRT_LT, FRT_LT, and SRT_LT. Remove the old spellings without compatibility +aliases to avoid confusion with less-or-equal. Relation values and semantics +are unchanged; the less-or-equal constants retain the _LQ suffix. + +[ENTRY] +Module: other +What: change +Rank: major +[DESCRIPTION] +Require C++23 and adopt four-space indentation and a 120-column limit with +clang-format 22. +Functions, variables, and members use snake_case; types retain PascalCase. +Constants and functions that stand for constant values, such as ME_INT_VAL, +ES_SUBSUMED, and INT_VAR_SIZE_MIN, retain UPPER_CASE. Public API names +change, including no_overlap, bin_packing, and modification_event_delta. +Update downstream source code before recompiling. +[MORE] +Add formatting, clang-tidy, and extended repository check commands. Extended +checks include generated sources, CTest suites, installed-package consumers, +and documentation. EditorConfig replaces per-file indentation headers. + [ENTRY] Module: other What: removed diff --git a/docs/code-style.md b/docs/code-style.md index 09d59124b0..6d8b0689ae 100644 --- a/docs/code-style.md +++ b/docs/code-style.md @@ -9,8 +9,9 @@ defaults. Keep upstream third-party files in their original style. C++ uses four-space indentation and a 120-column limit. Braces stay on the opening line, compact nested namespaces remain indented, and pointer and reference markers bind to the type. Function definitions retain a separate -return-type line. Include order and comment wrapping are preserved, including -copyright notices and Doxygen text. +return-type line. Include order and comment wrapping are preserved. Comment +indentation follows the surrounding code, including copyright notices and +Doxygen text. Four spaces distinguish nested control flow. The 120-column limit leaves room for namespace-qualified calls, templates, and generated scheduling expressions. @@ -35,18 +36,40 @@ The generated FlatZinc parser and lexer retain Bison and Flex formatting; their upstream scaffolding is excluded from clang-format. Regenerate these files from `.yxx` and `.lxx` inputs rather than editing the output by hand. -## Naming migration - -The naming migration is pending a decision on which identifier categories -change, including types and namespaces. Names should separate words with -underscores and describe their purpose. A casing check cannot identify word -boundaries in existing names such as `dfsengine` and `modeventdelta`; those -need explicit review. - -Changing every category requires resolving collisions before applying fixes. -For example, `Int` cannot become the keyword `int`, and the `DFS` class -template cannot take the existing `dfs` function's name. Review those choices -alongside the public API, generated code, and documentation. +## Naming + +Functions, variables, and members use `snake_case`. Types retain `PascalCase`; +enum constants and macros retain `UPPER_CASE`. The constants of a new scoped +enum use `PascalCase`, as in `EndReason::Limit`. Existing private-member leading +or trailing underscores are accepted when the name itself is snake_case. + +Constants may use `UPPER_CASE`, and so may functions that stand for constant +values. Modification events and propagation conditions (`ME_INT_VAL`, +`PC_INT_DOM`), propagator status helpers (`ES_SUBSUMED`, `ES_FIX_PARTIAL`), +and branching selectors (`INT_VAR_SIZE_MIN()`, `INT_VAL_MIN()`) belong to the +same vocabulary as the enum constants they appear with, such as `ES_FIX` and +`IRT_EQ`, and keep their spelling. +Names should separate words and describe their purpose. A casing check cannot +identify word boundaries in names such as `dfsengine` and `modeventdelta`; +those require explicit review. + +Representative API changes include: + +| Previous spelling | Current spelling | +|---|---| +| `IRT_LE`, `FRT_LE`, `SRT_LE` | `IRT_LT`, `FRT_LT`, `SRT_LT` | +| `nooverlap(...)` | `no_overlap(...)` | +| `binpacking(...)` | `bin_packing(...)` | +| `modeventdelta(...)` | `modification_event_delta(...)` | +| `dfsengine(...)` | `make_dfs_engine(...)` | +| `clearall(value)` | `fill_bits(value)` | +| `arg2intvarargs(...)` | `arg_to_int_var_args(...)` | + +Strict-less relation constants use `_LT`; `_LQ` continues to mean less-or-equal. +The former `_LE` names have no compatibility aliases. + +Qt overrides and other external interfaces retain the spellings their APIs +require. Parser tokens and protocol strings remain unchanged. ## Checking changes @@ -66,9 +89,42 @@ Lint requires a Ninja or Makefiles compilation database configured with `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`; it checks compiled sources and their maintained headers. The command reports sources outside that build so optional modules cannot silently disappear from the coverage report. +Bison/Flex grammar syntax is reviewed manually; clang-tidy checks the owned C++ +action ranges in their generated translation units. The extended command also checks the changelog and generated-source freshness, -builds the configured targets, runs the standard test suite, and runs CTest. +builds the configured targets, runs CTest integrity and enabled fault suites, +installs into `check-install` under the build directory, and builds, tests, and lints the +allocator and public-test-component package consumers. It also builds the +documentation (Doxygen 1.18.0 or newer). The full `check-standard` and +`check-sweep` suites remain separate targets: the standard suite alone contains +over 54,000 cases and defaults to five iterations per case. +Besides LLVM 22, the extended check requires uv, Bison 3.8.2, Flex 2.6.4, Ninja, +and Doxygen 1.18.0 or newer. Configure with `BUILD_TESTING`, `GECODE_INSTALL`, +`GECODE_ENABLE_ALLOCATOR`, search, integer variables, minimodel, and driver +enabled. Lint always analyzes assertions by undefining `NDEBUG`, regardless of +the selected build type. Ordinary compilation and runtime tests retain the +configured build settings. Enable optional and experimental modules in the build when checking them; platform-specific code also needs its corresponding CI toolchain. Normal builds use checked-in generated sources and do not require LLVM tools. + +Performance checks cover hidden loop copies, associative-container lookup, +vector growth, string operations, and missed moves as well as unnecessary +copies. Use `'\n'` inside a formatted record. Flush explicitly when publishing +a solution, progress update, protocol response, or complete diagnostic; a +printer should not flush each row of a multi-line solution. +The unused-return-value check accepts explicit `(void)` discards for reviewed +operations such as ownership handoff after successful engine construction. + +`performance-unnecessary-value-param` is reserved for manual performance audits. +Its suggestions mix Gecode's small, intentionally copied variable/view handles +with ownership-sensitive callbacks and argument arrays. Review actual copy +cost and lifetime requirements before changing those public signatures. + +Other performance checks need focused review: `performance-enum-size` changes +layouts and ABI, and `performance-no-int-to-ptr` conflicts with deliberate +pointer tagging. Review `noexcept` guarantees, destructor triviality, and math +promotion against allocation-failure handling and interval-rounding semantics +before adopting those checks. Never add `noexcept` to a potentially throwing +operation just to satisfy a diagnostic. diff --git a/examples/all-interval.cpp b/examples/all-interval.cpp index 1febd2fafd..26fc92ef56 100644 --- a/examples/all-interval.cpp +++ b/examples/all-interval.cpp @@ -79,7 +79,7 @@ class AllInterval : public Script { distinct(*this, d, opt.ipl()); // Break mirror symmetry - rel(*this, x[0], IRT_LE, x[1]); + rel(*this, x[0], IRT_LT, x[1]); // Break symmetry of dual solution rel(*this, d[0], IRT_GR, d[n - 2]); @@ -91,18 +91,18 @@ class AllInterval : public Script { d.update(*this, s.d); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new AllInterval(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { const int n = x.size(); os << "\tx[" << n << "] = {"; for (int i = 0; i < n - 1; i++) os << x[i] << "(" << d[i] << "),"; - os << x[n - 1] << "}" << std::endl; + os << x[n - 1] << "}" << '\n'; } }; @@ -117,7 +117,7 @@ main(int argc, char* argv[]) { opt.ipl(IPL_BND); opt.parse(argc, argv); if (opt.size() < 2) { - std::cerr << "size must be at least 2!" << std::endl; + std::cerr << "size must be at least 2!" << '\n'; return -1; } Script::run(opt); diff --git a/examples/alpha.cpp b/examples/alpha.cpp index c1d3816feb..827c16c0f3 100644 --- a/examples/alpha.cpp +++ b/examples/alpha.cpp @@ -106,20 +106,20 @@ class Alpha : public Script { le.update(*this, s.le); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Alpha(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << "\t"; for (int i = 0; i < n; i++) { os << ((char)(i + 'a')) << '=' << le[i] << ((i < n - 1) ? ", " : "\n"); if ((i + 1) % 8 == 0) - os << std::endl << "\t"; + os << '\n' << "\t"; } - os << std::endl; + os << '\n'; } }; diff --git a/examples/archimedean-spiral.cpp b/examples/archimedean-spiral.cpp index 90272dec44..aa91fbd0bc 100644 --- a/examples/archimedean-spiral.cpp +++ b/examples/archimedean-spiral.cpp @@ -91,19 +91,19 @@ class ArchimedeanSpiral : public FloatMaximizeScript { f.update(*this, p.f); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new ArchimedeanSpiral(*this); } /// Cost function - virtual FloatVar - cost(void) const { + FloatVar + cost(void) const override { return f[0]; } /// Print solution coordinates - virtual void - print(std::ostream& os) const { - os << "XY " << f[1].med() << " " << f[2].med() << std::endl; + void + print(std::ostream& os) const override { + os << "XY " << f[1].med() << " " << f[2].med() << '\n'; } }; diff --git a/examples/bacp.cpp b/examples/bacp.cpp index a8a687bb93..e7a547129a 100644 --- a/examples/bacp.cpp +++ b/examples/bacp.cpp @@ -117,12 +117,12 @@ class BACP : public IntMinimizeScript { /// Actual model BACP(const SizeOptions& opt) : IntMinimizeScript(opt), curr(curriculum[opt.size()]) { - std::map courseMap; // Map names to course numbers - int maxCredit = 0; - int numberOfCourses = 0; - for (const Course* co = curr.courses; co->name != 0; co++) { - courseMap[co->name] = numberOfCourses++; - maxCredit += co->credit; + std::map course_map; // Map names to course numbers + int max_credit = 0; + int number_of_courses = 0; + for (const Course* co = curr.courses; co->name != nullptr; co++) { + course_map[co->name] = number_of_courses++; + max_credit += co->credit; } int p = curr.p; @@ -132,14 +132,14 @@ class BACP : public IntMinimizeScript { int d = curr.d; l = IntVarArray(*this, p, a, b); - u = IntVar(*this, 0, maxCredit); + u = IntVar(*this, 0, max_credit); q = IntVarArray(*this, p, c, d); - x = IntVarArray(*this, numberOfCourses, 0, p - 1); + x = IntVarArray(*this, number_of_courses, 0, p - 1); for (int j = 0; j < p; j++) { - BoolVarArgs xij(*this, numberOfCourses, 0, 1); - IntArgs t(numberOfCourses); - for (int i = 0; i < numberOfCourses; i++) { + BoolVarArgs xij(*this, number_of_courses, 0, 1); + IntArgs t(number_of_courses); + for (int i = 0; i < number_of_courses; i++) { rel(*this, (x[i] == j) == xij[i]); t[i] = curr.courses[i].credit; } @@ -150,15 +150,15 @@ class BACP : public IntMinimizeScript { } // Precedence - for (const char** prereq = curr.prereqs; *prereq != 0; prereq += 2) - rel(*this, x[courseMap[*prereq]] < x[courseMap[*(prereq + 1)]]); + for (const char** prereq = curr.prereqs; *prereq != nullptr; prereq += 2) + rel(*this, x[course_map[*prereq]] < x[course_map[*(prereq + 1)]]); // Optimization criterion: minimize u max(*this, l, u); // Redundant constraints - linear(*this, l, IRT_EQ, maxCredit); - linear(*this, q, IRT_EQ, numberOfCourses); + linear(*this, l, IRT_EQ, max_credit); + linear(*this, q, IRT_EQ, number_of_courses); switch (opt.branching()) { case BRANCHING_NAIVE: @@ -213,31 +213,31 @@ class BACP : public IntMinimizeScript { x.update(*this, bacp.x); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new BACP(*this); } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return u; } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { std::vector> period(curr.p); for (int i = x.size(); i--;) period[x[i].val()].push_back(i); - os << "Solution with load " << u.val() << ":" << std::endl; + os << "Solution with load " << u.val() << ":" << '\n'; for (int i = 0; i < curr.p; i++) { os << "\tPeriod " << i + 1 << ": "; for (std::list::iterator v = period[i].begin(); v != period[i].end(); ++v) { os << curr.courses[*v].name << " "; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } }; @@ -256,7 +256,7 @@ main(int argc, char* argv[]) { opt.iterations(20); opt.parse(argc, argv); if (opt.size() >= n_examples) { - std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_examples - 1 << '\n'; return 1; } IntMinimizeScript::run(opt); @@ -277,7 +277,7 @@ namespace { {"hxwxx2", 1}, {"iei231", 4}, {"iei241", 4}, {"iei271", 3}, {"iei281", 3}, {"iwn261", 3}, {"hfw120", 2}, {"iei233", 4}, {"iei238", 3}, {"iei261", 3}, {"iei272", 3}, {"iei273", 3}, {"iei161", 3}, {"iei232", 3}, {"iei262", 3}, {"iei274", 3}, {"iwi365", 3}, {"iwn270", 3}, - {"hrw130", 2}, {"iei218", 3}, {"iei219", 3}, {"iei248", 3}, {0, 0}}; + {"hrw130", 2}, {"iei218", 3}, {"iei219", 3}, {"iei248", 3}, {nullptr, 0}}; /// Prerequisites for first example const char* prereqs8[] = {"dew101", "dew100", "fis101", "fis100", "fis101", "mat192", "mat191", "mat190", "mat193", @@ -288,7 +288,7 @@ namespace { "iei231", "iei238", "iei231", "iei261", "iwn261", "iei272", "iei271", "iei273", "iei271", "iei273", "iei271", "iei161", "iwn261", "iei161", "iwn261", "iei232", "iei273", "iei232", "iei273", "iei262", "iwn261", "iei274", "iei273", "iei274", "iei273", "iei219", "iei232", - "iei248", "iei233", "iei248", "iei233", 0, 0}; + "iei248", "iei233", "iei248", "iei233", nullptr, nullptr}; /// Courses for second example const Course courses10[] = { @@ -298,7 +298,7 @@ namespace { {"ili260", 3}, {"iwn261", 3}, {"mat024", 4}, {"fis130", 4}, {"ili239", 4}, {"ili245", 4}, {"ili253", 4}, {"fis140", 4}, {"ili236", 4}, {"ili243", 4}, {"ili270", 3}, {"ili280", 4}, {"ici344", 4}, {"ili263", 3}, {"ili332", 4}, {"ili355", 4}, {"iwn170", 3}, {"icdxx1", 3}, {"ili362", 3}, {"iwn270", 3}, {"icdxx2", 3}, - {0, 0}}; + {nullptr, 0}}; /// Prerequisites for second example const char* prereqs10[] = {"dew101", "dew100", "fis110", "fis100", "fis110", "mat021", "mat022", "mat021", "dewxx0", @@ -308,7 +308,7 @@ namespace { "ili245", "ili153", "ili253", "ili153", "fis140", "fis120", "fis140", "fis130", "ili236", "ili239", "ili243", "ili245", "ili270", "ili260", "ili270", "iwn261", "ili280", "mat024", "ici344", "ili243", "ili263", "ili260", "ili263", "iwn261", "ili332", "ili236", "ili355", - "ili153", "ili355", "ili280", "ili362", "ili263", 0, 0}; + "ili153", "ili355", "ili280", "ili362", "ili263", nullptr, nullptr}; /// Courses for third example const Course courses12[] = { @@ -321,7 +321,7 @@ namespace { {"ili238", 4}, {"ili242", 3}, {"ili275", 3}, {"ili355", 4}, {"hrw110", 2}, {"ici393", 4}, {"ili237", 4}, {"ili334", 4}, {"ili363", 3}, {"iwn261", 3}, {"hrw100", 2}, {"ici382", 4}, {"ili331", 4}, {"ili362", 3}, {"ili381", 3}, {"iln230", 3}, {"ici313", 2}, {"ici315", 2}, {"ici332", 3}, {"ici344", 4}, {"icn336", 3}, - {"iwi365", 3}, {"ici314", 2}, {"ici367", 2}, {0, 0}}; + {"iwi365", 3}, {"ici314", 2}, {"ici367", 2}, {nullptr, 0}}; /// Prerequisites for third example const char* prereqs12[] = { @@ -336,7 +336,7 @@ namespace { "hrw110", "hrw150", "ici393", "mat210", "ici393", "mat260", "ili237", "ili231", "ili237", "ili252", "ili334", "ili238", "ili363", "ili273", "hrw100", "hrw110", "ici382", "ili334", "ili331", "ili238", "ili331", "ili274", "ili362", "ili363", "ili381", "ili281", "ili381", "mat210", "iln230", "iwn170", "ici313", "ili331", "ici332", - "ici393", "ici332", "ili331", "ici344", "ili243", "icn336", "ici393", "ici314", "ici313", 0, 0}; + "ici393", "ici332", "ili331", "ici344", "ili243", "icn336", "ici393", "ici314", "ici313", nullptr, nullptr}; /// The example specifications const Curriculum curriculum[] = {{8, 10, 24, 2, 10, courses8, prereqs8}, diff --git a/examples/bibd.cpp b/examples/bibd.cpp index f444a82c9c..df844db4a6 100644 --- a/examples/bibd.cpp +++ b/examples/bibd.cpp @@ -68,15 +68,15 @@ class BIBDOptions : public Options { derive(); } /// Print help message - virtual void - help(void) { + void + help(void) override { Options::help(); - std::cerr << "\t(unsigned int) default: " << v << std::endl - << "\t\tparameter v" << std::endl - << "\t(unsigned int) default: " << k << std::endl - << "\t\tparameter k" << std::endl - << "\t(unsigned int) default: " << lambda << std::endl - << "\t\tparameter lambda" << std::endl; + std::cerr << "\t(unsigned int) default: " << v << '\n' + << "\t\tparameter v" << '\n' + << "\t(unsigned int) default: " << k << '\n' + << "\t\tparameter k" << '\n' + << "\t(unsigned int) default: " << lambda << '\n' + << "\t\tparameter lambda" << '\n'; } }; @@ -141,17 +141,17 @@ class BIBD : public Script { } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tBIBD(" << opt.v << "," << opt.k << "," << opt.lambda << ")" << std::endl; + void + print(std::ostream& os) const override { + os << "\tBIBD(" << opt.v << "," << opt.k << "," << opt.lambda << ")" << '\n'; Matrix p(_p, opt.b, opt.v); for (int i = 0; i < opt.v; i++) { os << "\t\t"; for (int j = 0; j < opt.b; j++) os << p(j, i) << " "; - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } /// Constructor for cloning \a s @@ -160,8 +160,8 @@ class BIBD : public Script { } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new BIBD(*this); } }; diff --git a/examples/bin-packing.cpp b/examples/bin-packing.cpp index bd8b533c5f..a0c95f9bd9 100644 --- a/examples/bin-packing.cpp +++ b/examples/bin-packing.cpp @@ -146,26 +146,29 @@ namespace { int u = 0; for (int i = 0; i < n; i++) { + const int item_size = size(i); int j = 0; // Skip bins with insufficient free space - while (f[j] < size(i)) + while ((j < n) && (f[j] < item_size)) j++; + // Every instance item fits in an empty bin. + assert(j < n); if (j > u) { // A new bin is needed u = j; - f[u] -= size(i); + f[u] -= item_size; } else { // The slack of the best-fit bin int b = j++; - int s = f[b] - size(i); + int s = f[b] - item_size; while (j <= u) { - if ((f[j] >= size(i)) && (f[j] - size(i) < s)) { + if ((f[j] >= item_size) && (f[j] - item_size < s)) { b = j; - s = f[b] - size(i); + s = f[b] - item_size; } j++; } - f[b] -= size(i); + f[b] -= item_size; } } delete[] f; @@ -241,15 +244,15 @@ class CDBF : public Brancher { same[k] = s[k]; } /// Archive into \a e - virtual void - archive(Archive& e) const { + void + archive(Archive& e) const override { Gecode::Choice::archive(e); e << alternatives() << item << n_same; for (int i = n_same; i--;) e << same[i]; } /// Destructor - virtual ~Choice(void) { + ~Choice(void) override { heap.free(same, n_same); } }; @@ -271,21 +274,21 @@ class CDBF : public Brancher { bin.update(home, cdbf.bin); } /// Copy brancher - virtual Actor* - copy(Space& home) { + Actor* + copy(Space& home) override { return new (home) CDBF(home, *this); } /// Delete brancher and return its size - virtual size_t - dispose(Space& home) { + size_t + dispose(Space& home) override { home.ignore(*this, AP_DISPOSE); size.~IntSharedArray(); (void)Brancher::dispose(home); return sizeof(*this); } /// Check status of brancher, return true if alternatives left - virtual bool - status(const Space&) const { + bool + status(const Space&) const override { for (int i = item; i < bin.size(); i++) if (!bin[i].assigned()) { item = i; @@ -294,8 +297,8 @@ class CDBF : public Brancher { return false; } /// Return choice - virtual Gecode::Choice* - choice(Space&) { + Gecode::Choice* + choice(Space&) override { assert(!bin[item].assigned()); int n = bin.size(), m = load.size(); @@ -349,8 +352,8 @@ class CDBF : public Brancher { return new Choice(*this, 2, item, same, n_same); } /// Return choice - virtual const Gecode::Choice* - choice(const Space&, Archive& e) { + const Gecode::Choice* + choice(const Space&, Archive& e) override { int alt, item, n_same; e >> alt >> item >> n_same; Region re; @@ -360,8 +363,8 @@ class CDBF : public Brancher { return new Choice(*this, alt, item, same, n_same); } /// Perform commit for choice \a _c and alternative \a a - virtual ExecStatus - commit(Space& home, const Gecode::Choice& _c, unsigned int a) { + ExecStatus + commit(Space& home, const Gecode::Choice& _c, unsigned int a) override { const Choice& c = static_cast(_c); // This catches also the case that the choice has a single aternative only if (a == 0) { @@ -379,8 +382,8 @@ class CDBF : public Brancher { return ES_OK; } /// Print explanation - virtual void - print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const { + void + print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const override { const Choice& c = static_cast(_c); if (a == 0) { o << "bin[" << c.item << "] = " << c.same[0]; @@ -470,7 +473,7 @@ class BinPacking : public IntMinimizeScript { linear(*this, sizes, x.row(j), IRT_EQ, load[j]); } break; case MODEL_PACKING: - binpacking(*this, load, bin, sizes); + bin_packing(*this, load, bin, sizes); break; } @@ -506,8 +509,8 @@ class BinPacking : public IntMinimizeScript { } } /// Return cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return bins; } /// Constructor for cloning \a s @@ -517,16 +520,16 @@ class BinPacking : public IntMinimizeScript { bins.update(*this, s.bins); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new BinPacking(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { int n = bin.size(); int m = load.size(); - os << "Bins used: " << bins << " (from " << m << " bins)." << std::endl; + os << "Bins used: " << bins << " (from " << m << " bins)." << '\n'; for (int j = 0; j < m; j++) { bool fst = true; os << "\t[" << j << "]={"; @@ -539,13 +542,13 @@ class BinPacking : public IntMinimizeScript { } os << i; } - os << "} #" << load[j] << std::endl; + os << "} #" << load[j] << '\n'; } if (!bin.assigned()) { - os << std::endl << "Unpacked items:" << std::endl; + os << '\n' << "Unpacked items:" << '\n'; for (int i = 0; i < n; i++) if (!bin[i].assigned()) - os << "\t[" << i << "] = " << bin[i] << std::endl; + os << "\t[" << i << "] = " << bin[i] << '\n'; } } }; @@ -566,7 +569,7 @@ main(int argc, char* argv[]) { opt.solutions(0); opt.parse(argc, argv); if (!Spec(opt.instance()).valid()) { - std::cerr << "Error: unknown instance" << std::endl; + std::cerr << "Error: unknown instance" << '\n'; return 1; } IntMinimizeScript::run(opt); diff --git a/examples/black-hole.cpp b/examples/black-hole.cpp index 0153ab38f0..38c3dd016f 100644 --- a/examples/black-hole.cpp +++ b/examples/black-hole.cpp @@ -137,14 +137,14 @@ class BlackHole : public Script { // between two consecutive cards is 1 or 12. if (opt.propagation() == PROPAGATION_REIFIED) { // Build table for accessing the rank of a card - IntArgs modtable(52); + IntArgs modulo_table(52); for (int i = 0; i < 52; ++i) { - modtable[i] = i % 13; + modulo_table[i] = i % 13; } for (int i = 0; i < 51; ++i) { IntVar x1(*this, 0, 12), x2(*this, 0, 12); - element(*this, modtable, x[i], x1); - element(*this, modtable, x[i + 1], x2); + element(*this, modulo_table, x[i], x1); + element(*this, modulo_table, x[i + 1], x2); const int dr[2] = {1, 12}; IntVar diff(*this, IntSet(dr, 2)); rel(*this, abs(x1 - x2) == diff, IPL_DOM); @@ -252,30 +252,30 @@ class BlackHole : public Script { return v; } /// Print instance and solution - virtual void - print(std::ostream& os) const { - os << "Layout:" << std::endl; + void + print(std::ostream& os) const override { + os << "Layout:" << '\n'; for (int i = 0; i < 17; i++) { for (int j = 0; j < 3; j++) os << card(layout[i][j]) << " "; if ((i + 1) % 3 == 0) - os << std::endl; + os << '\n'; else os << " \t"; } - os << std::endl << std::endl; + os << '\n' << '\n'; - os << "Solution:" << std::endl; + os << "Solution:" << '\n'; for (int i = 0; i < 52; ++i) { if (x[i].assigned()) os << card(x[i].val()) << " "; else os << " "; if ((i + 1) % 13 == 0) - os << std::endl; + os << '\n'; } - os << std::endl; - os << std::endl; + os << '\n'; + os << '\n'; } /// Constructor for cloning \a s @@ -284,8 +284,8 @@ class BlackHole : public Script { y.update(*this, s.y); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new BlackHole(*this); } }; diff --git a/examples/car-sequencing.cpp b/examples/car-sequencing.cpp index dada00549c..6436695ab1 100644 --- a/examples/car-sequencing.cpp +++ b/examples/car-sequencing.cpp @@ -55,13 +55,13 @@ namespace { class CarOptions : public SizeOptions { private: /// Max slack parameter - Driver::UnsignedIntOption _maxstall; + Driver::UnsignedIntOption _max_stalls; public: /// Initialize options for example with name \a s - CarOptions(const char* s) : SizeOptions(s), _maxstall("maxstall", "Maximum numbere of stalls", 30) { + CarOptions(const char* s) : SizeOptions(s), _max_stalls("maxstall", "Maximum numbere of stalls", 30) { // Add options - add(_maxstall); + add(_max_stalls); } /// Parse options from arguments \a argv (number is \a argc) void @@ -70,8 +70,8 @@ namespace { } /// Get max stalls int - maxstall(void) const { - return _maxstall.value(); + max_stalls(void) const { + return _max_stalls.value(); } }; @@ -108,9 +108,9 @@ namespace { /// Constructor for rewriting \a p during cloning PushToEnd(Space& home, Propagator& p, ViewArray& x0, View y0, int val0); /// Copy propagator during cloning - virtual Actor* copy(Space& home); + Actor* copy(Space& home) override; /// Perform propagation - virtual ExecStatus propagate(Space& home, const ModEventDelta& med); + ExecStatus propagate(Space& home, const ModEventDelta& med) override; /// Post propagator static ExecStatus post(Space& home, ViewArray& x0, View y0, int val0); }; @@ -180,7 +180,7 @@ namespace { /** \brief Post PushToEnd propagator. */ void - pushtoend(Space& home, IntVarArgs x, IntVar y, int val) { + push_to_end(Space& home, const IntVarArgs& x, IntVar y, int val) { ViewArray vx(home, x); Int::IntView vy(y); GECODE_ES_FAIL(PushToEnd::post(home, vx, vy, val)); @@ -216,88 +216,89 @@ class CarSequencing : public Script { /// Problem number const int problem; /// Number of cars - const int ncars; + const int car_count; /// Number of options - const int noptions; + const int option_count; /// Number of classes - const int nclasses; + const int class_count; /// Maximum number of stalls - const int maxstall; + const int max_stalls; /// Stall number - const int stallval; + const int stall_value; /// End number - const int endval; + const int end_value; /// Number of stalls (cost to minimize) - IntVar nstall; + IntVar stall_count; /// Number of end markers - IntVar nend; + IntVar end_count; /// Sequence of cars produced IntVarArray s; public: /// Initial model CarSequencing(const CarOptions& opt) - : Script(opt), problem(opt.size()), ncars(problems[problem][0]), noptions(problems[problem][1]), - nclasses(problems[problem][2]), maxstall(opt.maxstall()), stallval(nclasses), endval(nclasses + 1), - nstall(*this, 0, maxstall), nend(*this, 0, maxstall), s(*this, ncars + maxstall, 0, nclasses + 1) { + : Script(opt), problem(opt.size()), car_count(problems[problem][0]), option_count(problems[problem][1]), + class_count(problems[problem][2]), max_stalls(opt.max_stalls()), stall_value(class_count), + end_value(class_count + 1), stall_count(*this, 0, max_stalls), end_count(*this, 0, max_stalls), + s(*this, car_count + max_stalls, 0, class_count + 1) { // Read problem - const int* probit = problems[problem] + 3; + const int* problem_cursor = problems[problem] + 3; // Sequence requirements for the options. - IntArgs max(noptions), block(noptions); - for (int i = 0; i < noptions; ++i) { - max[i] = *probit++; + IntArgs max(option_count), block(option_count); + for (int i = 0; i < option_count; ++i) { + max[i] = *problem_cursor++; } - for (int i = 0; i < noptions; ++i) { - block[i] = *probit++; + for (int i = 0; i < option_count; ++i) { + block[i] = *problem_cursor++; } // Number of cars per class - IntArgs ncc(nclasses); + IntArgs ncc(class_count); // What classes require an option - IntSetArgs classes(noptions); - int** cdata = new int*[noptions]; - for (int i = noptions; i--;) - cdata[i] = new int[nclasses]; - int* n = new int[noptions]; - for (int i = noptions; i--;) + IntSetArgs classes(option_count); + int** class_data = new int*[option_count]; + for (int i = option_count; i--;) + class_data[i] = new int[class_count]; + int* n = new int[option_count]; + for (int i = option_count; i--;) n[i] = 0; // Read data - for (int c = 0; c < nclasses; ++c) { - probit++; - ncc[c] = *probit++; - for (int o = 0; o < noptions; ++o) { - if (*probit++) { - cdata[o][n[o]++] = c; + for (int c = 0; c < class_count; ++c) { + problem_cursor++; + ncc[c] = *problem_cursor++; + for (int o = 0; o < option_count; ++o) { + if (*problem_cursor++) { + class_data[o][n[o]++] = c; } } } // Transfer specification data to int-sets - for (int o = noptions; o--;) { - classes[o] = IntSet(cdata[o], n[o]); - delete[] cdata[o]; + for (int o = option_count; o--;) { + classes[o] = IntSet(class_data[o], n[o]); + delete[] class_data[o]; } - delete[] cdata; + delete[] class_data; delete[] n; // Count the cars { - IntSetArgs c(nclasses + 2); - for (int i = nclasses; i--;) { + IntSetArgs c(class_count + 2); + for (int i = class_count; i--;) { c[i] = IntSet(ncc[i], ncc[i]); } - c[stallval] = IntSet(0, maxstall); - c[endval] = IntSet(0, maxstall); + c[stall_value] = IntSet(0, max_stalls); + c[end_value] = IntSet(0, max_stalls); count(*this, s, c); } // Count number of end and stalls - count(*this, s, stallval, IRT_EQ, nstall); - count(*this, s, endval, IRT_EQ, nend); - rel(*this, nstall + nend == maxstall); + count(*this, s, stall_value, IRT_EQ, stall_count); + count(*this, s, end_value, IRT_EQ, end_count); + rel(*this, stall_count + end_count == max_stalls); // Make sure nothing is overloaded IntSet one(1, 1); - for (int o = noptions; o--;) { + for (int o = option_count; o--;) { // sb[i] reflects if car s[i] has option o BoolVarArgs sb(s.size()); for (int i = s.size(); i--;) { @@ -311,20 +312,20 @@ class CarSequencing : public Script { // End-markers located at end only switch (opt.propagation()) { case PROP_REGULAR: { - IntArgs notend(nclasses), notstallend(nclasses + 1); - for (int i = nclasses; i--;) { - notend[i] = i; - notstallend[i] = i; + IntArgs class_values(class_count), class_or_stall_values(class_count + 1); + for (int i = class_count; i--;) { + class_values[i] = i; + class_or_stall_values[i] = i; } - notstallend[nclasses] = stallval; - REG r = *REG(notend) + REG(notstallend) + *REG(endval); + class_or_stall_values[class_count] = stall_value; + REG r = *REG(class_values) + REG(class_or_stall_values) + *REG(end_value); extensional(*this, s, r); - for (int pos = s.size() - 1, i = 0; i < maxstall; ++i, --pos) { - rel(*this, (nend > i) >> (s[pos] == endval)); + for (int pos = s.size() - 1, i = 0; i < max_stalls; ++i, --pos) { + rel(*this, (end_count > i) >> (s[pos] == end_value)); } } break; case PROP_CUSTOM: { - pushtoend(*this, s, nend, endval); + push_to_end(*this, s, end_count, end_value); } break; } @@ -352,33 +353,33 @@ class CarSequencing : public Script { } /// Return cost - virtual void - constrain(const Space& _best) { + void + constrain(const Space& _best) override { const CarSequencing& best = static_cast(_best); - rel(*this, nstall, IRT_LE, best.nstall.val()); + rel(*this, stall_count, IRT_LT, best.stall_count.val()); } using Script::compare; /// Compare objective values - virtual SpaceComparison - compare(const Space& _other) const { + SpaceComparison + compare(const Space& _other) const override { const CarSequencing& other = static_cast(_other); - return compare_int(nstall.val(), other.nstall.val(), Sense::Minimize); + return compare_int(stall_count.val(), other.stall_count.val(), Sense::Minimize); } /// Print solution - virtual void - print(std::ostream& os) const { - int width = nclasses > 9 ? 2 : 1; - const char* space = nclasses > 9 ? " " : ""; - os << "Stall slots=" << nstall << ", End slots=" << nend << std::endl; + void + print(std::ostream& os) const override { + int width = class_count > 9 ? 2 : 1; + const char* space = class_count > 9 ? " " : ""; + os << "Stall slots=" << stall_count << ", End slots=" << end_count << '\n'; int i = 0; for (; i < s.size(); ++i) { if (s[i].assigned()) { int v = s[i].val(); - if (v == endval) + if (v == end_value) break; - if (v == stallval) + if (v == stall_value) os << space << "_ "; else os << std::setw(width) << v << " "; @@ -386,24 +387,24 @@ class CarSequencing : public Script { os << space << "? "; } if ((i + 1) % 20 == 0) - os << std::endl; + os << '\n'; } if (i % 20) - os << std::endl; - os << std::endl; + os << '\n'; + os << '\n'; } /// Constructor for cloning \a s CarSequencing(CarSequencing& cs) - : Script(cs), problem(cs.problem), ncars(cs.ncars), noptions(cs.noptions), nclasses(cs.nclasses), - maxstall(cs.maxstall), stallval(cs.stallval), endval(cs.endval) { - nstall.update(*this, cs.nstall); - nend.update(*this, cs.nend); + : Script(cs), problem(cs.problem), car_count(cs.car_count), option_count(cs.option_count), + class_count(cs.class_count), max_stalls(cs.max_stalls), stall_value(cs.stall_value), end_value(cs.end_value) { + stall_count.update(*this, cs.stall_count); + end_count.update(*this, cs.end_count); s.update(*this, cs.s); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new CarSequencing(*this); } }; @@ -424,7 +425,7 @@ main(int argc, char* argv[]) { opt.propagation(CarSequencing::PROP_CUSTOM, "custom"); opt.parse(argc, argv); if (opt.size() >= n_problems) { - std::cerr << "Error: size must be between 0 and " << n_problems - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_problems - 1 << '\n'; return 1; } diff --git a/examples/cartesian-heart.cpp b/examples/cartesian-heart.cpp index 0143256143..3c5db3894e 100644 --- a/examples/cartesian-heart.cpp +++ b/examples/cartesian-heart.cpp @@ -81,13 +81,13 @@ class CartesianHeart : public Script { f.update(*this, p.f); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new CartesianHeart(*this); } /// Add constraints to current model to get next solution (not too close) - virtual void - constrain(const Space& _b) { + void + constrain(const Space& _b) override { const CartesianHeart& b = static_cast(_b); rel(*this, (f[0] >= (b.f[0].max() + step)) || (f[1] >= (b.f[1].max() + step)) || (f[1] <= (b.f[1].min() - step))); @@ -101,17 +101,17 @@ class CartesianHeart : public Script { * is far enough from \a other to satisfy constrain, so parallel search keeps * the same kind of solutions as sequential search. This is not an order. */ - virtual SpaceComparison - compare(const Space& _other) const { + SpaceComparison + compare(const Space& _other) const override { const CartesianHeart& b = static_cast(_other); bool apart = (f[0].min() >= (b.f[0].max() + step)) || (f[1].min() >= (b.f[1].max() + step)) || (f[1].max() <= (b.f[1].min() - step)); return apart ? SpaceComparison::Better : SpaceComparison::Worse; } /// Print solution coordinates - virtual void - print(std::ostream& os) const { - os << "XY " << f[0].med() << " " << f[1].med() << std::endl; + void + print(std::ostream& os) const override { + os << "XY " << f[0].med() << " " << f[1].med() << '\n'; } }; diff --git a/examples/colored-matrix.cpp b/examples/colored-matrix.cpp index 6a4070d0e1..b4c25de9f6 100644 --- a/examples/colored-matrix.cpp +++ b/examples/colored-matrix.cpp @@ -234,9 +234,9 @@ class ColoredMatrix : public IntMinimizeScript { switch (opt.distinct_except_0()) { case DISTINCT_EXCEPT_0_REIFIED: for (int i = v.size(); i--;) { - BoolVar viIsZero = expr(*this, v[i] == 0); + BoolVar vi_is_zero = expr(*this, v[i] == 0); for (int j = i; j--;) { - rel(*this, viIsZero || (v[i] != v[j])); + rel(*this, vi_is_zero || (v[i] != v[j])); } } break; @@ -414,10 +414,10 @@ class ColoredMatrix : public IntMinimizeScript { // Lexical order for all columns and rows (all are interchangeable) if (opt.symmetry() & SYMMETRY_MATRIX) { for (int r = 0; r < height - 1; ++r) { - rel(*this, m.row(r), IRT_LE, m.row(r + 1)); + rel(*this, m.row(r), IRT_LT, m.row(r + 1)); } for (int c = 0; c < width - 1; ++c) { - rel(*this, m.col(c), IRT_LE, m.col(c + 1)); + rel(*this, m.col(c), IRT_LT, m.col(c + 1)); } } @@ -427,29 +427,29 @@ class ColoredMatrix : public IntMinimizeScript { } } - branch(*this, x, tiebreak(INT_VAR_MIN_MIN(), INT_VAR_SIZE_MIN()), INT_VAL_MIN()); + branch(*this, x, tie_break(INT_VAR_MIN_MIN(), INT_VAR_SIZE_MIN()), INT_VAL_MIN()); } /// Return cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return max_color; } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Matrix m(x, width, height); for (int r = 0; r < height; ++r) { os << "\t"; for (int c = 0; c < width; ++c) { os << m(c, r) << " "; } - os << std::endl; + os << '\n'; } - os << std::endl; - os << "\tmax color: " << max_color << std::endl; - os << std::endl; + os << '\n'; + os << "\tmax color: " << max_color << '\n'; + os << '\n'; } /// Constructor for cloning \a s @@ -459,8 +459,8 @@ class ColoredMatrix : public IntMinimizeScript { max_color.update(*this, s.max_color); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new ColoredMatrix(*this); } }; diff --git a/examples/common-pattern.cpp b/examples/common-pattern.cpp index 5c137661b1..961361601f 100644 --- a/examples/common-pattern.cpp +++ b/examples/common-pattern.cpp @@ -253,7 +253,7 @@ class CommonPattern : public IntMaximizeScript { } } os << " (length " << pattern.length() << ", support " << frequency << '/' << database.ends.size() << ")" - << std::endl; + << '\n'; } }; @@ -271,7 +271,7 @@ main(int argc, char* argv[]) { try { opt.read(); } catch (const std::invalid_argument& error) { - std::cerr << error.what() << std::endl; + std::cerr << error.what() << '\n'; return 1; } if (opt.search() == CommonPattern::SEARCH_DFS) diff --git a/examples/crew.cpp b/examples/crew.cpp index 8b32abe83f..cde919c25c 100644 --- a/examples/crew.cpp +++ b/examples/crew.cpp @@ -41,28 +41,28 @@ using namespace Gecode; namespace { /// The airline employees typedef enum { - Tom, - David, - Jeremy, - Ron, - Joe, - Bill, - Fred, - Bob, - Mario, - Ed, - Carol, - Janet, - Tracy, - Marilyn, - Carolyn, - Cathy, - Inez, - Jean, - Heather, - Juliet + TOM, + DAVID, + JEREMY, + RON, + JOE, + BILL, + FRED, + BOB, + MARIO, + ED, + CAROL, + JANET, + TRACY, + MARILYN, + CAROLYN, + CATHY, + INEZ, + JEAN, + HEATHER, + JULIET } Employee; - const int noOfEmployees = Juliet + 1; + const int no_of_employees = JULIET + 1; /// A flight to schedule struct Flight { @@ -74,19 +74,19 @@ namespace { int german; ///< How many German speaking employees are required }; - const char* employeeToName(Employee e); + const char* employee_to_name(Employee e); extern const int stewards[]; - extern const int noOfStewards; + extern const int no_of_stewards; extern const int hostesses[]; - extern const int noOfHostesses; - extern const int spanishSpeaking[]; - extern const int noOfSpanishSpeaking; - extern const int frenchSpeaking[]; - extern const int noOfFrenchSpeaking; - extern const int germanSpeaking[]; - extern const int noOfGermanSpeaking; - extern const Flight requiredCrew[]; - extern const int noOfFlights; + extern const int no_of_hostesses; + extern const int spanish_speaking[]; + extern const int no_of_spanish_speaking; + extern const int french_speaking[]; + extern const int no_of_french_speaking; + extern const int german_speaking[]; + extern const int no_of_german_speaking; + extern const Flight required_crew[]; + extern const int no_of_flights; } // namespace /** @@ -105,61 +105,61 @@ class Crew : public Script { SetVarArray flight; /// The actual model - Crew(const Options& opt) : Script(opt), flight(*this, noOfFlights, IntSet::empty, 0, noOfEmployees - 1) { - IntSet stewardsDS(stewards, noOfStewards); - IntSet hostessesDS(hostesses, noOfHostesses); - IntSet spanishDS(spanishSpeaking, noOfSpanishSpeaking); - IntSet frenchDS(frenchSpeaking, noOfFrenchSpeaking); - IntSet germanDS(germanSpeaking, noOfGermanSpeaking); + Crew(const Options& opt) : Script(opt), flight(*this, no_of_flights, IntSet::empty, 0, no_of_employees - 1) { + IntSet stewards_ds(stewards, no_of_stewards); + IntSet hostesses_ds(hostesses, no_of_hostesses); + IntSet spanish_ds(spanish_speaking, no_of_spanish_speaking); + IntSet french_ds(french_speaking, no_of_french_speaking); + IntSet german_ds(german_speaking, no_of_german_speaking); - for (int i = 0; i < noOfFlights; i++) { + for (int i = 0; i < no_of_flights; i++) { // The flight has staff as required by the specification - rel(*this, cardinality(flight[i]) == requiredCrew[i].staff); + rel(*this, cardinality(flight[i]) == required_crew[i].staff); // Enough members of different categories are on board - rel(*this, cardinality(flight[i] & stewardsDS) >= requiredCrew[i].stewards); - rel(*this, cardinality(flight[i] & hostessesDS) >= requiredCrew[i].hostesses); - rel(*this, cardinality(flight[i] & spanishDS) >= requiredCrew[i].spanish); - rel(*this, cardinality(flight[i] & frenchDS) >= requiredCrew[i].french); - rel(*this, cardinality(flight[i] & germanDS) >= requiredCrew[i].german); + rel(*this, cardinality(flight[i] & stewards_ds) >= required_crew[i].stewards); + rel(*this, cardinality(flight[i] & hostesses_ds) >= required_crew[i].hostesses); + rel(*this, cardinality(flight[i] & spanish_ds) >= required_crew[i].spanish); + rel(*this, cardinality(flight[i] & french_ds) >= required_crew[i].french); + rel(*this, cardinality(flight[i] & german_ds) >= required_crew[i].german); } // No crew member of flight i works on flights i+1 and i+2 - for (int i = 0; i < noOfFlights - 2; i++) { + for (int i = 0; i < no_of_flights - 2; i++) { rel(*this, flight[i] || flight[i + 1]); rel(*this, flight[i] || flight[i + 2]); } - rel(*this, flight[noOfFlights - 2] || flight[noOfFlights - 1]); + rel(*this, flight[no_of_flights - 2] || flight[no_of_flights - 1]); branch(*this, flight, SET_VAR_NONE(), SET_VAL_MIN_INC()); } /// Print solution - virtual void - print(std::ostream& os) const { - for (int i = 0; i < noOfFlights; i++) { - os << "\tFlight " << i + 1 << ":" << std::endl; - os << "\t\tCrew\tStew.\tHost.\tFrench\tSpanish\tGerman" << std::endl << "\t"; - os << "\t" << requiredCrew[i].staff << "\t" << requiredCrew[i].stewards << "\t" << requiredCrew[i].hostesses - << "\t" << requiredCrew[i].spanish << "\t" << requiredCrew[i].french << "\t" << requiredCrew[i].german - << std::endl; + void + print(std::ostream& os) const override { + for (int i = 0; i < no_of_flights; i++) { + os << "\tFlight " << i + 1 << ":" << '\n'; + os << "\t\tCrew\tStew.\tHost.\tFrench\tSpanish\tGerman" << '\n' << "\t"; + os << "\t" << required_crew[i].staff << "\t" << required_crew[i].stewards << "\t" + << required_crew[i].hostesses << "\t" << required_crew[i].spanish << "\t" << required_crew[i].french + << "\t" << required_crew[i].german << '\n'; - os << "\t\tSchedule:" << std::endl << "\t\t"; + os << "\t\tSchedule:" << '\n' << "\t\t"; if (flight[i].assigned()) { for (SetVarGlbValues d(flight[i]); d(); ++d) { - os << employeeToName(static_cast(d.val())) << " "; + os << employee_to_name(static_cast(d.val())) << " "; } } else { os << "\tRequired: "; for (SetVarGlbValues d(flight[i]); d(); ++d) { - os << employeeToName(static_cast(d.val())) << " "; + os << employee_to_name(static_cast(d.val())) << " "; } - os << std::endl << "\t\t\tPossible: "; + os << '\n' << "\t\t\tPossible: "; for (SetVarUnknownValues d(flight[i]); d(); ++d) { - os << employeeToName(static_cast(d.val())) << " "; + os << employee_to_name(static_cast(d.val())) << " "; } } - os << std::endl << std::endl; + os << '\n' << '\n'; } } @@ -168,8 +168,8 @@ class Crew : public Script { flight.update(*this, s.flight); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Crew(*this); } }; @@ -190,47 +190,47 @@ namespace { /// Return name of employee \a e as a string const char* - employeeToName(Employee e) { + employee_to_name(Employee e) { switch (e) { - case Tom: + case TOM: return "Tom"; - case David: + case DAVID: return "David"; - case Jeremy: + case JEREMY: return "Jeremy"; - case Ron: + case RON: return "Ron"; - case Joe: + case JOE: return "Joe"; - case Bill: + case BILL: return "Bill"; - case Fred: + case FRED: return "Fred"; - case Bob: + case BOB: return "Bob"; - case Mario: + case MARIO: return "Mario"; - case Ed: + case ED: return "Ed"; - case Carol: + case CAROL: return "Carol"; - case Janet: + case JANET: return "Janet"; - case Tracy: + case TRACY: return "Tracy"; - case Marilyn: + case MARILYN: return "Marilyn"; - case Carolyn: + case CAROLYN: return "Carolyn"; - case Cathy: + case CATHY: return "Cathy"; - case Inez: + case INEZ: return "Inez"; - case Jean: + case JEAN: return "Jean"; - case Heather: + case HEATHER: return "Heather"; - case Juliet: + case JULIET: return "Juliet"; default: GECODE_NEVER; @@ -240,33 +240,33 @@ namespace { // these have to be sorted! /// The stewards - const int stewards[] = {Tom, David, Jeremy, Ron, Joe, Bill, Fred, Bob, Mario, Ed}; + const int stewards[] = {TOM, DAVID, JEREMY, RON, JOE, BILL, FRED, BOB, MARIO, ED}; /// The number of stewards - const int noOfStewards = sizeof(stewards) / sizeof(int); + const int no_of_stewards = sizeof(stewards) / sizeof(int); /// The hostesses - const int hostesses[] = {Carol, Janet, Tracy, Marilyn, Carolyn, Cathy, Inez, Jean, Heather, Juliet}; + const int hostesses[] = {CAROL, JANET, TRACY, MARILYN, CAROLYN, CATHY, INEZ, JEAN, HEATHER, JULIET}; /// The number of hostesses - const int noOfHostesses = sizeof(hostesses) / sizeof(int); + const int no_of_hostesses = sizeof(hostesses) / sizeof(int); /// The French speaking employees - const int frenchSpeaking[] = {Bill, Inez, Jean, Juliet}; + const int french_speaking[] = {BILL, INEZ, JEAN, JULIET}; /// The number of French speaking employees - const int noOfFrenchSpeaking = sizeof(frenchSpeaking) / sizeof(int); + const int no_of_french_speaking = sizeof(french_speaking) / sizeof(int); /// The German speaking employees - const int germanSpeaking[] = {Tom, Jeremy, Mario, Cathy, Juliet}; + const int german_speaking[] = {TOM, JEREMY, MARIO, CATHY, JULIET}; /// The number of German speaking employees - const int noOfGermanSpeaking = sizeof(germanSpeaking) / sizeof(int); + const int no_of_german_speaking = sizeof(german_speaking) / sizeof(int); /// The Spanish speaking employees - const int spanishSpeaking[] = {Joe, Bill, Fred, Mario, Marilyn, Inez, Heather}; + const int spanish_speaking[] = {JOE, BILL, FRED, MARIO, MARILYN, INEZ, HEATHER}; /// The number of Spanish speaking employees - const int noOfSpanishSpeaking = sizeof(spanishSpeaking) / sizeof(int); + const int no_of_spanish_speaking = sizeof(spanish_speaking) / sizeof(int); /// The flights to schedule - const Flight requiredCrew[] = {{4, 1, 1, 1, 1, 1}, {5, 1, 1, 1, 1, 1}, {5, 1, 1, 1, 1, 1}, {6, 2, 2, 1, 1, 1}, - {7, 3, 3, 1, 1, 1}, {4, 1, 1, 1, 1, 1}, {5, 1, 1, 1, 1, 1}, {6, 1, 1, 1, 1, 1}, - {6, 2, 2, 1, 1, 1}, {7, 3, 3, 1, 1, 1}}; + const Flight required_crew[] = {{4, 1, 1, 1, 1, 1}, {5, 1, 1, 1, 1, 1}, {5, 1, 1, 1, 1, 1}, {6, 2, 2, 1, 1, 1}, + {7, 3, 3, 1, 1, 1}, {4, 1, 1, 1, 1, 1}, {5, 1, 1, 1, 1, 1}, {6, 1, 1, 1, 1, 1}, + {6, 2, 2, 1, 1, 1}, {7, 3, 3, 1, 1, 1}}; /// The number of flights to schedule - const int noOfFlights = sizeof(requiredCrew) / sizeof(Flight); + const int no_of_flights = sizeof(required_crew) / sizeof(Flight); } // namespace // STATISTICS: example-any diff --git a/examples/crossword.cpp b/examples/crossword.cpp index 8575d252f7..dd101126d9 100644 --- a/examples/crossword.cpp +++ b/examples/crossword.cpp @@ -204,57 +204,57 @@ class Crossword : public Script { switch (opt.branching()) { case BRANCH_WORDS_AFC: // Branch by assigning words - branch(*this, allwords, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_SPLIT_MIN(), nullptr, &printwords); + branch(*this, allwords, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_SPLIT_MIN(), nullptr, &print_words); break; case BRANCH_LETTERS_AFC: // Branch by assigning letters - branch(*this, letters, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN(), nullptr, &printletters); + branch(*this, letters, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN(), nullptr, &print_letters); break; case BRANCH_LETTERS_AFC_ALL: // Branch by assigning letters (try all letters) - branch(*this, letters, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VALUES_MIN(), nullptr, &printletters); + branch(*this, letters, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VALUES_MIN(), nullptr, &print_letters); break; case BRANCH_WORDS_ACTION: // Branch by assigning words - branch(*this, allwords, INT_VAR_ACTION_SIZE_MAX(opt.decay()), INT_VAL_SPLIT_MIN(), nullptr, &printwords); + branch(*this, allwords, INT_VAR_ACTION_SIZE_MAX(opt.decay()), INT_VAL_SPLIT_MIN(), nullptr, &print_words); break; case BRANCH_LETTERS_ACTION: // Branch by assigning letters - branch(*this, letters, INT_VAR_ACTION_SIZE_MAX(opt.decay()), INT_VAL_MIN(), nullptr, &printletters); + branch(*this, letters, INT_VAR_ACTION_SIZE_MAX(opt.decay()), INT_VAL_MIN(), nullptr, &print_letters); break; case BRANCH_LETTERS_ACTION_ALL: // Branch by assigning letters (try all letters) - branch(*this, letters, INT_VAR_ACTION_SIZE_MAX(opt.decay()), INT_VALUES_MIN(), nullptr, &printletters); + branch(*this, letters, INT_VAR_ACTION_SIZE_MAX(opt.decay()), INT_VALUES_MIN(), nullptr, &print_letters); break; case BRANCH_WORDS_CHB: // Branch by assigning words - branch(*this, allwords, INT_VAR_CHB_SIZE_MAX(), INT_VAL_SPLIT_MIN(), nullptr, &printwords); + branch(*this, allwords, INT_VAR_CHB_SIZE_MAX(), INT_VAL_SPLIT_MIN(), nullptr, &print_words); break; case BRANCH_LETTERS_CHB: // Branch by assigning letters - branch(*this, letters, INT_VAR_CHB_SIZE_MAX(), INT_VAL_MIN(), nullptr, &printletters); + branch(*this, letters, INT_VAR_CHB_SIZE_MAX(), INT_VAL_MIN(), nullptr, &print_letters); break; case BRANCH_LETTERS_CHB_ALL: // Branch by assigning letters (try all letters) - branch(*this, letters, INT_VAR_CHB_SIZE_MAX(), INT_VALUES_MIN(), nullptr, &printletters); + branch(*this, letters, INT_VAR_CHB_SIZE_MAX(), INT_VALUES_MIN(), nullptr, &print_letters); break; } } /// Print brancher information when branching on letters static void - printletters(const Space& home, const Brancher&, unsigned int a, IntVar, int i, const int& n, std::ostream& os) { + print_letters(const Space& home, const Brancher&, unsigned int a, IntVar, int i, const int& n, std::ostream& os) { const Crossword& c = static_cast(home); int x = i % c.w, y = i / c.w; os << "letters[" << x << "," << y << "] " << ((a == 0) ? "=" : "!=") << " " << static_cast(n); } /// Print brancher information when branching on words static void - printwords(const Space&, const Brancher&, unsigned int a, IntVar, int i, const int& n, std::ostream& os) { + print_words(const Space&, const Brancher&, unsigned int a, IntVar, int i, const int& n, std::ostream& os) { os << "allwords[" << i << "] " << ((a == 0) ? "<=" : ">") << " " << n; } /// Post no-goods, and do not perform a restart when a solution is found void - hub(HubContext& hc) { + hub(HubContext& hc) override { if (hc.engine() == MetaEngine::Restart) { hc.nogoods().post(*this); if (hc.event() == MetaEvent::Solution) @@ -268,13 +268,13 @@ class Crossword : public Script { letters.update(*this, s.letters); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Crossword(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { // Matrix for letters Matrix ml(letters, w, h); for (int i = 0; i < h; i++) { @@ -287,9 +287,9 @@ class Crossword : public Script { os << static_cast(ml(j, i).val()); else os << '?'; - os << std::endl; + os << '\n'; } - os << std::endl << std::endl; + os << '\n' << '\n'; } }; @@ -317,7 +317,7 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); dict.init(opt.file()); if (opt.size() >= n_grids) { - std::cerr << "Error: size must be between 0 and " << n_grids - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_grids - 1 << '\n'; return 1; } Script::run(opt); diff --git a/examples/crowded-chess.cpp b/examples/crowded-chess.cpp index 780cb5cffe..2470cdb1ab 100644 --- a/examples/crowded-chess.cpp +++ b/examples/crowded-chess.cpp @@ -87,8 +87,8 @@ namespace { Bishops(Bishops& s) : Space(s), n(s.n) { k.update(*this, s.k); } - virtual Space* - copy(void) { + Space* + copy(void) override { return new Bishops(*this); } }; @@ -331,14 +331,14 @@ class CrowdedChess : public Script { } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new CrowdedChess(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Matrix m(s, n); char names[PMAX]; names[E] = '.'; @@ -374,9 +374,9 @@ class CrowdedChess : public Script { } } } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } }; @@ -393,7 +393,7 @@ main(int argc, char* argv[]) { opt.size(8); opt.parse(argc, argv); if (opt.size() < 5) { - std::cerr << "Error: size must be at least 5" << std::endl; + std::cerr << "Error: size must be at least 5" << '\n'; return 1; } init_bishops(opt.size()); diff --git a/examples/descartes-folium.cpp b/examples/descartes-folium.cpp index b88bf0ee6e..56288274e3 100644 --- a/examples/descartes-folium.cpp +++ b/examples/descartes-folium.cpp @@ -94,19 +94,19 @@ class DescartesFolium : public FloatMaximizeScript { f.update(*this, p.f); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new DescartesFolium(*this); } /// Cost function - virtual FloatVar - cost(void) const { + FloatVar + cost(void) const override { return f[0]; } /// Print solution coordinates - virtual void - print(std::ostream& os) const { - os << "XY " << f[1].med() << " " << f[2].med() << std::endl; + void + print(std::ostream& os) const override { + os << "XY " << f[1].med() << " " << f[2].med() << '\n'; } }; diff --git a/examples/dominating-queens.cpp b/examples/dominating-queens.cpp index f97092cb6c..17a62a8a6b 100644 --- a/examples/dominating-queens.cpp +++ b/examples/dominating-queens.cpp @@ -112,8 +112,8 @@ class DominatingQueens : public IntMinimizeScript { } /// Return cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return q; } @@ -124,17 +124,18 @@ class DominatingQueens : public IntMinimizeScript { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new DominatingQueens(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tNumber of Queens: " << q << std::endl; - os << "\tBoard: " << b << std::endl; + void + print(std::ostream& os) const override { + os << "\tNumber of Queens: " << q << '\n'; + os << "\tBoard: " << b << '\n'; if (b.assigned()) { + os << std::flush; // Print a nice board bool* placed = new bool[n * n]; for (int i = 0; i < n * n; i++) @@ -145,11 +146,12 @@ class DominatingQueens : public IntMinimizeScript { std::cout << "\t\t"; for (int i = 0; i < n; i++) std::cout << (placed[xy(i, j)] ? 'Q' : '.') << ' '; - std::cout << std::endl; + std::cout << '\n'; } + std::cout << std::flush; delete[] placed; } - os << std::endl; + os << '\n'; } }; diff --git a/examples/domino.cpp b/examples/domino.cpp index 8ddf572cfa..1601dcac25 100644 --- a/examples/domino.cpp +++ b/examples/domino.cpp @@ -106,10 +106,10 @@ class Domino : public Script { IntVarArgs p2(*this, 28, 0, (width + 1) * height - 1); if (opt.propagation() == PROP_ELEMENT) { - int dominoCount = 0; + int domino_count = 0; - int possibleDiffsA[] = {1, width + 1}; - IntSet possibleDiffs(possibleDiffsA, 2); + int possible_diffs_a[] = {1, width + 1}; + IntSet possible_diffs(possible_diffs_a, 2); for (int i = 0; i <= 6; i++) for (int j = i; j <= 6; j++) { @@ -119,25 +119,25 @@ class Domino : public Script { // The separator column makes sure that a field // at the right border is not adjacent to the first field // in the next row. - IntVar diff(*this, possibleDiffs); - abs(*this, expr(*this, p1[dominoCount] - p2[dominoCount]), diff, IPL_DOM); + IntVar diff(*this, possible_diffs); + abs(*this, expr(*this, p1[domino_count] - p2[domino_count]), diff, IPL_DOM); // If the piece is symmetrical, order the locations if (i == j) - rel(*this, p1[dominoCount], IRT_LE, p2[dominoCount]); + rel(*this, p1[domino_count], IRT_LT, p2[domino_count]); // Link the current piece to the board - element(*this, board, p1[dominoCount], i); - element(*this, board, p2[dominoCount], j); + element(*this, board, p1[domino_count], i); + element(*this, board, p2[domino_count], j); // Link the current piece to the array where its // number is stored. - element(*this, x, p1[dominoCount], dominoCount); - element(*this, x, p2[dominoCount], dominoCount); - dominoCount++; + element(*this, x, p1[domino_count], domino_count); + element(*this, x, p2[domino_count], domino_count); + domino_count++; } } else { - int dominoCount = 0; + int domino_count = 0; for (int i = 0; i <= 6; i++) for (int j = i; j <= 6; j++) { @@ -160,13 +160,13 @@ class Domino : public Script { valids |= REG(pos + width + 1) + REG(pos); } } - extensional(*this, IntVarArgs({p1[dominoCount], p2[dominoCount]}), valids); + extensional(*this, IntVarArgs({p1[domino_count], p2[domino_count]}), valids); // Link the current piece to the array where its // number is stored. - element(*this, x, p1[dominoCount], dominoCount); - element(*this, x, p2[dominoCount], dominoCount); - dominoCount++; + element(*this, x, p1[domino_count], domino_count); + element(*this, x, p2[domino_count], domino_count); + domino_count++; } } @@ -181,8 +181,8 @@ class Domino : public Script { } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { for (int h = 0; h < height; ++h) { os << "\t"; for (int w = 0; w < width; ++w) { @@ -190,17 +190,17 @@ class Domino : public Script { char c = val < 10 ? '0' + val : 'A' + (val - 10); os << c; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } /// Constructor for cloning \a s Domino(Domino& s) : Script(s), spec(s.spec), width(s.width), height(s.height) { x.update(*this, s.x); } /// Copy space during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Domino(*this); } }; @@ -217,7 +217,7 @@ main(int argc, char* argv[]) { opt.propagation(Domino::PROP_EXTENSIONAL, "extensional"); opt.parse(argc, argv); if (opt.size() >= n_examples) { - std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_examples - 1 << '\n'; return 1; } Script::run(opt); diff --git a/examples/donald.cpp b/examples/donald.cpp index 393a3aa3ba..243e5ad111 100644 --- a/examples/donald.cpp +++ b/examples/donald.cpp @@ -94,14 +94,14 @@ class Donald : public Script { le.update(*this, s.le); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Donald(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\t" << le << std::endl; + void + print(std::ostream& os) const override { + os << "\t" << le << '\n'; ; } }; diff --git a/examples/efpa.cpp b/examples/efpa.cpp index feb064530d..610ef58ea5 100644 --- a/examples/efpa.cpp +++ b/examples/efpa.cpp @@ -176,7 +176,7 @@ class EFPA : public Script { // Symmetry breaking if (opt.symmetry()) { - IntRelType row_less = d == 0 ? IRT_EQ : IRT_LE; + IntRelType row_less = d == 0 ? IRT_EQ : IRT_LT; // order rows for (int r = 0; r < v - 1; ++r) { rel(*this, cm.row(r), row_less, cm.row(r + 1)); @@ -266,9 +266,9 @@ class EFPA : public Script { rel(*this, perm[1], IRT_NQ, perm[2], cformb); rel(*this, perm[1], IRT_NQ, perm[3], cformb); // Common ordering-constraints - symmetry breaking - rel(*this, perm[0], IRT_LE, perm[1]); - rel(*this, perm[0], IRT_LE, perm[2]); - rel(*this, perm[0], IRT_LE, perm[3]); + rel(*this, perm[0], IRT_LT, perm[1]); + rel(*this, perm[0], IRT_LT, perm[2]); + rel(*this, perm[0], IRT_LT, perm[3]); // Conditional ordering constraint - symmetry breaking for cform 0 rel(*this, (!cformb) >> (perm[2] < perm[3])); } @@ -279,14 +279,14 @@ class EFPA : public Script { } /// Print instance and solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Matrix cm(c, n, v); for (int i = 0; i < v; ++i) { IntVarArgs r = cm.row(i); - os << r << std::endl; + os << r << '\n'; } - os << std::endl; + os << '\n'; } /// Constructor for cloning \a s @@ -295,8 +295,8 @@ class EFPA : public Script { diff.update(*this, s.diff); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new EFPA(*this); } }; diff --git a/examples/eq20.cpp b/examples/eq20.cpp index 60299940b6..e45d0857e0 100644 --- a/examples/eq20.cpp +++ b/examples/eq20.cpp @@ -89,14 +89,14 @@ class Eq20 : public Script { x.update(*this, s.x); } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Eq20(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tx[] = " << x << std::endl; + void + print(std::ostream& os) const override { + os << "\tx[] = " << x << '\n'; } }; diff --git a/examples/fifteen-puzzle.cpp b/examples/fifteen-puzzle.cpp index 5659934cbf..3d0773d5cc 100644 --- a/examples/fifteen-puzzle.cpp +++ b/examples/fifteen-puzzle.cpp @@ -412,6 +412,8 @@ run(PuzzleOptions& opt) { Script::run(opt); else Script::run(opt); + // The guidance lives only in this block + opt.guidance(nullptr); } break; #endif } diff --git a/examples/golden-spiral.cpp b/examples/golden-spiral.cpp index f24cad2845..780d6e6a80 100644 --- a/examples/golden-spiral.cpp +++ b/examples/golden-spiral.cpp @@ -99,19 +99,19 @@ class GoldenSpiral : public FloatMaximizeScript { f.update(*this, p.f); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new GoldenSpiral(*this); } /// Cost function - virtual FloatVar - cost(void) const { + FloatVar + cost(void) const override { return f[0]; } /// Print solution coordinates - virtual void - print(std::ostream& os) const { - os << "XY " << f[1].med() << " " << f[2].med() << std::endl; + void + print(std::ostream& os) const override { + os << "XY " << f[1].med() << " " << f[2].med() << '\n'; } }; diff --git a/examples/golf.cpp b/examples/golf.cpp index 323742d92e..2deba902ba 100644 --- a/examples/golf.cpp +++ b/examples/golf.cpp @@ -111,9 +111,9 @@ class Golf : public Script { Matrix schedule(groups, g, w); // Groups in one week must be disjoint - SetVar allPlayers(*this, 0, g * s - 1, 0, g * s - 1); + SetVar all_players(*this, 0, g * s - 1, 0, g * s - 1); for (int i = 0; i < w; i++) - rel(*this, setdunion(schedule.row(i)) == allPlayers); + rel(*this, set_disjoint_union(schedule.row(i)) == all_players); // No two golfers play in the same group more than once if (opt.propagation() == PROP_SET || opt.propagation() == PROP_MIXED) { @@ -125,12 +125,12 @@ class Golf : public Script { if (opt.propagation() == PROP_INT || opt.propagation() == PROP_MIXED) { // Set up table mapping from pairs (p1,p2) (where p1 schedule(groups, g, w); for (int j = 0; j < w; j++) { - os << "Week " << j << ": " << std::endl << " "; - os << schedule.row(j) << std::endl; + os << "Week " << j << ": " << '\n' << " "; + os << schedule.row(j) << '\n'; } } @@ -218,8 +218,8 @@ class Golf : public Script { groups.update(*this, s.groups); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Golf(*this); } }; diff --git a/examples/golomb-ruler.cpp b/examples/golomb-ruler.cpp index b054cf2ddd..9188095bf9 100644 --- a/examples/golomb-ruler.cpp +++ b/examples/golomb-ruler.cpp @@ -73,7 +73,7 @@ class GolombRuler : public IntMinimizeScript { rel(*this, m[0], IRT_EQ, 0); // Order marks - rel(*this, m, IRT_LE); + rel(*this, m, IRT_LT); // Number of marks and differences const int n = m.size(); @@ -92,21 +92,21 @@ class GolombRuler : public IntMinimizeScript { // Symmetry breaking if (n > 2) - rel(*this, d[0], IRT_LE, d[n_d - 1]); + rel(*this, d[0], IRT_LT, d[n_d - 1]); branch(*this, m, INT_VAR_NONE(), INT_VAL_MIN()); } /// Return cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return m[m.size() - 1]; } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tm[" << m.size() << "] = " << m << std::endl; + void + print(std::ostream& os) const override { + os << "\tm[" << m.size() << "] = " << m << '\n'; } /// Constructor for cloning \a s @@ -114,8 +114,8 @@ class GolombRuler : public IntMinimizeScript { m.update(*this, s.m); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new GolombRuler(*this); } }; diff --git a/examples/graph-color.cpp b/examples/graph-color.cpp index bbe2508f13..e12da862cb 100644 --- a/examples/graph-color.cpp +++ b/examples/graph-color.cpp @@ -282,7 +282,7 @@ class GraphColor : public IntMinimizeScript { branch(*this, v, INT_VAR_SIZE_MIN(), INT_VAL_MIN()); break; case BRANCH_DEGREE: - branch(*this, v, tiebreak(INT_VAR_DEGREE_MAX(), INT_VAR_SIZE_MIN()), INT_VAL_MIN()); + branch(*this, v, tie_break(INT_VAR_DEGREE_MAX(), INT_VAR_SIZE_MIN()), INT_VAL_MIN()); break; case BRANCH_DEGREE_SIZE: branch(*this, v, INT_VAR_DEGREE_SIZE_MAX(), INT_VAL_MIN()); @@ -298,13 +298,13 @@ class GraphColor : public IntMinimizeScript { // Branching while considering value symmetry breaking // (every permutation of color values gives equivalent solutions) Symmetries syms; - syms << ValueSymmetry(IntArgs::create(g.n_v, 0)); + syms << value_symmetry(IntArgs::create(g.n_v, 0)); switch (opt.branching()) { case BRANCH_SIZE: branch(*this, v, INT_VAR_SIZE_MIN(), INT_VAL_MIN(), syms); break; case BRANCH_DEGREE: - branch(*this, v, tiebreak(INT_VAR_DEGREE_MAX(), INT_VAR_SIZE_MIN()), INT_VAL_MIN(), syms); + branch(*this, v, tie_break(INT_VAR_DEGREE_MAX(), INT_VAR_SIZE_MIN()), INT_VAL_MIN(), syms); break; case BRANCH_DEGREE_SIZE: branch(*this, v, INT_VAR_DEGREE_SIZE_MAX(), INT_VAL_MIN(), syms); @@ -319,8 +319,8 @@ class GraphColor : public IntMinimizeScript { } } /// Cost function - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return m; } /// Constructor for cloning \a s @@ -329,20 +329,20 @@ class GraphColor : public IntMinimizeScript { m.update(*this, s.m); } /// Copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new GraphColor(*this); } /// Print the solution - virtual void - print(std::ostream& os) const { - os << "\tm = " << m << std::endl << "\tv[] = {"; + void + print(std::ostream& os) const override { + os << "\tm = " << m << '\n' << "\tv[] = {"; for (int i = 0; i < v.size(); i++) { os << v[i] << ", "; if ((i + 1) % 15 == 0) - os << std::endl << "\t "; + os << '\n' << "\t "; } - os << "};" << std::endl; + os << "};" << '\n'; } }; diff --git a/examples/grocery.cpp b/examples/grocery.cpp index 819c9b2e50..d976bc6c25 100644 --- a/examples/grocery.cpp +++ b/examples/grocery.cpp @@ -84,15 +84,15 @@ class Grocery : public Script { } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Grocery(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\t" << abcd << std::endl; + void + print(std::ostream& os) const override { + os << "\t" << abcd << '\n'; } }; diff --git a/examples/hamming.cpp b/examples/hamming.cpp index 410e412e49..80dcaed803 100644 --- a/examples/hamming.cpp +++ b/examples/hamming.cpp @@ -114,10 +114,10 @@ class Hamming : public Script { } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { for (int i = 0; i < x.size(); i++) { - os << "\t[" << i << "] = " << x[i] << std::endl; + os << "\t[" << i << "] = " << x[i] << '\n'; } } @@ -126,8 +126,8 @@ class Hamming : public Script { x.update(*this, s.x); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Hamming(*this); } }; diff --git a/examples/ind-set.cpp b/examples/ind-set.cpp index a00754dd98..098485fb43 100644 --- a/examples/ind-set.cpp +++ b/examples/ind-set.cpp @@ -96,18 +96,18 @@ class IndSet : public IntMaximizeScript { k.update(*this, s.k); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new IndSet(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tk = " << k << std::endl << "\tv[] = " << v << std::endl; + void + print(std::ostream& os) const override { + os << "\tk = " << k << '\n' << "\tv[] = " << v << '\n'; } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return k; } }; diff --git a/examples/job-shop.cpp b/examples/job-shop.cpp index f93389788a..09e78981ea 100644 --- a/examples/job-shop.cpp +++ b/examples/job-shop.cpp @@ -326,16 +326,16 @@ class JobShopOptions : public InstanceOptions { return _tbf.value(); } /// Print help text for list of instances - virtual void - help(void) { + void + help(void) override { InstanceOptions::help(); - std::cerr << "\tAvailable instances:" << std::endl << "\t\t"; + std::cerr << "\tAvailable instances:" << '\n' << "\t\t"; for (int i = 1; ::name[i] != nullptr; i++) { std::cerr << ::name[i] << ", "; if (i % 4 == 0) - std::cerr << std::endl << "\t\t"; + std::cerr << '\n' << "\t\t"; } - std::cerr << std::endl; + std::cerr << '\n'; } }; @@ -383,7 +383,7 @@ class JobShopBase : public IntMinimizeScript { } /// Do not overload machines void - nooverload(void) { + post_no_overload(void) { // Number of jobs and machines/steps int n = spec.jobs(), m = spec.machines(); @@ -407,8 +407,8 @@ class JobShopBase : public IntMinimizeScript { } } /// Return cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return makespan; } /// Constructor for cloning \a s @@ -417,9 +417,9 @@ class JobShopBase : public IntMinimizeScript { makespan.update(*this, s.makespan); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\t\t" << spec.name() << " [makespan: " << makespan << "]" << std::endl; + void + print(std::ostream& os) const override { + os << "\t\t" << spec.name() << " [makespan: " << makespan << "]" << '\n'; if (opt.verbose()) { // Number of jobs int n = spec.jobs(); @@ -429,7 +429,7 @@ class JobShopBase : public IntMinimizeScript { os << "\t\t\t[" << i << "]: "; for (int j = 0; j < m; j++) os << start[i * m + j] << " "; - os << std::endl; + os << '\n'; } } } @@ -453,7 +453,7 @@ class JobShopProbe : public JobShopBase { public: /// Actual model JobShopProbe(const JobShopOptions& o) : JobShopBase(o) { - nooverload(); + post_no_overload(); } void branch(unsigned int p, Rnd r) { @@ -468,10 +468,10 @@ class JobShopProbe : public JobShopBase { Gecode::branch(*this, start, INT_VAR_SIZE_MIN(), INT_VAL_MIN()); break; case 3U: - Gecode::branch(*this, start, tiebreak(INT_VAR_MIN_MIN(), INT_VAR_RND(r)), INT_VAL_MIN()); + Gecode::branch(*this, start, tie_break(INT_VAR_MIN_MIN(), INT_VAR_RND(r)), INT_VAL_MIN()); break; case 4U: - Gecode::branch(*this, start, tiebreak(INT_VAR_MAX_MIN(), INT_VAR_RND(r)), INT_VAL_MIN()); + Gecode::branch(*this, start, tie_break(INT_VAR_MAX_MIN(), INT_VAR_RND(r)), INT_VAL_MIN()); break; default: if (p & 1U) @@ -485,8 +485,8 @@ class JobShopProbe : public JobShopBase { /// Constructor for cloning \a s JobShopProbe(JobShopProbe& s) : JobShopBase(s) {} /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new JobShopProbe(*this); } }; @@ -509,7 +509,7 @@ class JobShopSolve : public JobShopBase { } /// Trampoline function for AFC-based cost static double - afcmerit(const Space& home, BoolVar x, int i) { + afc_merit(const Space& home, BoolVar x, int i) { return static_cast(home).afc(x, i); } /// Action information @@ -522,7 +522,7 @@ class JobShopSolve : public JobShopBase { } /// Trampoline function for Action-based cost static double - actionmerit(const Space& home, BoolVar, int i) { + action_merit(const Space& home, BoolVar, int i) { return static_cast(home).action(i); } /// CHB information @@ -535,7 +535,7 @@ class JobShopSolve : public JobShopBase { } /// Trampoline function for CHB-based cost static double - chbmerit(const Space& home, BoolVar, int i) { + chb_merit(const Space& home, BoolVar, int i) { return static_cast(home).chb(i); } /// Random number generator for probing and relaxation @@ -557,7 +557,7 @@ class JobShopSolve : public JobShopBase { JobShopSolve(const JobShopOptions& o) : JobShopBase(o), sorder(*this, spec.machines() * spec.jobs() * (spec.jobs() - 1) / 2, 0, 1), rnd(o.rnd()) { if (opt.propagation() == PROP_UNARY) - nooverload(); + post_no_overload(); // Number of jobs and machines/steps int n = spec.jobs(), m = spec.machines(); @@ -602,9 +602,10 @@ class JobShopSolve : public JobShopBase { assert(b >= w); return b - (b - w) * tbf; }; - branch(*this, sorder, tiebreak(BOOL_VAR_MERIT_MAX(&afcmerit, tbl), BOOL_VAR_RND(rnd)), BOOL_VAL_MIN()); + branch(*this, sorder, tie_break(BOOL_VAR_MERIT_MAX(&afc_merit, tbl), BOOL_VAR_RND(rnd)), + BOOL_VAL_MIN()); } else { - branch(*this, sorder, BOOL_VAR_MERIT_MAX(&afcmerit), BOOL_VAL_MIN()); + branch(*this, sorder, BOOL_VAR_MERIT_MAX(&afc_merit), BOOL_VAL_MIN()); } break; case BRANCH_ACTION: @@ -615,10 +616,10 @@ class JobShopSolve : public JobShopBase { assert(b >= w); return b - (b - w) * tbf; }; - branch(*this, sorder, tiebreak(BOOL_VAR_MERIT_MAX(&actionmerit, tbl), BOOL_VAR_RND(rnd)), + branch(*this, sorder, tie_break(BOOL_VAR_MERIT_MAX(&action_merit, tbl), BOOL_VAR_RND(rnd)), BOOL_VAL_MIN()); } else { - branch(*this, sorder, BOOL_VAR_MERIT_MAX(&actionmerit), BOOL_VAL_MIN()); + branch(*this, sorder, BOOL_VAR_MERIT_MAX(&action_merit), BOOL_VAL_MIN()); } break; case BRANCH_CHB: @@ -629,9 +630,10 @@ class JobShopSolve : public JobShopBase { assert(b >= w); return b - (b - w) * tbf; }; - branch(*this, sorder, tiebreak(BOOL_VAR_MERIT_MAX(&chbmerit, tbl), BOOL_VAR_RND(rnd)), BOOL_VAL_MIN()); + branch(*this, sorder, tie_break(BOOL_VAR_MERIT_MAX(&chb_merit, tbl), BOOL_VAR_RND(rnd)), + BOOL_VAL_MIN()); } else { - branch(*this, sorder, BOOL_VAR_MERIT_MAX(&chbmerit), BOOL_VAL_MIN()); + branch(*this, sorder, BOOL_VAR_MERIT_MAX(&chb_merit), BOOL_VAL_MIN()); } break; } @@ -643,8 +645,8 @@ class JobShopSolve : public JobShopBase { : JobShopBase(s), sorder(s.sorder), fst(s.fst), snd(s.snd), iafc(s.iafc), iaction(s.iaction), baction(s.baction), ichb(s.ichb), bchb(s.bchb), rnd(s.rnd) {} /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new JobShopSolve(*this); } }; @@ -659,8 +661,8 @@ class FailTimeStop : public Search::Stop { FailTimeStop(unsigned int fail, unsigned int time) : fs(new Search::FailStop(fail)), ts(new Search::TimeStop(time)) {} /// Test whether search must be stopped - virtual bool - stop(const Search::Statistics& s, const Search::Options& o) { + bool + stop(const Search::Statistics& s, const Search::Options& o) override { return fs->stop(s, o) || ts->stop(s, o); } /// Whether the stop was due to failures @@ -674,7 +676,7 @@ class FailTimeStop : public Search::Stop { return ts->stop(s, o); } /// Destructor - ~FailTimeStop(void) { + ~FailTimeStop(void) override { delete fs; delete ts; } @@ -684,10 +686,10 @@ class FailTimeStop : public Search::Stop { void print(const Search::Statistics& stat, bool restart) { using namespace std; - cout << "\t\t\tnodes: " << stat.node << endl << "\t\t\tfailures: " << stat.fail << endl; + cout << "\t\t\tnodes: " << stat.node << '\n' << "\t\t\tfailures: " << stat.fail << '\n'; if (restart) - cout << "\t\t\trestarts: " << stat.restart << endl << "\t\t\tno-goods: " << stat.nogood << endl; - cout << "\t\t\tpeak depth: " << stat.depth << endl; + cout << "\t\t\trestarts: " << stat.restart << '\n' << "\t\t\tno-goods: " << stat.nogood << '\n'; + cout << "\t\t\tpeak depth: " << stat.depth << '\n'; } /// Solver @@ -711,7 +713,7 @@ solve(const JobShopOptions& opt) { if (root->status() != SS_SOLVED) { delete root; - std::cerr << "Error: has no solution..." << std::endl; + std::cerr << "Error: has no solution..." << '\n'; return; } @@ -723,9 +725,9 @@ solve(const JobShopOptions& opt) { so.stop = &fts; bool stopped = false; - std::cout << "\tProbing..." << std::endl; + std::cout << "\tProbing..." << '\n'; - std::cout << "\t\tBounds: [" << l << "," << u << "]" << std::endl; + std::cout << "\t\tBounds: [" << l << "," << u << "]" << '\n' << std::flush; for (unsigned int p = 0; p < opt.probes(); p++) { JobShopProbe* jsp = static_cast(root->clone()); @@ -738,6 +740,7 @@ solve(const JobShopOptions& opt) { if (u > s->cost().val()) { u = s->cost().val(); s->print(std::cout); + std::cout << std::flush; } delete s; } else if (fts.time(statj, so)) { @@ -751,14 +754,14 @@ solve(const JobShopOptions& opt) { print(stat, false); std::cout << "\t\t\truntime: "; Driver::stop(t, std::cout); - std::cout << std::endl; + std::cout << '\n' << std::flush; if (stopped) { - std::cout << "\t\t\t\tstopped due to time-out..." << std::endl; + std::cout << "\t\t\t\tstopped due to time-out..." << '\n' << std::flush; } } - std::cout << std::endl << "\tAdjusting..." << std::endl; + std::cout << '\n' << "\tAdjusting..." << '\n' << std::flush; // Dichotomic search { @@ -766,7 +769,7 @@ solve(const JobShopOptions& opt) { if (model->status() == SS_FAILED) { delete model; - std::cerr << "Error: has no solution..." << std::endl; + std::cerr << "Error: has no solution..." << '\n'; return; } @@ -779,7 +782,7 @@ solve(const JobShopOptions& opt) { so.stop = Search::Stop::time(opt.time_adjust()); bool stopped = false; while (l < u) { - std::cout << "\t\tBounds: [" << l << "," << u << "]" << std::endl; + std::cout << "\t\tBounds: [" << l << "," << u << "]" << '\n' << std::flush; JobShopSolve* jss = static_cast(model->clone()); int m = (l + u) / 2; rel(*jss, jss->cost() >= l); @@ -792,6 +795,7 @@ solve(const JobShopOptions& opt) { if (s != nullptr) { s->print(std::cout); + std::cout << std::flush; u = s->cost().val(); delete s; } else if (rbs.end_reason() == Search::EndReason::Exhausted) { @@ -806,23 +810,23 @@ solve(const JobShopOptions& opt) { print(stat, true); std::cout << "\t\t\truntime: "; Driver::stop(t, std::cout); - std::cout << std::endl; + std::cout << '\n' << std::flush; if (stopped) { - std::cout << "\t\t\t\tstopped due to time-out..." << std::endl; + std::cout << "\t\t\t\tstopped due to time-out..." << '\n' << std::flush; } } if (l == u) { delete model; - std::cout << std::endl << "\tFound best solution and proved optimality." << std::endl; + std::cout << '\n' << "\tFound best solution and proved optimality." << '\n' << std::flush; return; } { Support::Timer t; t.start(); - std::cout << std::endl << "\tSolving..." << std::endl; + std::cout << '\n' << "\tSolving..." << '\n' << std::flush; rel(*model, model->cost() >= l); rel(*model, model->cost() < u); @@ -834,6 +838,7 @@ solve(const JobShopOptions& opt) { RBS rbs(model, so); while (JobShopSolve* s = rbs.next()) { s->print(std::cout); + std::cout << std::flush; u = s->cost().val(); delete s; } @@ -841,16 +846,16 @@ solve(const JobShopOptions& opt) { print(rbs.statistics(), true); std::cout << "\t\t\truntime: "; Driver::stop(t, std::cout); - std::cout << std::endl; + std::cout << '\n' << std::flush; if (rbs.end_reason() != Search::EndReason::Exhausted) { - std::cout << "\t\t\t\tstopped due to time-out..." << std::endl; - std::cout << std::endl << "\tSolution at most "; + std::cout << "\t\t\t\tstopped due to time-out..." << '\n' << std::flush; + std::cout << '\n' << "\tSolution at most "; double a = (static_cast(u - l + 1) / u) * 100.0; - std::cout << std::setprecision(2) << a << "% away from optimum." << std::endl; + std::cout << std::setprecision(2) << a << "% away from optimum." << '\n' << std::flush; } else { - std::cout << std::endl << "\tFound best solution and proved optimality." << std::endl; + std::cout << '\n' << "\tFound best solution and proved optimality." << '\n' << std::flush; } } } @@ -881,11 +886,11 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); try { if (!Spec(opt).valid()) { - std::cerr << "Error: unknown instance" << std::endl; + std::cerr << "Error: unknown instance" << '\n'; return 1; } } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } solve(opt); diff --git a/examples/kakuro.cpp b/examples/kakuro.cpp index fd2d0a4436..e7b9b5d36e 100644 --- a/examples/kakuro.cpp +++ b/examples/kakuro.cpp @@ -261,8 +261,8 @@ namespace { x.update(*this, s.x); } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new DistinctLinear(*this); } /// Return a solution @@ -365,7 +365,7 @@ class Kakuro : public Script { } /// Post a distinct-linear constraint on variables \a x with sum \a c void - distinctlinear(Cache& dc, const IntVarArgs& x, int c, const SizeOptions& opt) { + distinct_linear(Cache& dc, const IntVarArgs& x, int c, const SizeOptions& opt) { int n = x.size(); if (opt.model() == MODEL_DECOMPOSE) { if (n < 8) @@ -436,7 +436,7 @@ class Kakuro : public Script { IntVarArgs col(n); for (int i = n; i--;) col[i] = init(b(x, y + i + 1)); - distinctlinear(cache, col, s, opt); + distinct_linear(cache, col, s, opt); } k++; @@ -449,7 +449,7 @@ class Kakuro : public Script { IntVarArgs row(n); for (int i = n; i--;) row[i] = init(b(x + i + 1, y)); - distinctlinear(cache, row, s, opt); + distinct_linear(cache, row, s, opt); } branch(*this, f, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_SPLIT_MIN()); } @@ -458,13 +458,13 @@ class Kakuro : public Script { f.update(*this, s.f); } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Kakuro(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Matrix b(f, w, h); for (int y = 0; y < h; y++) { os << '\t'; @@ -473,7 +473,7 @@ class Kakuro : public Script { os << ". "; else os << b(x, y) << ' '; - os << std::endl; + os << '\n'; } } }; @@ -490,7 +490,7 @@ main(int argc, char* argv[]) { opt.ipl(IPL_DOM); opt.parse(argc, argv); if (opt.size() >= n_examples) { - std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_examples - 1 << '\n'; return 1; } Script::run(opt); diff --git a/examples/knights.cpp b/examples/knights.cpp index 425e59585f..b6ceb06be5 100644 --- a/examples/knights.cpp +++ b/examples/knights.cpp @@ -71,8 +71,8 @@ class Warnsdorff : public Brancher { */ Choice(const Brancher& b, int pos0, int val0) : Gecode::Choice(b, 2), pos(pos0), val(val0) {} /// Archive into \a e - virtual void - archive(Archive& e) const { + void + archive(Archive& e) const override { Gecode::Choice::archive(e); e << pos << val; } @@ -87,8 +87,8 @@ class Warnsdorff : public Brancher { public: /// Check status of brancher, return true if alternatives left - virtual bool - status(const Space&) const { + bool + status(const Space&) const override { // A path to follow can be at most x.size() long for (int n = x.size(); n--;) { if (!x[start].assigned()) @@ -99,8 +99,8 @@ class Warnsdorff : public Brancher { return false; } /// Return choice - virtual Gecode::Choice* - choice(Space&) { + Gecode::Choice* + choice(Space&) override { Int::ViewValues iv(x[start]); int n = iv.val(); unsigned int min = x[n].size(); @@ -116,15 +116,15 @@ class Warnsdorff : public Brancher { return new Choice(*this, start, n); } /// Return choice - virtual Choice* - choice(const Space&, Archive& e) { + Choice* + choice(const Space&, Archive& e) override { int pos, val; e >> pos >> val; return new Choice(*this, pos, val); } /// Perform commit for choice \a _c and alternative \a a - virtual ExecStatus - commit(Space& home, const Gecode::Choice& _c, unsigned int a) { + ExecStatus + commit(Space& home, const Gecode::Choice& _c, unsigned int a) override { const Choice& c = static_cast(_c); if (a == 0) return me_failed(x[c.pos].eq(home, c.val)) ? ES_FAILED : ES_OK; @@ -132,14 +132,14 @@ class Warnsdorff : public Brancher { return me_failed(x[c.pos].nq(home, c.val)) ? ES_FAILED : ES_OK; } /// Print explanation - virtual void - print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const { + void + print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const override { const Choice& c = static_cast(_c); o << "x[" << c.pos << "] " << ((a == 0) ? "=" : "!=") << " " << c.val; } /// Copy brancher - virtual Actor* - copy(Space& home) { + Actor* + copy(Space& home) override { return new (home) Warnsdorff(home, *this); } /// Post brancher @@ -149,8 +149,8 @@ class Warnsdorff : public Brancher { (void)new (home) Warnsdorff(home, xv); } /// Delete brancher and return its size - virtual size_t - dispose(Space&) { + size_t + dispose(Space&) override { return sizeof(*this); } }; @@ -216,8 +216,8 @@ class Knights : public Script { succ.update(*this, s.succ); } /// Print board - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { int* jump = new int[n * n]; { int j = 0; @@ -232,9 +232,9 @@ class Knights : public Script { os.width(3); os << jump[f(i, j)] << " "; } - os << std::endl << "\t"; + os << '\n' << "\t"; } - os << std::endl; + os << '\n'; delete[] jump; } }; @@ -285,8 +285,8 @@ class KnightsReified : public Knights { /// Constructor for cloning \a s KnightsReified(KnightsReified& s) : Knights(s) {} /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new KnightsReified(*this); } }; @@ -315,8 +315,8 @@ class KnightsCircuit : public Knights { /// Constructor for cloning \a s KnightsCircuit(KnightsCircuit& s) : Knights(s) {} /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new KnightsCircuit(*this); } }; @@ -342,13 +342,14 @@ class KnightsInspector : public Gist::Inspector { /// Constructor KnightsInspector(void) : scene(nullptr), mw(nullptr) {} /// Inspect space \a s - virtual void - inspect(const Space& s) { + void + inspect(const Space& s) override { const Knights& k = static_cast(s); + const int half_unit = unit / 2; if (!scene) initialize(); - QList itemList = scene->items(); + QList item_list = scene->items(); foreach (QGraphicsItem* i, scene->items()) { scene->removeItem(i); delete i; @@ -367,8 +368,8 @@ class KnightsInspector : public Gist::Inspector { for (IntVarValues xv(k.succ[i * k.n + j]); xv(); ++xv) { int ky = xv.val() % k.n; int kx = xv.val() / k.n; - scene->addLine(i * unit + unit / 2, j * unit + unit / 2, kx * unit + unit / 2, ky * unit + unit / 2, - pen); + scene->addLine(i * unit + half_unit, j * unit + half_unit, kx * unit + half_unit, + ky * unit + half_unit, pen); } } } @@ -385,20 +386,20 @@ class KnightsInspector : public Gist::Inspector { mw->setCentralWidget(view); mw->setAttribute(Qt::WA_QuitOnClose, false); mw->setAttribute(Qt::WA_DeleteOnClose, false); - QAction* closeWindow = new QAction("Close window", mw); - closeWindow->setShortcut(QKeySequence("Ctrl+W")); - mw->connect(closeWindow, SIGNAL(triggered()), mw, SLOT(close())); - mw->addAction(closeWindow); + QAction* close_window = new QAction("Close window", mw); + close_window->setShortcut(QKeySequence("Ctrl+W")); + mw->connect(close_window, SIGNAL(triggered()), mw, SLOT(close())); + mw->addAction(close_window); } /// Name of the inspector - virtual std::string - name(void) { + std::string + name(void) override { return "Board"; } /// Finalize inspector - virtual void - finalize(void) { + void + finalize(void) override { delete mw; mw = nullptr; } diff --git a/examples/langford-number.cpp b/examples/langford-number.cpp index c481f7a631..07f0e074fa 100644 --- a/examples/langford-number.cpp +++ b/examples/langford-number.cpp @@ -60,13 +60,13 @@ class LangfordNumberOptions : public Options { k = atoi(argv[2]); } /// Print help message - virtual void - help(void) { + void + help(void) override { Options::help(); - std::cerr << "\t(unsigned int) default: " << n << std::endl - << "\t\tparameter n" << std::endl - << "\t(unsigned int) default: " << k << std::endl - << "\t\tparameter k" << std::endl; + std::cerr << "\t(unsigned int) default: " << n << '\n' + << "\t\tparameter n" << '\n' + << "\t(unsigned int) default: " << k << '\n' + << "\t\tparameter k" << '\n'; } }; @@ -150,16 +150,16 @@ class LangfordNumber : public Script { } // Symmetry breaking - rel(*this, y[0], IRT_LE, y[n * k - 1]); + rel(*this, y[0], IRT_LT, y[n * k - 1]); // Branching branch(*this, y, INT_VAR_SIZE_MIN(), INT_VAL_MAX()); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\t" << y << std::endl; + void + print(std::ostream& os) const override { + os << "\t" << y << '\n'; } /// Constructor for cloning \a l @@ -167,8 +167,8 @@ class LangfordNumber : public Script { y.update(*this, l.y); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new LangfordNumber(*this); } }; @@ -186,11 +186,11 @@ main(int argc, char* argv[]) { opt.propagation(LangfordNumber::PROP_EXTENSIONAL_CHANNEL, "extensional-channel"); opt.parse(argc, argv); if (opt.k < 1) { - std::cerr << "k must be at least 1!" << std::endl; + std::cerr << "k must be at least 1!" << '\n'; return 1; } if (opt.k > opt.n) { - std::cerr << "n must be at least k!" << std::endl; + std::cerr << "n must be at least k!" << '\n'; return 1; } Script::run(opt); diff --git a/examples/magic-sequence.cpp b/examples/magic-sequence.cpp index a29f7b63f9..65627ac33e 100644 --- a/examples/magic-sequence.cpp +++ b/examples/magic-sequence.cpp @@ -89,20 +89,20 @@ class MagicSequence : public Script { s.update(*this, e.s); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new MagicSequence(*this); } /// Print sequence - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << "\t"; for (int i = 0; i < n; i++) { os << s[i] << ", "; if ((i + 1) % 20 == 0) - os << std::endl << "\t"; + os << '\n' << "\t"; } - os << std::endl; + os << '\n'; } }; diff --git a/examples/magic-square-partial.cpp b/examples/magic-square-partial.cpp index 496cd88908..f21fced33a 100644 --- a/examples/magic-square-partial.cpp +++ b/examples/magic-square-partial.cpp @@ -120,7 +120,7 @@ class MagicSquare : public Script { switch (opt.branching()) { case BRANCH_CBS_MAX_SD: #ifdef GECODE_HAS_CBS - cbsbranch(*this, x); + cbs_branch(*this, x); #endif case BRANCH_SIZE: branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN()); @@ -137,13 +137,13 @@ class MagicSquare : public Script { } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new MagicSquare(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { // Matrix-wrapper for the square Matrix m(x, n, n); for (int i = 0; i < n; i++) { @@ -152,7 +152,7 @@ class MagicSquare : public Script { os.width(2); os << m(i, j) << " "; } - os << std::endl; + os << '\n'; } } }; @@ -189,231 +189,231 @@ namespace { * \relates Magic-square */ //@{ - const int magicSquare5_filled10_10[] = { + const int magic_square5_filled10_10[] = { 5, 10, 1, 2, 18, 1, 3, 9, 1, 5, 2, 2, 2, 5, 3, 1, 1, 3, 5, 24, 4, 2, 21, 4, 3, 6, 5, 2, 13, 5, 4, 10, }; - const int magicSquare5_filled10_11[] = { + const int magic_square5_filled10_11[] = { 5, 10, 1, 3, 6, 1, 5, 2, 2, 2, 8, 2, 5, 25, 3, 1, 1, 3, 4, 17, 3, 5, 24, 4, 1, 9, 4, 2, 21, 5, 3, 16, }; - const int magicSquare5_filled10_12[] = { + const int magic_square5_filled10_12[] = { 5, 10, 1, 2, 5, 1, 4, 21, 2, 1, 10, 2, 2, 16, 2, 3, 8, 3, 4, 12, 4, 2, 20, 4, 5, 11, 5, 1, 18, 5, 5, 3, }; - const int magicSquare5_filled10_13[] = { + const int magic_square5_filled10_13[] = { 5, 10, 1, 5, 2, 1, 2, 16, 2, 3, 8, 3, 3, 21, 3, 1, 1, 4, 1, 12, 5, 2, 6, 5, 1, 20, 5, 3, 14, 5, 5, 3, }; - const int magicSquare5_filled10_14[] = { + const int magic_square5_filled10_14[] = { 5, 10, 1, 3, 14, 1, 2, 7, 2, 3, 12, 2, 4, 4, 3, 3, 21, 3, 5, 24, 4, 5, 11, 4, 4, 6, 4, 3, 13, 5, 4, 22, }; - const int magicSquare5_filled10_15[] = { + const int magic_square5_filled10_15[] = { 5, 10, 1, 5, 2, 1, 1, 21, 2, 1, 15, 2, 2, 5, 4, 2, 18, 4, 5, 11, 5, 4, 20, 5, 5, 3, 5, 2, 12, 5, 3, 8, }; - const int magicSquare5_filled10_16[] = { + const int magic_square5_filled10_16[] = { 5, 10, 1, 1, 22, 1, 5, 2, 1, 4, 18, 2, 5, 25, 2, 4, 7, 3, 4, 15, 3, 1, 1, 3, 2, 9, 4, 4, 4, 5, 1, 23, }; - const int magicSquare5_filled10_17[] = { + const int magic_square5_filled10_17[] = { 5, 10, 1, 2, 5, 2, 4, 4, 2, 5, 25, 3, 4, 16, 3, 5, 24, 3, 3, 14, 3, 1, 1, 4, 2, 22, 5, 3, 13, 5, 4, 7, }; - const int magicSquare5_filled10_18[] = { + const int magic_square5_filled10_18[] = { 5, 10, 1, 3, 7, 1, 4, 22, 2, 5, 25, 2, 4, 4, 2, 1, 10, 3, 1, 1, 4, 4, 6, 4, 3, 20, 5, 3, 8, 5, 2, 12, }; - const int magicSquare5_filled10_19[] = { + const int magic_square5_filled10_19[] = { 5, 10, 1, 2, 6, 1, 5, 2, 2, 2, 18, 2, 1, 13, 3, 5, 24, 3, 3, 17, 5, 2, 7, 5, 1, 22, 5, 4, 21, 5, 3, 12, }; - const int magicSquare5_filled10_1[] = { + const int magic_square5_filled10_1[] = { 5, 10, 1, 4, 16, 1, 5, 2, 1, 3, 20, 2, 5, 25, 2, 4, 4, 3, 5, 24, 3, 1, 1, 4, 4, 9, 5, 2, 12, 5, 1, 23, }; - const int magicSquare5_filled10_20[] = { + const int magic_square5_filled10_20[] = { 5, 10, 1, 1, 22, 2, 5, 25, 2, 2, 5, 3, 5, 24, 3, 1, 1, 4, 4, 19, 4, 5, 11, 5, 1, 23, 5, 2, 8, 5, 3, 10, }; - const int magicSquare5_filled10_2[] = { + const int magic_square5_filled10_2[] = { 5, 10, 1, 2, 19, 1, 4, 9, 2, 5, 25, 2, 1, 15, 3, 2, 6, 4, 2, 20, 4, 1, 5, 5, 5, 3, 5, 3, 10, 5, 1, 23, }; - const int magicSquare5_filled10_3[] = { + const int magic_square5_filled10_3[] = { 5, 10, 1, 1, 15, 1, 5, 2, 2, 1, 20, 2, 3, 7, 3, 4, 5, 4, 1, 6, 4, 4, 16, 5, 1, 23, 5, 2, 12, 5, 3, 8, }; - const int magicSquare5_filled10_4[] = { + const int magic_square5_filled10_4[] = { 5, 10, 1, 2, 15, 1, 5, 2, 1, 1, 22, 1, 4, 16, 2, 5, 25, 3, 5, 24, 3, 1, 1, 4, 1, 23, 4, 2, 18, 4, 3, 9, }; - const int magicSquare5_filled10_5[] = { + const int magic_square5_filled10_5[] = { 5, 10, 1, 1, 14, 1, 4, 21, 2, 2, 12, 2, 5, 25, 3, 2, 5, 3, 3, 19, 3, 5, 24, 4, 2, 18, 5, 1, 22, 5, 2, 10, }; - const int magicSquare5_filled10_6[] = { + const int magic_square5_filled10_6[] = { 5, 10, 1, 1, 19, 1, 2, 20, 2, 1, 7, 3, 3, 23, 4, 5, 11, 4, 4, 4, 5, 3, 13, 5, 5, 3, 5, 4, 22, 5, 2, 10, }; - const int magicSquare5_filled10_7[] = { + const int magic_square5_filled10_7[] = { 5, 10, 1, 2, 10, 2, 4, 4, 3, 5, 24, 3, 4, 17, 4, 5, 11, 4, 2, 23, 4, 4, 5, 4, 1, 14, 5, 2, 6, 5, 5, 3, }; - const int magicSquare5_filled10_8[] = { + const int magic_square5_filled10_8[] = { 5, 10, 1, 1, 22, 1, 3, 5, 2, 5, 25, 2, 4, 4, 3, 5, 24, 3, 2, 8, 4, 1, 10, 4, 2, 21, 4, 3, 16, 4, 5, 11, }; - const int magicSquare5_filled10_9[] = { + const int magic_square5_filled10_9[] = { 5, 10, 1, 5, 2, 2, 2, 10, 2, 5, 25, 3, 3, 23, 3, 1, 1, 4, 2, 15, 4, 4, 13, 4, 3, 6, 5, 5, 3, 5, 3, 5, }; - const int magicSquare5_filled11_3_1[] = { + const int magic_square5_filled11_3_1[] = { 5, 11, 1, 1, 15, 1, 5, 2, 2, 1, 20, 2, 3, 7, 3, 2, 13, 3, 4, 5, 4, 1, 6, 4, 4, 16, 5, 1, 23, 5, 2, 12, 5, 3, 8, }; - const int magicSquare5_filled11_5_1[] = { + const int magic_square5_filled11_5_1[] = { 5, 11, 1, 1, 14, 1, 4, 21, 2, 2, 12, 2, 5, 25, 3, 2, 5, 3, 3, 19, 3, 4, 16, 3, 5, 24, 4, 2, 18, 5, 1, 22, 5, 2, 10, }; - const int magicSquare5_filled11_5_2[] = { + const int magic_square5_filled11_5_2[] = { 5, 11, 1, 1, 14, 1, 4, 21, 2, 2, 12, 2, 5, 25, 3, 2, 5, 3, 3, 19, 3, 5, 24, 4, 2, 18, 5, 1, 22, 5, 2, 10, 5, 5, 3, }; - const int magicSquare5_filled11_5_3[] = { + const int magic_square5_filled11_5_3[] = { 5, 11, 1, 1, 14, 1, 3, 8, 1, 4, 21, 2, 2, 12, 2, 5, 25, 3, 2, 5, 3, 3, 19, 3, 5, 24, 4, 2, 18, 5, 1, 22, 5, 2, 10, }; - const int magicSquare5_filled12_10_1[] = { + const int magic_square5_filled12_10_1[] = { 5, 12, 1, 2, 18, 1, 3, 9, 1, 5, 2, 2, 2, 5, 3, 1, 1, 3, 3, 15, 3, 5, 24, 4, 1, 7, 4, 2, 21, 4, 3, 6, 5, 2, 13, 5, 4, 10, }; - const int magicSquare5_filled12_1_1[] = { + const int magic_square5_filled12_1_1[] = { 5, 12, 1, 1, 21, 1, 3, 20, 1, 4, 16, 1, 5, 2, 2, 5, 25, 2, 4, 4, 3, 1, 1, 3, 3, 14, 3, 5, 24, 4, 4, 9, 5, 2, 12, 5, 1, 23, }; - const int magicSquare5_filled12_1_2[] = { + const int magic_square5_filled12_1_2[] = { 5, 12, 1, 3, 20, 1, 4, 16, 1, 5, 2, 2, 2, 18, 2, 4, 4, 2, 5, 25, 3, 1, 1, 3, 3, 14, 3, 5, 24, 4, 4, 9, 5, 2, 12, 5, 1, 23, }; - const int magicSquare5_filled12_1_3[] = { + const int magic_square5_filled12_1_3[] = { 5, 12, 1, 3, 20, 1, 4, 16, 1, 5, 2, 2, 2, 18, 2, 4, 4, 2, 5, 25, 3, 1, 1, 3, 5, 24, 4, 4, 9, 5, 1, 23, 5, 2, 12, 5, 3, 10, }; - const int magicSquare5_filled12_2_1[] = { + const int magic_square5_filled12_2_1[] = { 5, 12, 1, 1, 21, 1, 2, 19, 1, 4, 9, 2, 1, 15, 2, 5, 25, 3, 2, 6, 3, 4, 18, 4, 1, 5, 4, 2, 20, 5, 1, 23, 5, 3, 10, 5, 5, 3, }; - const int magicSquare5_filled12_2_2[] = { + const int magic_square5_filled12_2_2[] = { 5, 12, 1, 2, 19, 1, 4, 9, 2, 1, 15, 2, 3, 8, 2, 5, 25, 3, 2, 6, 3, 4, 18, 4, 1, 5, 4, 2, 20, 5, 1, 23, 5, 3, 10, 5, 5, 3, }; - const int magicSquare5_filled12_2_3[] = { + const int magic_square5_filled12_2_3[] = { 5, 12, 1, 1, 21, 1, 2, 19, 1, 4, 9, 2, 1, 15, 2, 5, 25, 3, 2, 6, 4, 1, 5, 4, 2, 20, 4, 4, 12, 5, 1, 23, 5, 3, 10, 5, 5, 3, }; - const int magicSquare5_filled12_3_1[] = { + const int magic_square5_filled12_3_1[] = { 5, 12, 1, 1, 15, 1, 4, 21, 1, 5, 2, 2, 1, 20, 2, 3, 7, 3, 4, 5, 4, 1, 6, 4, 4, 16, 5, 1, 23, 5, 2, 12, 5, 3, 8, 5, 5, 3, }; - const int magicSquare5_filled12_3_2[] = { + const int magic_square5_filled12_3_2[] = { 5, 12, 1, 1, 15, 1, 2, 17, 1, 3, 10, 1, 5, 2, 2, 1, 20, 2, 3, 7, 3, 4, 5, 4, 1, 6, 4, 4, 16, 5, 1, 23, 5, 2, 12, 5, 3, 8, }; - const int magicSquare9_filled10_10[] = { + const int magic_square9_filled10_10[] = { 9, 10, 8, 2, 19, 6, 7, 25, 7, 3, 15, 8, 4, 77, 7, 1, 29, 4, 9, 63, 4, 6, 53, 7, 1, 29, 3, 9, 36, 5, 4, 74, }; - const int magicSquare9_filled10_11[] = { + const int magic_square9_filled10_11[] = { 9, 10, 5, 5, 78, 6, 5, 56, 9, 8, 30, 3, 3, 38, 2, 3, 9, 1, 2, 23, 3, 5, 80, 9, 7, 52, 7, 5, 1, 1, 1, 32, }; - const int magicSquare9_filled10_12[] = { + const int magic_square9_filled10_12[] = { 9, 10, 6, 7, 25, 1, 4, 2, 5, 1, 54, 3, 3, 38, 7, 2, 71, 1, 5, 28, 3, 2, 50, 2, 7, 59, 7, 7, 42, 5, 4, 74, }; - const int magicSquare9_filled10_13[] = { + const int magic_square9_filled10_13[] = { 9, 10, 7, 2, 71, 8, 9, 22, 2, 2, 17, 3, 3, 38, 1, 8, 72, 6, 5, 56, 5, 6, 41, 9, 1, 8, 7, 8, 37, 3, 3, 38, }; - const int magicSquare9_filled10_14[] = { + const int magic_square9_filled10_14[] = { 9, 10, 9, 4, 35, 1, 3, 48, 9, 6, 69, 7, 6, 70, 6, 1, 46, 5, 1, 54, 4, 2, 62, 2, 8, 67, 7, 6, 70, 7, 3, 15, }; - const int magicSquare9_filled10_15[] = { + const int magic_square9_filled10_15[] = { 9, 10, 9, 8, 30, 1, 6, 4, 9, 9, 45, 9, 2, 49, 5, 6, 41, 6, 5, 56, 5, 9, 7, 2, 6, 3, 3, 2, 50, 1, 2, 23, }; - const int magicSquare9_filled10_16[] = { + const int magic_square9_filled10_16[] = { 9, 10, 1, 9, 81, 3, 8, 18, 8, 4, 77, 6, 5, 56, 7, 9, 31, 1, 9, 81, 7, 3, 15, 6, 4, 5, 6, 8, 61, 4, 6, 53, }; - const int magicSquare9_filled10_17[] = { + const int magic_square9_filled10_17[] = { 9, 10, 4, 4, 12, 9, 5, 26, 7, 6, 70, 8, 2, 19, 7, 2, 71, 8, 1, 68, 8, 2, 19, 5, 5, 78, 6, 3, 21, 5, 3, 75, }; - const int magicSquare9_filled10_18[] = { + const int magic_square9_filled10_18[] = { 9, 10, 7, 2, 71, 4, 1, 47, 6, 9, 24, 8, 8, 39, 3, 9, 36, 2, 9, 60, 4, 3, 64, 5, 8, 11, 4, 2, 62, 3, 7, 43, }; - const int magicSquare9_filled10_19[] = { + const int magic_square9_filled10_19[] = { 9, 10, 7, 4, 73, 8, 3, 44, 8, 1, 68, 1, 2, 23, 1, 6, 4, 5, 7, 16, 3, 6, 6, 8, 2, 19, 4, 5, 14, 3, 3, 38, }; - const int magicSquare9_filled10_1[] = { + const int magic_square9_filled10_1[] = { 9, 10, 4, 5, 14, 6, 7, 25, 8, 8, 39, 6, 7, 25, 3, 8, 18, 4, 4, 12, 8, 2, 19, 4, 1, 47, 4, 6, 53, 8, 5, 10, }; - const int magicSquare9_filled10_20[] = { + const int magic_square9_filled10_20[] = { 9, 10, 1, 4, 2, 8, 6, 57, 1, 5, 28, 1, 8, 72, 6, 1, 46, 4, 1, 47, 8, 7, 33, 4, 6, 53, 1, 5, 28, 5, 8, 11, }; - const int magicSquare9_filled10_2[] = { + const int magic_square9_filled10_2[] = { 9, 10, 2, 5, 76, 9, 1, 8, 2, 4, 51, 1, 2, 23, 9, 7, 52, 1, 8, 72, 3, 3, 38, 6, 6, 66, 3, 7, 43, 7, 6, 70, }; - const int magicSquare9_filled10_3[] = { + const int magic_square9_filled10_3[] = { 9, 10, 5, 6, 41, 5, 3, 75, 6, 1, 46, 3, 2, 50, 3, 8, 18, 1, 5, 28, 3, 2, 50, 5, 9, 7, 4, 8, 34, 1, 4, 2, }; - const int magicSquare9_filled10_4[] = { + const int magic_square9_filled10_4[] = { 9, 10, 4, 9, 63, 9, 4, 35, 7, 5, 1, 2, 6, 3, 8, 4, 77, 7, 6, 70, 5, 8, 11, 2, 5, 76, 9, 4, 35, 3, 6, 6, }; - const int magicSquare9_filled10_5[] = { + const int magic_square9_filled10_5[] = { 9, 10, 2, 5, 76, 1, 4, 2, 9, 3, 55, 1, 2, 23, 3, 3, 38, 2, 5, 76, 3, 4, 40, 3, 4, 40, 1, 2, 23, 3, 6, 6, }; - const int magicSquare9_filled10_6[] = { + const int magic_square9_filled10_6[] = { 9, 10, 7, 5, 1, 4, 7, 20, 8, 7, 33, 5, 5, 78, 5, 2, 13, 3, 1, 58, 1, 9, 81, 5, 1, 54, 3, 1, 58, 7, 5, 1, }; - const int magicSquare9_filled10_7[] = { + const int magic_square9_filled10_7[] = { 9, 10, 7, 5, 1, 7, 5, 1, 1, 5, 28, 4, 8, 34, 4, 1, 47, 4, 2, 62, 2, 6, 3, 2, 8, 67, 1, 9, 81, 5, 4, 74, }; - const int magicSquare9_filled10_8[] = { + const int magic_square9_filled10_8[] = { 9, 10, 9, 4, 35, 4, 9, 63, 1, 6, 4, 5, 5, 78, 7, 5, 1, 9, 4, 35, 5, 6, 41, 6, 3, 21, 9, 3, 55, 3, 5, 80, }; - const int magicSquare9_filled10_9[] = { + const int magic_square9_filled10_9[] = { 9, 10, 4, 8, 34, 4, 1, 47, 3, 9, 36, 8, 6, 57, 9, 2, 49, 9, 9, 45, 1, 6, 4, 4, 6, 53, 3, 6, 6, 2, 2, 17, }; - const int magicSquare9_filled50_10[] = { + const int magic_square9_filled50_10[] = { 9, 50, 4, 3, 64, 3, 9, 36, 8, 3, 44, 6, 9, 24, 2, 7, 59, 7, 2, 71, 8, 2, 19, 2, 8, 67, 6, 7, 25, 6, 6, 66, 3, 8, 18, 1, 9, 81, 8, 4, 77, 5, 4, 74, 8, 2, 19, 6, 9, 24, 4, 9, 63, 9, 3, 55, 2, 5, 76, 9, 2, 49, 3, 7, 43, 3, 8, 18, 6, 3, 21, 6, 2, 65, 9, 2, 49, 7, 9, 31, 8, 6, 57, 8, 6, 57, 9, 3, 55, 7, 5, 1, 2, 4, 51, 5, 4, 74, 3, @@ -421,7 +421,7 @@ namespace { 3, 15, 9, 5, 26, 7, 1, 29, 6, 9, 24, 2, 6, 3, 3, 5, 80, 7, 9, 31, }; - const int magicSquare9_filled50_11[] = { + const int magic_square9_filled50_11[] = { 9, 50, 6, 8, 61, 3, 3, 38, 9, 7, 52, 6, 3, 21, 4, 9, 63, 3, 9, 36, 7, 3, 15, 1, 1, 32, 2, 7, 59, 1, 8, 72, 2, 5, 76, 8, 7, 33, 5, 1, 54, 3, 5, 80, 3, 8, 18, 4, 8, 34, 4, 5, 14, 2, 3, 9, 9, 5, 26, 3, 3, 38, 2, 5, 76, 9, 8, 30, 8, 9, 22, 6, 7, 25, 7, 6, 70, 5, 6, 41, 2, 1, 27, 4, 4, 12, 8, 4, 77, 8, 2, 19, 9, 1, 8, 7, 3, 15, 5, @@ -429,7 +429,7 @@ namespace { 2, 49, 7, 7, 42, 1, 6, 4, 7, 7, 42, 7, 2, 71, 4, 7, 20, 4, 3, 64, }; - const int magicSquare9_filled50_12[] = { + const int magic_square9_filled50_12[] = { 9, 50, 1, 3, 48, 3, 5, 80, 4, 5, 14, 6, 1, 46, 8, 8, 39, 2, 8, 67, 8, 8, 39, 9, 2, 49, 2, 2, 17, 6, 1, 46, 9, 9, 45, 8, 9, 22, 3, 4, 40, 2, 3, 9, 4, 6, 53, 5, 3, 75, 6, 6, 66, 7, 1, 29, 8, 1, 68, 1, 7, 79, 7, 9, 31, 5, 3, 75, 6, 4, 5, 5, 7, 16, 3, 1, 58, 5, 3, 75, 7, 4, 73, 9, 8, 30, 5, 8, 11, 1, 7, 79, 4, 4, 12, 9, 8, 30, 7, @@ -437,7 +437,7 @@ namespace { 9, 7, 5, 5, 78, 6, 7, 25, 6, 5, 56, 3, 3, 38, 8, 8, 39, 8, 1, 68, }; - const int magicSquare9_filled50_13[] = { + const int magic_square9_filled50_13[] = { 9, 50, 2, 7, 59, 6, 2, 65, 9, 5, 26, 6, 5, 56, 8, 6, 57, 1, 1, 32, 9, 9, 45, 7, 6, 70, 4, 2, 62, 4, 9, 63, 4, 9, 63, 4, 8, 34, 3, 6, 6, 1, 1, 32, 2, 6, 3, 8, 3, 44, 2, 3, 9, 2, 1, 27, 7, 7, 42, 3, 6, 6, 2, 3, 9, 4, 1, 47, 2, 1, 27, 5, 4, 74, 9, 8, 30, 3, 1, 58, 7, 4, 73, 6, 9, 24, 7, 5, 1, 8, 8, 39, 1, 4, 2, 1, 9, 81, 6, @@ -445,7 +445,7 @@ namespace { 3, 44, 2, 4, 51, 1, 9, 81, 8, 8, 39, 9, 2, 49, 6, 6, 66, 3, 1, 58, }; - const int magicSquare9_filled50_14[] = { + const int magic_square9_filled50_14[] = { 9, 50, 1, 4, 2, 6, 7, 25, 3, 2, 50, 6, 6, 66, 2, 8, 67, 5, 1, 54, 2, 6, 3, 7, 7, 42, 6, 2, 65, 2, 8, 67, 8, 3, 44, 2, 9, 60, 4, 5, 14, 9, 5, 26, 4, 1, 47, 5, 2, 13, 4, 9, 63, 6, 5, 56, 1, 9, 81, 1, 2, 23, 8, 4, 77, 1, 9, 81, 9, 7, 52, 5, 3, 75, 8, 6, 57, 1, 7, 79, 8, 9, 22, 4, 9, 63, 5, 1, 54, 3, 6, 6, 1, 7, 79, 5, 3, 75, 6, @@ -453,7 +453,7 @@ namespace { 6, 4, 7, 3, 15, 2, 6, 3, 1, 6, 4, 6, 4, 5, 5, 1, 54, 8, 4, 77, }; - const int magicSquare9_filled50_15[] = { + const int magic_square9_filled50_15[] = { 9, 50, 1, 4, 2, 2, 7, 59, 7, 5, 1, 7, 7, 42, 5, 3, 75, 5, 1, 54, 7, 8, 37, 2, 8, 67, 3, 3, 38, 4, 9, 63, 3, 3, 38, 3, 1, 58, 6, 8, 61, 5, 2, 13, 6, 1, 46, 5, 5, 78, 4, 4, 12, 2, 8, 67, 9, 8, 30, 5, 2, 13, 9, 7, 52, 3, 4, 40, 5, 2, 13, 9, 7, 52, 2, 3, 9, 5, 5, 78, 3, 5, 80, 5, 8, 11, 2, 7, 59, 9, 7, 52, 7, 2, 71, 9, 8, 30, 4, @@ -461,7 +461,7 @@ namespace { 4, 12, 5, 4, 74, 9, 1, 8, 3, 8, 18, 8, 4, 77, 7, 3, 15, 4, 2, 62, }; - const int magicSquare9_filled50_16[] = { + const int magic_square9_filled50_16[] = { 9, 50, 1, 4, 2, 3, 6, 6, 3, 7, 43, 5, 4, 74, 1, 8, 72, 5, 6, 41, 4, 7, 20, 2, 6, 3, 3, 5, 80, 8, 8, 39, 6, 5, 56, 6, 7, 25, 3, 4, 40, 1, 7, 79, 4, 3, 64, 8, 5, 10, 4, 8, 34, 8, 6, 57, 5, 3, 75, 8, 5, 10, 8, 1, 68, 8, 2, 19, 5, 9, 7, 8, 8, 39, 3, 4, 40, 4, 6, 53, 8, 9, 22, 3, 8, 18, 1, 2, 23, 6, 5, 56, 4, 2, 62, 9, 7, 52, 1, @@ -469,7 +469,7 @@ namespace { 9, 81, 4, 4, 12, 4, 5, 14, 6, 3, 21, 2, 4, 51, 8, 9, 22, 8, 6, 57, }; - const int magicSquare9_filled50_17[] = { + const int magic_square9_filled50_17[] = { 9, 50, 8, 6, 57, 9, 2, 49, 3, 5, 80, 3, 6, 6, 8, 2, 19, 9, 1, 8, 2, 1, 27, 3, 1, 58, 1, 2, 23, 1, 2, 23, 5, 2, 13, 6, 8, 61, 5, 5, 78, 2, 1, 27, 5, 8, 11, 4, 1, 47, 4, 3, 64, 2, 4, 51, 8, 3, 44, 9, 4, 35, 2, 8, 67, 5, 4, 74, 7, 5, 1, 2, 7, 59, 6, 2, 65, 9, 9, 45, 4, 3, 64, 7, 6, 70, 8, 9, 22, 4, 3, 64, 7, 7, 42, 1, 1, 32, 7, @@ -477,7 +477,7 @@ namespace { 3, 38, 1, 6, 4, 5, 5, 78, 1, 3, 48, 4, 7, 20, 2, 6, 3, 8, 4, 77, }; - const int magicSquare9_filled50_18[] = { + const int magic_square9_filled50_18[] = { 9, 50, 5, 3, 75, 7, 1, 29, 9, 4, 35, 3, 8, 18, 9, 1, 8, 4, 5, 14, 2, 6, 3, 2, 8, 67, 8, 4, 77, 1, 6, 4, 7, 3, 15, 2, 5, 76, 5, 5, 78, 3, 7, 43, 1, 8, 72, 8, 5, 10, 1, 5, 28, 6, 7, 25, 6, 6, 66, 5, 3, 75, 6, 7, 25, 8, 8, 39, 3, 9, 36, 4, 1, 47, 2, 3, 9, 7, 8, 37, 5, 6, 41, 4, 8, 34, 1, 4, 2, 3, 8, 18, 9, 1, 8, 3, 9, 36, 5, @@ -485,7 +485,7 @@ namespace { 6, 66, 5, 6, 41, 4, 2, 62, 6, 5, 56, 1, 8, 72, 8, 4, 77, 4, 8, 34, }; - const int magicSquare9_filled50_19[] = { + const int magic_square9_filled50_19[] = { 9, 50, 1, 5, 28, 3, 5, 80, 1, 2, 23, 1, 4, 2, 5, 7, 16, 8, 8, 39, 5, 9, 7, 7, 2, 71, 1, 1, 32, 5, 4, 74, 7, 9, 31, 5, 1, 54, 2, 4, 51, 7, 9, 31, 7, 1, 29, 6, 5, 56, 3, 8, 18, 1, 4, 2, 9, 8, 30, 7, 3, 15, 3, 4, 40, 1, 8, 72, 3, 5, 80, 9, 3, 55, 6, 4, 5, 6, 1, 46, 1, 9, 81, 1, 2, 23, 3, 5, 80, 9, 7, 52, 4, 5, 14, 3, 6, 6, 1, @@ -493,7 +493,7 @@ namespace { 2, 71, 2, 4, 51, 8, 5, 10, 6, 1, 46, 2, 6, 3, 1, 6, 4, 4, 7, 20, }; - const int magicSquare9_filled50_1[] = { + const int magic_square9_filled50_1[] = { 9, 50, 7, 1, 29, 2, 9, 60, 2, 4, 51, 1, 8, 72, 8, 5, 10, 4, 6, 53, 3, 4, 40, 6, 2, 65, 8, 2, 19, 3, 6, 6, 6, 2, 65, 2, 8, 67, 2, 5, 76, 8, 9, 22, 6, 2, 65, 6, 1, 46, 2, 8, 67, 1, 4, 2, 9, 8, 30, 2, 5, 76, 3, 3, 38, 1, 3, 48, 4, 6, 53, 5, 1, 54, 7, 5, 1, 6, 1, 46, 4, 6, 53, 6, 5, 56, 1, 5, 28, 3, 6, 6, 4, 8, 34, 7, 6, 70, 4, @@ -501,7 +501,7 @@ namespace { 8, 30, 4, 2, 62, 3, 8, 18, 8, 7, 33, 4, 2, 62, 9, 8, 30, 5, 9, 7, }; - const int magicSquare9_filled50_20[] = { + const int magic_square9_filled50_20[] = { 9, 50, 8, 3, 44, 8, 2, 19, 3, 5, 80, 7, 8, 37, 8, 4, 77, 6, 5, 56, 4, 5, 14, 1, 3, 48, 2, 6, 3, 4, 3, 64, 9, 9, 45, 6, 6, 66, 8, 5, 10, 2, 6, 3, 1, 5, 28, 3, 7, 43, 8, 8, 39, 8, 8, 39, 1, 4, 2, 4, 8, 34, 5, 8, 11, 2, 8, 67, 1, 2, 23, 1, 2, 23, 7, 2, 71, 2, 7, 59, 1, 7, 79, 1, 6, 4, 2, 9, 60, 3, 1, 58, 3, 3, 38, 7, 8, 37, 9, @@ -509,7 +509,7 @@ namespace { 1, 8, 7, 9, 31, 1, 9, 81, 3, 7, 43, 7, 2, 71, 8, 2, 19, 8, 2, 19, }; - const int magicSquare9_filled50_2[] = { + const int magic_square9_filled50_2[] = { 9, 50, 2, 1, 27, 8, 8, 39, 6, 3, 21, 7, 6, 70, 8, 5, 10, 2, 9, 60, 7, 7, 42, 4, 5, 14, 8, 1, 68, 2, 3, 9, 3, 2, 50, 8, 1, 68, 8, 9, 22, 9, 5, 26, 7, 2, 71, 2, 8, 67, 2, 1, 27, 5, 6, 41, 3, 2, 50, 9, 8, 30, 4, 1, 47, 7, 9, 31, 7, 1, 29, 4, 4, 12, 2, 3, 9, 4, 2, 62, 4, 9, 63, 9, 9, 45, 8, 8, 39, 2, 5, 76, 1, 4, 2, 1, 9, 81, 4, @@ -517,7 +517,7 @@ namespace { 7, 79, 1, 9, 81, 9, 8, 30, 3, 7, 43, 5, 4, 74, 3, 8, 18, 7, 4, 73, }; - const int magicSquare9_filled50_3[] = { + const int magic_square9_filled50_3[] = { 9, 50, 8, 7, 33, 9, 8, 30, 4, 4, 12, 4, 1, 47, 3, 3, 38, 5, 9, 7, 1, 9, 81, 9, 7, 52, 9, 7, 52, 2, 7, 59, 7, 1, 29, 5, 9, 7, 8, 7, 33, 2, 8, 67, 3, 6, 6, 2, 1, 27, 3, 9, 36, 9, 6, 69, 3, 3, 38, 5, 3, 75, 4, 9, 63, 2, 4, 51, 6, 2, 65, 2, 5, 76, 8, 1, 68, 9, 5, 26, 2, 2, 17, 3, 7, 43, 9, 2, 49, 3, 2, 50, 7, 2, 71, 3, 1, 58, 1, @@ -525,7 +525,7 @@ namespace { 4, 51, 9, 4, 35, 4, 6, 53, 4, 6, 53, 6, 4, 5, 5, 1, 54, 7, 6, 70, }; - const int magicSquare9_filled50_4[] = { + const int magic_square9_filled50_4[] = { 9, 50, 8, 2, 19, 2, 6, 3, 9, 8, 30, 5, 6, 41, 4, 8, 34, 8, 9, 22, 9, 6, 69, 5, 5, 78, 4, 6, 53, 6, 3, 21, 8, 7, 33, 7, 2, 71, 1, 3, 48, 3, 5, 80, 1, 8, 72, 9, 9, 45, 9, 8, 30, 3, 6, 6, 6, 7, 25, 9, 7, 52, 3, 5, 80, 6, 3, 21, 2, 1, 27, 5, 3, 75, 5, 8, 11, 4, 1, 47, 6, 1, 46, 9, 6, 69, 1, 2, 23, 9, 2, 49, 7, 8, 37, 1, 4, 2, 4, @@ -533,7 +533,7 @@ namespace { 3, 9, 8, 8, 39, 2, 4, 51, 4, 2, 62, 7, 7, 42, 2, 5, 76, 4, 8, 34, }; - const int magicSquare9_filled50_5[] = { + const int magic_square9_filled50_5[] = { 9, 50, 8, 7, 33, 7, 7, 42, 5, 7, 16, 5, 1, 54, 8, 6, 57, 1, 1, 32, 9, 8, 30, 4, 2, 62, 5, 6, 41, 2, 1, 27, 2, 3, 9, 4, 6, 53, 2, 9, 60, 3, 3, 38, 4, 5, 14, 1, 9, 81, 9, 5, 26, 7, 2, 71, 9, 2, 49, 2, 8, 67, 7, 9, 31, 6, 5, 56, 5, 1, 54, 4, 7, 20, 4, 5, 14, 8, 5, 10, 5, 9, 7, 1, 6, 4, 8, 2, 19, 8, 9, 22, 6, 6, 66, 9, 3, 55, 1, @@ -541,7 +541,7 @@ namespace { 7, 43, 9, 8, 30, 6, 3, 21, 4, 5, 14, 6, 2, 65, 1, 1, 32, 2, 6, 3, }; - const int magicSquare9_filled50_6[] = { + const int magic_square9_filled50_6[] = { 9, 50, 4, 7, 20, 6, 7, 25, 9, 1, 8, 4, 1, 47, 8, 7, 33, 4, 8, 34, 6, 4, 5, 5, 4, 74, 9, 5, 26, 1, 9, 81, 1, 7, 79, 9, 4, 35, 2, 5, 76, 5, 1, 54, 3, 5, 80, 4, 7, 20, 9, 7, 52, 2, 8, 67, 7, 3, 15, 7, 3, 15, 7, 1, 29, 1, 1, 32, 2, 3, 9, 5, 1, 54, 5, 5, 78, 7, 5, 1, 9, 5, 26, 6, 2, 65, 7, 8, 37, 9, 1, 8, 1, 1, 32, 5, 1, 54, 7, @@ -549,7 +549,7 @@ namespace { 5, 10, 9, 5, 26, 5, 1, 54, 5, 7, 16, 8, 2, 19, 1, 4, 2, 3, 3, 38, }; - const int magicSquare9_filled50_7[] = { + const int magic_square9_filled50_7[] = { 9, 50, 6, 3, 21, 7, 6, 70, 3, 4, 40, 5, 2, 13, 6, 6, 66, 7, 8, 37, 8, 6, 57, 8, 1, 68, 2, 9, 60, 4, 8, 34, 7, 3, 15, 2, 3, 9, 4, 3, 64, 2, 2, 17, 7, 2, 71, 3, 3, 38, 4, 9, 63, 8, 4, 77, 2, 4, 51, 3, 5, 80, 7, 1, 29, 3, 5, 80, 6, 1, 46, 4, 7, 20, 1, 5, 28, 3, 5, 80, 8, 4, 77, 7, 2, 71, 6, 8, 61, 3, 3, 38, 8, 4, 77, 3, 9, 36, 1, @@ -557,7 +557,7 @@ namespace { 2, 50, 2, 4, 51, 3, 7, 43, 5, 5, 78, 4, 5, 14, 4, 7, 20, 5, 4, 74, }; - const int magicSquare9_filled50_8[] = { + const int magic_square9_filled50_8[] = { 9, 50, 2, 8, 67, 1, 3, 48, 5, 8, 11, 3, 8, 18, 8, 6, 57, 1, 2, 23, 1, 8, 72, 3, 8, 18, 2, 4, 51, 7, 1, 29, 5, 9, 7, 5, 9, 7, 5, 8, 11, 4, 6, 53, 4, 8, 34, 1, 3, 48, 5, 8, 11, 5, 7, 16, 6, 5, 56, 5, 3, 75, 9, 4, 35, 4, 9, 63, 9, 5, 26, 5, 8, 11, 8, 2, 19, 6, 3, 21, 9, 1, 8, 2, 4, 51, 7, 3, 15, 9, 1, 8, 9, 7, 52, 1, 2, 23, 6, @@ -565,7 +565,7 @@ namespace { 2, 71, 5, 5, 78, 2, 2, 17, 2, 9, 60, 3, 7, 43, 2, 2, 17, 7, 9, 31, }; - const int magicSquare9_filled50_9[] = { + const int magic_square9_filled50_9[] = { 9, 50, 3, 8, 18, 6, 7, 25, 2, 9, 60, 8, 9, 22, 7, 8, 37, 3, 3, 38, 5, 6, 41, 8, 2, 19, 8, 4, 77, 3, 4, 40, 8, 2, 19, 5, 9, 7, 8, 8, 39, 5, 9, 7, 7, 9, 31, 9, 9, 45, 5, 5, 78, 4, 7, 20, 3, 9, 36, 4, 9, 63, 8, 5, 10, 9, 3, 55, 8, 6, 57, 2, 7, 59, 9, 2, 49, 1, 7, 79, 1, 3, 48, 4, 8, 34, 8, 6, 57, 7, 5, 1, 5, 6, 41, 2, 1, 27, 9, @@ -574,79 +574,79 @@ namespace { }; const int* specs[] = { - magicSquare5_filled10_1, // 0 - magicSquare5_filled10_2, // 1 - magicSquare5_filled10_3, // 2 - magicSquare5_filled10_4, // 3 - magicSquare5_filled10_5, // 4 - magicSquare5_filled10_6, // 5 - magicSquare5_filled10_7, // 6 - magicSquare5_filled10_8, // 7 - magicSquare5_filled10_9, // 8 - magicSquare5_filled10_10, // 9 - magicSquare5_filled10_11, // 10 - magicSquare5_filled10_12, // 11 - magicSquare5_filled10_13, // 12 - magicSquare5_filled10_14, // 13 - magicSquare5_filled10_15, // 14 - magicSquare5_filled10_16, // 15 - magicSquare5_filled10_17, // 16 - magicSquare5_filled10_18, // 17 - magicSquare5_filled10_19, // 18 - magicSquare5_filled10_20, // 19 - magicSquare5_filled11_3_1, // 20 - magicSquare5_filled11_5_1, // 21 - magicSquare5_filled11_5_2, // 22 - magicSquare5_filled11_5_3, // 23 - magicSquare5_filled12_10_1, // 24 - magicSquare5_filled12_1_1, // 25 - magicSquare5_filled12_1_2, // 26 - magicSquare5_filled12_1_3, // 27 - magicSquare5_filled12_2_1, // 28 - magicSquare5_filled12_2_2, // 29 - magicSquare5_filled12_2_3, // 30 - magicSquare5_filled12_3_1, // 31 - magicSquare5_filled12_3_2, // 32 - magicSquare9_filled10_1, // 33 - magicSquare9_filled10_2, // 34 - magicSquare9_filled10_3, // 35 - magicSquare9_filled10_4, // 36 - magicSquare9_filled10_5, // 37 - magicSquare9_filled10_6, // 38 - magicSquare9_filled10_7, // 39 - magicSquare9_filled10_8, // 40 - magicSquare9_filled10_9, // 41 - magicSquare9_filled10_10, // 42 - magicSquare9_filled10_11, // 43 - magicSquare9_filled10_12, // 44 - magicSquare9_filled10_13, // 45 - magicSquare9_filled10_14, // 46 - magicSquare9_filled10_15, // 47 - magicSquare9_filled10_16, // 48 - magicSquare9_filled10_17, // 49 - magicSquare9_filled10_18, // 50 - magicSquare9_filled10_19, // 51 - magicSquare9_filled10_20, // 52 - magicSquare9_filled50_1, // 53 - magicSquare9_filled50_2, // 54 - magicSquare9_filled50_3, // 55 - magicSquare9_filled50_4, // 56 - magicSquare9_filled50_5, // 57 - magicSquare9_filled50_6, // 58 - magicSquare9_filled50_7, // 59 - magicSquare9_filled50_8, // 60 - magicSquare9_filled50_9, // 61 - magicSquare9_filled50_10, // 62 - magicSquare9_filled50_11, // 63 - magicSquare9_filled50_12, // 64 - magicSquare9_filled50_13, // 65 - magicSquare9_filled50_14, // 66 - magicSquare9_filled50_15, // 67 - magicSquare9_filled50_16, // 68 - magicSquare9_filled50_17, // 69 - magicSquare9_filled50_18, // 70 - magicSquare9_filled50_19, // 71 - magicSquare9_filled50_20 // 72 + magic_square5_filled10_1, // 0 + magic_square5_filled10_2, // 1 + magic_square5_filled10_3, // 2 + magic_square5_filled10_4, // 3 + magic_square5_filled10_5, // 4 + magic_square5_filled10_6, // 5 + magic_square5_filled10_7, // 6 + magic_square5_filled10_8, // 7 + magic_square5_filled10_9, // 8 + magic_square5_filled10_10, // 9 + magic_square5_filled10_11, // 10 + magic_square5_filled10_12, // 11 + magic_square5_filled10_13, // 12 + magic_square5_filled10_14, // 13 + magic_square5_filled10_15, // 14 + magic_square5_filled10_16, // 15 + magic_square5_filled10_17, // 16 + magic_square5_filled10_18, // 17 + magic_square5_filled10_19, // 18 + magic_square5_filled10_20, // 19 + magic_square5_filled11_3_1, // 20 + magic_square5_filled11_5_1, // 21 + magic_square5_filled11_5_2, // 22 + magic_square5_filled11_5_3, // 23 + magic_square5_filled12_10_1, // 24 + magic_square5_filled12_1_1, // 25 + magic_square5_filled12_1_2, // 26 + magic_square5_filled12_1_3, // 27 + magic_square5_filled12_2_1, // 28 + magic_square5_filled12_2_2, // 29 + magic_square5_filled12_2_3, // 30 + magic_square5_filled12_3_1, // 31 + magic_square5_filled12_3_2, // 32 + magic_square9_filled10_1, // 33 + magic_square9_filled10_2, // 34 + magic_square9_filled10_3, // 35 + magic_square9_filled10_4, // 36 + magic_square9_filled10_5, // 37 + magic_square9_filled10_6, // 38 + magic_square9_filled10_7, // 39 + magic_square9_filled10_8, // 40 + magic_square9_filled10_9, // 41 + magic_square9_filled10_10, // 42 + magic_square9_filled10_11, // 43 + magic_square9_filled10_12, // 44 + magic_square9_filled10_13, // 45 + magic_square9_filled10_14, // 46 + magic_square9_filled10_15, // 47 + magic_square9_filled10_16, // 48 + magic_square9_filled10_17, // 49 + magic_square9_filled10_18, // 50 + magic_square9_filled10_19, // 51 + magic_square9_filled10_20, // 52 + magic_square9_filled50_1, // 53 + magic_square9_filled50_2, // 54 + magic_square9_filled50_3, // 55 + magic_square9_filled50_4, // 56 + magic_square9_filled50_5, // 57 + magic_square9_filled50_6, // 58 + magic_square9_filled50_7, // 59 + magic_square9_filled50_8, // 60 + magic_square9_filled50_9, // 61 + magic_square9_filled50_10, // 62 + magic_square9_filled50_11, // 63 + magic_square9_filled50_12, // 64 + magic_square9_filled50_13, // 65 + magic_square9_filled50_14, // 66 + magic_square9_filled50_15, // 67 + magic_square9_filled50_16, // 68 + magic_square9_filled50_17, // 69 + magic_square9_filled50_18, // 70 + magic_square9_filled50_19, // 71 + magic_square9_filled50_20 // 72 }; const unsigned n_examples = sizeof(specs) / sizeof(int*); diff --git a/examples/magic-square.cpp b/examples/magic-square.cpp index c2f94489ee..9d10600cff 100644 --- a/examples/magic-square.cpp +++ b/examples/magic-square.cpp @@ -109,13 +109,13 @@ class MagicSquare : public Script { } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new MagicSquare(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { // Matrix-wrapper for the square Matrix m(x, n, n); for (int i = 0; i < n; i++) { @@ -124,7 +124,7 @@ class MagicSquare : public Script { os.width(2); os << m(i, j) << " "; } - os << std::endl; + os << '\n'; } } }; diff --git a/examples/minesweeper.cpp b/examples/minesweeper.cpp index d0e9d99ef9..5b7f2e95d2 100644 --- a/examples/minesweeper.cpp +++ b/examples/minesweeper.cpp @@ -42,7 +42,7 @@ namespace { extern const char* specs[]; extern const unsigned int n_examples; int spec_size(const char* s); - int mineField(const char* s, int n, int i, int j); + int mine_field(const char* s, int n, int i, int j); } // namespace /** @@ -75,7 +75,7 @@ class MineSweeper : public Script { /// Return the fields in \a m around position (\a x,\a y) BoolVarArgs - fieldsAround(Matrix& m, int x, int y) { + fields_around(Matrix& m, int x, int y) { int bvsize = 0; for (int ix = std::max(0, x - 1); ix <= x + 1 && ix < size; ix++) for (int iy = std::max(0, y - 1); iy <= y + 1 && iy < size; iy++) @@ -100,10 +100,10 @@ class MineSweeper : public Script { // Initialize matrix and post constraints for (int h = 0; h < size; h++) for (int w = 0; w < size; w++) { - int v = mineField(spec, size, h, w); + int v = mine_field(spec, size, h, w); if (v != -1) { rel(*this, m(w, h), IRT_EQ, 0); - linear(*this, fieldsAround(m, w, h), IRT_EQ, v); + linear(*this, fields_around(m, w, h), IRT_EQ, v); } } @@ -112,12 +112,12 @@ class MineSweeper : public Script { } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { for (int h = 0; h < size; ++h) { os << '\t'; for (int w = 0; w < size; ++w) { - int v = mineField(spec, size, h, w); + int v = mine_field(spec, size, h, w); if (v != -1) os << v << " "; else if (pos(h, w).val() == 1) @@ -125,9 +125,9 @@ class MineSweeper : public Script { else os << ". "; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } /// Constructor for cloning \a s @@ -135,8 +135,8 @@ class MineSweeper : public Script { b.update(*this, s.b); } /// Copy space during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new MineSweeper(*this); } }; @@ -150,7 +150,7 @@ main(int argc, char* argv[]) { opt.size(0); opt.parse(argc, argv); if (opt.size() >= n_examples) { - std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_examples - 1 << '\n'; return 1; } Script::run(opt); @@ -280,7 +280,7 @@ namespace { /// Return value at position (\a i,\a j) in the example \a s of size \a n int - mineField(const char* s, int n, int i, int j) { + mine_field(const char* s, int n, int i, int j) { assert(spec_size(s) == n); assert(i >= 0 && i < n); assert(j >= 0 && j < n); diff --git a/examples/money.cpp b/examples/money.cpp index deb14d1150..823ed987cb 100644 --- a/examples/money.cpp +++ b/examples/money.cpp @@ -98,9 +98,9 @@ class Money : public Script { }); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\t" << le << std::endl; + void + print(std::ostream& os) const override { + os << "\t" << le << '\n'; } /// Constructor for cloning \a s @@ -108,8 +108,8 @@ class Money : public Script { le.update(*this, s.le); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Money(*this); } }; diff --git a/examples/multi-bin-packing.cpp b/examples/multi-bin-packing.cpp index ee365fc79b..5e60b43f8a 100644 --- a/examples/multi-bin-packing.cpp +++ b/examples/multi-bin-packing.cpp @@ -156,7 +156,7 @@ class MultiBinPacking : public Script { for (int i = 0; i < spec.items(); i++) s[i] = spec.size(i, k); - binpacking(*this, l, bin, s); + bin_packing(*this, l, bin, s); } } break; case MODEL_MULTI: { @@ -171,8 +171,8 @@ class MultiBinPacking : public Script { for (int k = 0; k < spec.dimension(); k++) s[i * spec.dimension() + k] = spec.size(i, k); - // Post multidimensional binpacking constraint - IntSet mc = binpacking(*this, spec.dimension(), load, bin, s, c); + // Post multidimensional bin_packing constraint + IntSet mc = bin_packing(*this, spec.dimension(), load, bin, s, c); // Symmetry breaking if (opt.symmetry() == SYMMETRY_MAX_CONFLICT) { @@ -202,14 +202,14 @@ class MultiBinPacking : public Script { load.update(*this, s.load); } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new MultiBinPacking(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tInstance: " << spec.iname() << std::endl; + void + print(std::ostream& os) const override { + os << "\tInstance: " << spec.iname() << '\n'; if (bin.assigned()) { for (int j = 0; j < spec.bins(); j++) { os << "\tbin[" << j << "]: "; @@ -219,10 +219,10 @@ class MultiBinPacking : public Script { os << "\n\t\tloads: "; for (int k = 0; k < spec.dimension(); k++) os << load[j * spec.dimension() + k] << " "; - os << std::endl; + os << '\n'; } } else { - os << "\tbins: " << bin << std::endl << "\tload: " << load << std::endl; + os << "\tbins: " << bin << '\n' << "\tload: " << load << '\n'; } } }; @@ -247,7 +247,7 @@ main(int argc, char* argv[]) { opt.solutions(1); opt.parse(argc, argv); if (!Spec(opt.instance()).valid()) { - std::cerr << "Error: unknown instance" << std::endl; + std::cerr << "Error: unknown instance" << '\n'; return 1; } Script::run(opt); diff --git a/examples/nonogram.cpp b/examples/nonogram.cpp index 2f67351afd..47532b12db 100644 --- a/examples/nonogram.cpp +++ b/examples/nonogram.cpp @@ -243,22 +243,22 @@ class Nonogram : public Script { } /// Copy space during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Nonogram(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Matrix m(b, width(), height()); for (int h = 0; h < height(); ++h) { os << '\t'; for (int w = 0; w < width(); ++w) os << ((m(w, h).val() == 1) ? '#' : ' '); - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } }; @@ -276,12 +276,11 @@ main(int argc, char* argv[]) { try { IntSharedArray file; if (specification(opt, file) == nullptr) { - std::cerr << "Error: instance must be a number between 0 and " << n_examples - 1 << " or a file" - << std::endl; + std::cerr << "Error: instance must be a number between 0 and " << n_examples - 1 << " or a file" << '\n'; return 1; } } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } Script::run(opt); diff --git a/examples/open-route.cpp b/examples/open-route.cpp index db9f1985aa..14f5b5bfab 100644 --- a/examples/open-route.cpp +++ b/examples/open-route.cpp @@ -109,7 +109,7 @@ class OpenRoute : public Script { os << " -> "; os << route[i]; } - os << " (length " << route.length() << ")" << std::endl; + os << " (length " << route.length() << ")" << '\n'; } }; diff --git a/examples/open-shop.cpp b/examples/open-shop.cpp index 603dabfe5f..92ed0f8aac 100644 --- a/examples/open-shop.cpp +++ b/examples/open-shop.cpp @@ -129,37 +129,37 @@ class OpenShop : public IntMinimizeScript { new (&tasks[k++]) Task(j, i, dur(i, j)); int* t0_tasks = re.alloc(spec.n * spec.m); // Earliest possible tasks - bool stopCROSH = false; + bool stop_crosh = false; - int maxIterations; + int max_iterations; switch (spec.n) { case 3: - maxIterations = 5; + max_iterations = 5; break; case 4: - maxIterations = 25; + max_iterations = 25; break; case 5: - maxIterations = 50; + max_iterations = 50; break; case 6: - maxIterations = 1000; + max_iterations = 1000; break; case 7: - maxIterations = 10000; + max_iterations = 10000; break; case 8: - maxIterations = 10000; + max_iterations = 10000; break; case 9: - maxIterations = 10000; + max_iterations = 10000; break; default: - maxIterations = 25000; + max_iterations = 25000; break; } int iteration = 0; - while (!stopCROSH && maxmakespan > minmakespan) { + while (!stop_crosh && maxmakespan > minmakespan) { for (int i = spec.n; i--;) ct_j[i] = 0; for (int i = spec.m; i--;) @@ -201,8 +201,8 @@ class OpenShop : public IntMinimizeScript { } maxmakespan = std::min(maxmakespan, cmax); - if (iteration++ > maxIterations) - stopCROSH = true; // Iterate a couple of times + if (iteration++ > max_iterations) + stop_crosh = true; // Iterate a couple of times } } @@ -263,14 +263,14 @@ class OpenShop : public IntMinimizeScript { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new OpenShop(*this); } /// Minimize the makespan - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return makespan; } @@ -288,8 +288,8 @@ class OpenShop : public IntMinimizeScript { }; /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Region re; PrintTask* m = re.alloc(spec.n); for (int i = 0; i < spec.m; i++) { @@ -304,9 +304,9 @@ class OpenShop : public IntMinimizeScript { os << "Machine " << i << ": "; for (int j = 0; j < spec.n; j++) os << "\t" << m[j].job << "(" << m[j].p << ")"; - os << " = " << m[spec.n - 1].start + m[spec.n - 1].p << std::endl; + os << " = " << m[spec.n - 1].start + m[spec.n - 1].p << '\n'; } - os << "Makespan: " << makespan << std::endl; + os << "Makespan: " << makespan << '\n'; } }; @@ -321,7 +321,7 @@ main(int argc, char* argv[]) { opt.solutions(0); opt.parse(argc, argv); if (opt.size() >= n_examples) { - std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_examples - 1 << '\n'; return 1; } IntMinimizeScript::run(opt); diff --git a/examples/ortho-latin.cpp b/examples/ortho-latin.cpp index 3d2605560f..89baa02bd9 100644 --- a/examples/ortho-latin.cpp +++ b/examples/ortho-latin.cpp @@ -133,31 +133,31 @@ class OrthoLatinSquare : public Script { } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new OrthoLatinSquare(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { for (int i = 0; i < n; i++) { os << "\t"; for (int j = 0; j < n; j++) { os.width(2); os << y1(i, j) << " "; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; for (int i = 0; i < n; i++) { os << "\t"; for (int j = 0; j < n; j++) { os.width(2); os << y2(i, j) << " "; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } }; diff --git a/examples/partition.cpp b/examples/partition.cpp index 93db6ddd6e..f9e32e8186 100644 --- a/examples/partition.cpp +++ b/examples/partition.cpp @@ -55,10 +55,10 @@ class Partition : public Script { const int n = opt.size(); // Break symmetries by ordering numbers in each group - rel(*this, x, IRT_LE); - rel(*this, y, IRT_LE); + rel(*this, x, IRT_LT); + rel(*this, y, IRT_LT); - rel(*this, x[0], IRT_LE, y[0]); + rel(*this, x[0], IRT_LT, y[0]); IntVarArgs xy(2 * n); for (int i = n; i--;) { @@ -98,13 +98,13 @@ class Partition : public Script { y.update(*this, s.y); } /// Copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Partition(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << "\t"; int a, b; a = b = 0; @@ -113,14 +113,14 @@ class Partition : public Script { b += x[i].val() * x[i].val(); os << x[i] << ", "; } - os << " = " << a << ", " << b << std::endl << "\t"; + os << " = " << a << ", " << b << '\n' << "\t"; a = b = 0; for (int i = 0; i < y.size(); i++) { a += y[i].val(); b += y[i].val() * y[i].val(); os << y[i] << ", "; } - os << " = " << a << ", " << b << std::endl; + os << " = " << a << ", " << b << '\n'; } }; diff --git a/examples/pentominoes.cpp b/examples/pentominoes.cpp index bc469bec0e..097a17964a 100644 --- a/examples/pentominoes.cpp +++ b/examples/pentominoes.cpp @@ -441,14 +441,14 @@ class Pentominoes : public Script { } /// Copy space during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Pentominoes(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { for (int h = 0; h < height; ++h) { os << "\t"; for (int w = 0; w < width - 1; ++w) { @@ -456,9 +456,9 @@ class Pentominoes : public Script { char c = val < 10 ? '0' + val : 'A' + (val - 10); os << c; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } }; @@ -479,7 +479,7 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); if (opt.size() >= n_examples) { - std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_examples - 1 << '\n'; return 1; } Script::run(opt); @@ -838,7 +838,7 @@ namespace { int pos(int h, int w, int h1, int w1) { if (!(0 <= h && h < h1) || !(0 <= w && w < w1)) { - std::cerr << "Cannot place (" << h << "," << w << ") on board of size " << h1 << "x" << w1 << std::endl; + std::cerr << "Cannot place (" << h << "," << w << ") on board of size " << h1 << "x" << w1 << '\n'; } return h * w1 + w; } diff --git a/examples/perfect-square.cpp b/examples/perfect-square.cpp index 272f5a03e6..0102864c94 100644 --- a/examples/perfect-square.cpp +++ b/examples/perfect-square.cpp @@ -155,7 +155,7 @@ class PerfectSquare : public Script { IntArgs sa(n, s); // Squares do not overlap - nooverlap(*this, x, sa, y, sa); + no_overlap(*this, x, sa, y, sa); /* * Capacity constraints @@ -214,17 +214,17 @@ class PerfectSquare : public Script { y.update(*this, s.y); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new PerfectSquare(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << "\t"; for (int i = 0; i < x.size(); i++) os << "(" << x[i] << "," << y[i] << ") "; - os << std::endl; + os << '\n'; } }; @@ -239,7 +239,7 @@ main(int argc, char* argv[]) { opt.c_d(20); opt.parse(argc, argv); if (opt.size() >= n_specs) { - std::cerr << "Error: size must be between 0 and " << n_specs - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_specs - 1 << '\n'; return 1; } Script::run(opt); diff --git a/examples/photo.cpp b/examples/photo.cpp index cd783301ee..72bee61b78 100644 --- a/examples/photo.cpp +++ b/examples/photo.cpp @@ -120,7 +120,7 @@ class Photo : public IntMinimizeScript { branch(*this, pos, INT_VAR_NONE(), INT_VAL_MIN()); break; case BRANCH_DEGREE: - branch(*this, pos, tiebreak(INT_VAR_DEGREE_MAX(), INT_VAR_SIZE_MIN()), INT_VAL_MIN()); + branch(*this, pos, tie_break(INT_VAR_DEGREE_MAX(), INT_VAR_SIZE_MIN()), INT_VAL_MIN()); break; case BRANCH_AFC_SIZE: branch(*this, pos, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN()); @@ -129,7 +129,7 @@ class Photo : public IntMinimizeScript { } /// Relax the last solution for large neighbourhood search void - spoke(SpokeContext& sc) { + spoke(SpokeContext& sc) override { if ((sc.engine() == MetaEngine::Restart) && (sc.last() != nullptr) && (p > 0.0)) { const Photo& l = static_cast(*sc.last()); relax(*this, pos, l.pos, rnd.split(sc), p); @@ -142,18 +142,18 @@ class Photo : public IntMinimizeScript { violations.update(*this, s.violations); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Photo(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tpos[] = " << pos << std::endl << "\tviolations: " << violations << std::endl; + void + print(std::ostream& os) const override { + os << "\tpos[] = " << pos << '\n' << "\tviolations: " << violations << '\n'; } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return violations; } }; @@ -176,7 +176,7 @@ main(int argc, char* argv[]) { opt.branching(Photo::BRANCH_AFC_SIZE, "afc"); opt.parse(argc, argv); if (opt.size() >= n_pi) { - std::cerr << "Error: size must be between 0 and " << n_pi - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << n_pi - 1 << '\n'; return 1; } IntMinimizeScript::run(opt); diff --git a/examples/qcp.cpp b/examples/qcp.cpp index 00884501c8..f5b95fd83f 100644 --- a/examples/qcp.cpp +++ b/examples/qcp.cpp @@ -198,7 +198,7 @@ class QCP : public Script { switch (opt.branching()) { case BRANCH_CBS_MAX_SD: #ifdef GECODE_HAS_CBS - cbsbranch(*this, e); + cbs_branch(*this, e); #endif case BRANCH_SIZE: branch(*this, e, INT_VAR_SIZE_MIN(), INT_VAL_MIN()); @@ -210,8 +210,8 @@ class QCP : public Script { } } /// Post a different branching for each asset of portfolio search - virtual void - spoke(SpokeContext& sc) { + void + spoke(SpokeContext& sc) override { if (sc.engine() == MetaEngine::Portfolio) { double tbf = opt.tbf(); Rnd r(seeds[sc.asset() % n_seeds]); @@ -221,14 +221,14 @@ class QCP : public Script { assert(w >= b); return b + (w - b) * tbf; }; - branch(*this, e, tiebreak(INT_VAR_SIZE_MIN(tbl), INT_VAR_RND(r)), INT_VAL_MIN()); + branch(*this, e, tie_break(INT_VAR_SIZE_MIN(tbl), INT_VAR_RND(r)), INT_VAL_MIN()); } break; case BRANCH_AFC_SIZE: { auto tbl = [tbf](const Space&, double w, double b) { assert(b >= w); return b - (b - w) * tbf; }; - branch(*this, e, tiebreak(INT_VAR_AFC_SIZE_MAX(opt.decay(), tbl), INT_VAR_RND(r)), INT_VAL_MIN()); + branch(*this, e, tie_break(INT_VAR_AFC_SIZE_MAX(opt.decay(), tbl), INT_VAR_RND(r)), INT_VAL_MIN()); } break; default:; } @@ -239,13 +239,13 @@ class QCP : public Script { e.update(*this, s.e); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new QCP(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { int n = spec.size(); Matrix m(e, n); @@ -256,7 +256,7 @@ class QCP : public Script { os.width(2); os << m(i, j) << " "; } - os << std::endl; + os << '\n'; } } }; @@ -285,7 +285,7 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); if (!Spec(opt.instance()).valid()) { - std::cerr << "Error: unknown instance" << std::endl; + std::cerr << "Error: unknown instance" << '\n'; return 1; } Script::run(opt); diff --git a/examples/queen-armies.cpp b/examples/queen-armies.cpp index 6580453ebc..585641650c 100644 --- a/examples/queen-armies.cpp +++ b/examples/queen-armies.cpp @@ -41,7 +41,7 @@ using namespace Gecode; * * \relates QueenArmies */ -IntSet* A; +IntSet* a; /** * \brief %Example: Peaceable co-existing armies of queens @@ -65,11 +65,11 @@ IntSet* A; class QueenArmies : public IntMaximizeScript { public: const int n; - SetVar U, ///< Set of un-attacked squares - W; ///< Set of squares occupied by white queens - BoolVarArray w, ///< The placement of the white queens - b; ///< The placement of the black queens - IntVar q; ///< The number of white queens placed. + SetVar u, ///< Set of un-attacked squares + white_positions; ///< Set of squares occupied by white queens + BoolVarArray white_matrix, ///< The placement of the white queens + b; ///< The placement of the black queens + IntVar q; ///< The number of white queens placed. /// Branching to use for model enum { @@ -79,29 +79,30 @@ class QueenArmies : public IntMaximizeScript { /// Constructor QueenArmies(const SizeOptions& opt) - : IntMaximizeScript(opt), n(opt.size()), U(*this, IntSet::empty, IntSet(0, n * n)), - W(*this, IntSet::empty, IntSet(0, n * n)), w(*this, n * n, 0, 1), b(*this, n * n, 0, 1), q(*this, 0, n * n) { + : IntMaximizeScript(opt), n(opt.size()), u(*this, IntSet::empty, IntSet(0, n * n)), + white_positions(*this, IntSet::empty, IntSet(0, n * n)), white_matrix(*this, n * n, 0, 1), + b(*this, n * n, 0, 1), q(*this, 0, n * n) { // Basic rules of the model for (int i = n * n; i--;) { // w[i] means that no blacks are allowed on A[i] - rel(*this, w[i] == (U || A[i])); + rel(*this, white_matrix[i] == (u || a[i])); // Make sure blacks and whites are disjoint. - rel(*this, !w[i] || !b[i]); + rel(*this, !white_matrix[i] || !b[i]); // If i in U, then b[i] has a piece. - rel(*this, b[i] == (singleton(i) <= U)); + rel(*this, b[i] == (singleton(i) <= u)); } // Connect optimization variable to number of pieces - linear(*this, w, IRT_EQ, q); + linear(*this, white_matrix, IRT_EQ, q); linear(*this, b, IRT_GQ, q); // Connect cardinality of U to the number of black pieces. - IntVar unknowns = expr(*this, cardinality(U)); + IntVar unknowns = expr(*this, cardinality(u)); rel(*this, q <= unknowns); linear(*this, b, IRT_EQ, unknowns); if (opt.branching() == BRANCH_NAIVE) { - branch(*this, w, BOOL_VAR_NONE(), BOOL_VAL_MAX()); + branch(*this, white_matrix, BOOL_VAR_NONE(), BOOL_VAL_MAX()); branch(*this, b, BOOL_VAR_NONE(), BOOL_VAL_MAX()); } else { QueenBranch::post(*this); @@ -110,39 +111,39 @@ class QueenArmies : public IntMaximizeScript { } /// Constructor for cloning QueenArmies(QueenArmies& s) : IntMaximizeScript(s), n(s.n) { - U.update(*this, s.U); - W.update(*this, s.W); - w.update(*this, s.w); + u.update(*this, s.u); + white_positions.update(*this, s.white_positions); + white_matrix.update(*this, s.white_matrix); b.update(*this, s.b); q.update(*this, s.q); } /// Return copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new QueenArmies(*this); } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return q; } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << '\t'; for (int i = 0; i < n * n; ++i) { - if (w[i].assigned() && w[i].val()) + if (white_matrix[i].assigned() && white_matrix[i].val()) os << "W"; else if (b[i].assigned() && b[i].val()) os << "B"; - else if (!w[i].assigned() && !b[i].assigned()) + else if (!white_matrix[i].assigned() && !b[i].assigned()) os << " "; else os << "."; if ((i + 1) % n == 0) - os << std::endl << (i != (n * n - 1) ? "\t" : ""); + os << '\n' << (i != (n * n - 1) ? "\t" : ""); } - os << "Number of white queens: " << q << std::endl << std::endl; + os << "Number of white queens: " << q << '\n' << '\n'; } /** \brief Custom brancher for Peacable queens @@ -168,8 +169,8 @@ class QueenArmies : public IntMaximizeScript { */ Choice(const Brancher& b, int pos0, bool val0) : Gecode::Choice(b, 2), pos(pos0), val(val0) {} /// Archive into \a e - virtual void - archive(Archive& e) const { + void + archive(Archive& e) const override { Gecode::Choice::archive(e); e << pos << val; } @@ -182,11 +183,11 @@ class QueenArmies : public IntMaximizeScript { public: /// Check status of brancher, return true if alternatives left. - virtual bool - status(const Space& home) const { + bool + status(const Space& home) const override { const QueenArmies& q = static_cast(home); for (int i = start; i < q.n * q.n; ++i) - if (!q.w[i].assigned()) { + if (!q.white_matrix[i].assigned()) { start = i; return true; } @@ -194,18 +195,18 @@ class QueenArmies : public IntMaximizeScript { return false; } /// Return choice - virtual Gecode::Choice* - choice(Space& home) { + Gecode::Choice* + choice(Space& home) override { const QueenArmies& q = static_cast(home); int maxsize = -1; int pos = -1; for (int i = start; i < q.n * q.n; ++i) { - if (q.w[i].assigned()) + if (q.white_matrix[i].assigned()) continue; - IntSetRanges ai(A[i]); - SetVarUnknownRanges qU(q.U); - Iter::Ranges::Inter r(ai, qU); + IntSetRanges ai(a[i]); + SetVarUnknownRanges q_u(q.u); + Iter::Ranges::Inter r(ai, q_u); int size = Iter::Ranges::size(r); if (size > maxsize) { maxsize = size; @@ -217,8 +218,8 @@ class QueenArmies : public IntMaximizeScript { return new Choice(*this, pos, true); } /// Return choice - virtual Choice* - choice(const Space&, Archive& e) { + Choice* + choice(const Space&, Archive& e) override { int pos, val; e >> pos >> val; return new Choice(*this, pos, val); @@ -226,23 +227,23 @@ class QueenArmies : public IntMaximizeScript { /** \brief Perform commit for choice \a _c and * alternative \a a. */ - virtual ExecStatus - commit(Space& home, const Gecode::Choice& _c, unsigned int a) { + ExecStatus + commit(Space& home, const Gecode::Choice& _c, unsigned int a) override { QueenArmies& q = static_cast(home); const Choice& c = static_cast(_c); bool val = (a == 0) ? c.val : !c.val; - return me_failed(Int::BoolView(q.w[c.pos]).eq(q, val)) ? ES_FAILED : ES_OK; + return me_failed(Int::BoolView(q.white_matrix[c.pos]).eq(q, val)) ? ES_FAILED : ES_OK; } /// Print explanation - virtual void - print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const { + void + print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const override { const Choice& c = static_cast(_c); bool val = (a == 0) ? c.val : !c.val; o << "w[" << c.pos << "] = " << val; } /// Copy brancher during cloning - virtual Actor* - copy(Space& home) { + Actor* + copy(Space& home) override { return new (home) QueenBranch(home, *this); } /// Post brancher @@ -251,8 +252,8 @@ class QueenArmies : public IntMaximizeScript { (void)new (home) QueenBranch(home); } /// Delete brancher and return its size - virtual size_t - dispose(Space&) { + size_t + dispose(Space&) override { return sizeof(*this); } }; @@ -278,7 +279,7 @@ main(int argc, char* argv[]) { // Set up the A-sets // A[i] will contain the values attacked by a queen at position i int n = opt.size(); - A = new IntSet[n * n]; + a = new IntSet[n * n]; int* p = new int[std::max(n * n, 25)]; int pn = 0; for (int i = n; i--;) { @@ -293,7 +294,7 @@ main(int argc, char* argv[]) { } } - A[pos(i, j, n)] = IntSet(p, pn); + a[pos(i, j, n)] = IntSet(p, pn); pn = 0; } diff --git a/examples/queens.cpp b/examples/queens.cpp index b4aa208e6f..3e8c00e51a 100644 --- a/examples/queens.cpp +++ b/examples/queens.cpp @@ -97,21 +97,21 @@ class Queens : public Script { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Queens(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << "queens\t"; for (int i = 0; i < q.size(); i++) { os << q[i] << ", "; if ((i + 1) % 10 == 0) - os << std::endl << "\t"; + os << '\n' << "\t"; } - os << std::endl; + os << '\n'; } }; @@ -130,13 +130,15 @@ class QueensInspector : public Gist::Inspector { /// Constructor QueensInspector(void) : scene(nullptr), mw(nullptr) {} /// Inspect space \a s - virtual void - inspect(const Space& s) { + void + inspect(const Space& s) override { const Queens& q = static_cast(s); + const int inset = unit / 4; + const int diameter = unit / 2; if (!scene) initialize(); - QList itemList = scene->items(); + QList item_list = scene->items(); foreach (QGraphicsItem* i, scene->items()) { scene->removeItem(i); delete i; @@ -149,7 +151,7 @@ class QueensInspector : public Gist::Inspector { QBrush b(q.q[i].assigned() ? Qt::black : Qt::red); QPen p(q.q[i].assigned() ? Qt::black : Qt::white); for (IntVarValues xv(q.q[i]); xv(); ++xv) { - scene->addEllipse(QRectF(i * unit + unit / 4, xv.val() * unit + unit / 4, unit / 2, unit / 2), p, b); + scene->addEllipse(QRectF(i * unit + inset, xv.val() * unit + inset, diameter, diameter), p, b); } } mw->show(); @@ -165,20 +167,20 @@ class QueensInspector : public Gist::Inspector { mw->setCentralWidget(view); mw->setAttribute(Qt::WA_QuitOnClose, false); mw->setAttribute(Qt::WA_DeleteOnClose, false); - QAction* closeWindow = new QAction("Close window", mw); - closeWindow->setShortcut(QKeySequence("Ctrl+W")); - mw->connect(closeWindow, SIGNAL(triggered()), mw, SLOT(close())); - mw->addAction(closeWindow); + QAction* close_window = new QAction("Close window", mw); + close_window->setShortcut(QKeySequence("Ctrl+W")); + mw->connect(close_window, SIGNAL(triggered()), mw, SLOT(close())); + mw->addAction(close_window); } /// Name of the inspector - virtual std::string - name(void) { + std::string + name(void) override { return "Board"; } /// Finalize inspector - virtual void - finalize(void) { + void + finalize(void) override { delete mw; mw = nullptr; } diff --git a/examples/radiotherapy.cpp b/examples/radiotherapy.cpp index 5f47516319..d0a3f1110c 100644 --- a/examples/radiotherapy.cpp +++ b/examples/radiotherapy.cpp @@ -57,22 +57,22 @@ class RadiotherapyData { const int n; ///< Width of intensity matrix const int* intensity; ///< Intensity matrix - int btMin; ///< Minimal beam time (computed from other parameters) - int btMax; ///< Maximal beam time (computed from other parameters) - int intsSum; ///< Sum of all intensities + int bt_min; ///< Minimal beam time (computed from other parameters) + int bt_max; ///< Maximal beam time (computed from other parameters) + int ints_sum; ///< Sum of all intensities /// Construct instance data RadiotherapyData(int m0, int n0, const int* intensity0) : m(m0), n(n0), intensity(intensity0) { - btMax = 0; - intsSum = 0; + bt_max = 0; + ints_sum = 0; for (int i = 0; i < m * n; i++) { - btMax = std::max(btMax, intensity[i]); - intsSum += intensity[i]; + bt_max = std::max(bt_max, intensity[i]); + ints_sum += intensity[i]; } - btMin = 0; + bt_min = 0; for (int i = 0; i < m; i++) - btMin = std::max(btMin, incr_sum(i)); + bt_min = std::max(bt_min, incr_sum(i)); } }; @@ -103,9 +103,9 @@ class Radiotherapy : public IntMinimizeScript { /// Total beam-on time IntVar beamtime; /// Number of shape matrices - IntVar K; + IntVar k; /// n[b] is the number of shape matrices with associated beam-on time b - IntVarArray N; + IntVarArray n; /// Q[i,j,b] is the number of shape matrices with associated beam-on time b that expose cell (i,j) IntVarArray q; @@ -117,42 +117,42 @@ class Radiotherapy : public IntMinimizeScript { Radiotherapy(const SizeOptions& opt) : IntMinimizeScript(opt), rd(rds[opt.size()]) { // Initialize variables - beamtime = IntVar(*this, rd.btMin, rd.intsSum); - K = IntVar(*this, 0, rd.m * rd.n); - N = IntVarArray(*this, rd.btMax, 0, rd.m * rd.n); - q = IntVarArray(*this, rd.m * rd.n * rd.btMax, 0, rd.m * rd.n); + beamtime = IntVar(*this, rd.bt_min, rd.ints_sum); + k = IntVar(*this, 0, rd.m * rd.n); + n = IntVarArray(*this, rd.bt_max, 0, rd.m * rd.n); + q = IntVarArray(*this, rd.m * rd.n * rd.bt_max, 0, rd.m * rd.n); - IntArgs coeffs(rd.btMax); - for (int i = 0; i < rd.btMax; i++) + IntArgs coeffs(rd.bt_max); + for (int i = 0; i < rd.bt_max; i++) coeffs[i] = i + 1; - linear(*this, coeffs, N, IRT_EQ, beamtime); - linear(*this, N, IRT_EQ, K); + linear(*this, coeffs, n, IRT_EQ, beamtime); + linear(*this, n, IRT_EQ, k); for (int i = 0; i < rd.m; i++) { for (int j = 0; j < rd.n; j++) { - IntVarArgs qs(rd.btMax); - for (int b = 0; b < rd.btMax; b++) - qs[b] = q[i * rd.n * rd.btMax + j * rd.btMax + b]; + IntVarArgs qs(rd.bt_max); + for (int b = 0; b < rd.bt_max; b++) + qs[b] = q[i * rd.n * rd.bt_max + j * rd.bt_max + b]; linear(*this, coeffs, qs, IRT_EQ, rd.intensity[i * rd.n + j], IPL_DOM); } } for (int i = 0; i < rd.m; i++) { - for (int b = 0; b < rd.btMax; b++) { + for (int b = 0; b < rd.bt_max; b++) { IntVarArgs qs(rd.n); for (int j = 0; j < rd.n; j++) - qs[j] = q[i * rd.n * rd.btMax + j * rd.btMax + b]; - incr_sum(N[b], qs, rd.m * rd.n); + qs[j] = q[i * rd.n * rd.bt_max + j * rd.bt_max + b]; + incr_sum(n[b], qs, rd.m * rd.n); } } - _cost = IntVar(*this, 0, (rd.m * rd.n + 1) * (rd.intsSum + 1)); - rel(*this, _cost == beamtime * (rd.m * rd.n + 1) + K); + _cost = IntVar(*this, 0, (rd.m * rd.n + 1) * (rd.ints_sum + 1)); + rel(*this, _cost == beamtime * (rd.m * rd.n + 1) + k); // First branch over beamtime and N IntVarArgs ba({beamtime}); branch(*this, ba, INT_VAR_NONE(), INT_VAL_MIN()); - branch(*this, N, INT_VAR_NONE(), INT_VAL_SPLIT_MIN()); + branch(*this, n, INT_VAR_NONE(), INT_VAL_SPLIT_MIN()); // Then perform a nested search over q NestedSearch::post(*this); @@ -174,28 +174,28 @@ class Radiotherapy : public IntMinimizeScript { /// Constructor for cloning \a s Radiotherapy(Radiotherapy& s) : IntMinimizeScript(s), rd(s.rd) { beamtime.update(*this, s.beamtime); - N.update(*this, s.N); - K.update(*this, s.K); + n.update(*this, s.n); + k.update(*this, s.k); _cost.update(*this, s._cost); q.update(*this, s.q); } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Radiotherapy(*this); } /// Cost to be minimized - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return _cost; } /// Print solution - virtual void - print(std::ostream& os) const { - os << std::endl << "B / K = " << beamtime << " / " << K << ",\nN = " << N << std::endl; + void + print(std::ostream& os) const override { + os << '\n' << "B / K = " << beamtime << " / " << k << ",\nN = " << n << '\n'; } /// Nested search on the q variables @@ -223,8 +223,8 @@ class Radiotherapy : public IntMinimizeScript { /// Initialize choice for brancher \a b Choice(const Brancher& b, bool fail0) : Gecode::Choice(b, 1), fail(fail0) {} /// Archive into \a e - virtual void - archive(Archive& e) const { + void + archive(Archive& e) const override { Gecode::Choice::archive(e); e.put(fail); } @@ -252,24 +252,24 @@ class Radiotherapy : public IntMinimizeScript { NestedSearch(Space& home, NestedSearch& b) : Brancher(home, b), done(b.done), index(b.index) {} public: - virtual bool - status(const Space&) const { + bool + status(const Space&) const override { return !done; } IntVarArgs - getRow(Radiotherapy* row, int i) { - IntVarArgs ri(row->rd.n * row->rd.btMax); + get_row(Radiotherapy* row, int i) { + IntVarArgs ri(row->rd.n * row->rd.bt_max); for (int j = 0; j < row->rd.n; j++) { - for (int b = 0; b < row->rd.btMax; b++) { - ri[j * row->rd.btMax + b] = row->q[i * row->rd.n * row->rd.btMax + j * row->rd.btMax + b]; + for (int b = 0; b < row->rd.bt_max; b++) { + ri[j * row->rd.bt_max + b] = row->q[i * row->rd.n * row->rd.bt_max + j * row->rd.bt_max + b]; } } return ri; } /// Return choice - virtual Gecode::Choice* - choice(Space& home) { + Gecode::Choice* + choice(Space& home) override { done = true; Radiotherapy& rt = static_cast(home); @@ -282,12 +282,12 @@ class Radiotherapy : public IntMinimizeScript { Radiotherapy* row = static_cast(rt.clone()); // Branch over row i - branch(*row, getRow(row, index[i].idx), INT_VAR_NONE(), INT_VAL_SPLIT_MIN()); + branch(*row, get_row(row, index[i].idx), INT_VAR_NONE(), INT_VAL_SPLIT_MIN()); Search::Options o; o.clone = false; - if (Radiotherapy* newSol = dfs(row, o)) { + if (Radiotherapy* new_sol = dfs(row, o)) { // Found a solution for row i, so try to find one for i+1 - delete newSol; + delete new_sol; std::cerr << index[i].idx; } else { // Found no solution for row i, so back to search the N variables @@ -302,26 +302,26 @@ class Radiotherapy : public IntMinimizeScript { return new Choice(*this, fail); } /// Return choice - virtual Choice* - choice(const Space&, Archive& e) { + Choice* + choice(const Space&, Archive& e) override { bool fail; e >> fail; return new Choice(*this, fail); } /// Perform commit for choice \a _c and alternative \a a - virtual ExecStatus - commit(Space&, const Gecode::Choice& _c, unsigned int) { + ExecStatus + commit(Space&, const Gecode::Choice& _c, unsigned int) override { return static_cast(_c).fail ? ES_FAILED : ES_OK; } /// Print explanation - virtual void - print(const Space&, const Gecode::Choice& _c, unsigned int, std::ostream& o) const { + void + print(const Space&, const Gecode::Choice& _c, unsigned int, std::ostream& o) const override { const Choice& c = static_cast(_c); o << (c.fail ? "fail" : "ok"); } /// Copy brancher - virtual Actor* - copy(Space& home) { + Actor* + copy(Space& home) override { return new (home) NestedSearch(home, *this); } /// Post brancher @@ -331,7 +331,7 @@ class Radiotherapy : public IntMinimizeScript { } /// Dispose member function size_t - dispose(Space& home) { + dispose(Space& home) override { home.ignore(*this, AP_DISPOSE); // Periodic scaling of weights if (!--index[index.size() - 1].idx) { @@ -357,7 +357,7 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); if (opt.size() >= rds_n) { - std::cerr << "Error: size must be between 0 and " << rds_n - 1 << std::endl; + std::cerr << "Error: size must be between 0 and " << rds_n - 1 << '\n'; return 1; } diff --git a/examples/sat.cpp b/examples/sat.cpp index 73cacc6ef7..adcd2a3fa7 100644 --- a/examples/sat.cpp +++ b/examples/sat.cpp @@ -127,15 +127,15 @@ class Sat : public Script { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Sat(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "solution:\n" << x << std::endl; + void + print(std::ostream& os) const override { + os << "solution:\n" << x << '\n'; } }; @@ -148,22 +148,22 @@ main(int argc, char* argv[]) { InstanceOptions opt("SAT", instance_spec); opt.parse(argc, argv); if (argc > 2) { - std::cerr << "Error: unexpected arguments after the DIMACS file" << std::endl; + std::cerr << "Error: unexpected arguments after the DIMACS file" << '\n'; return 1; } if (!opt.is_file()) { if (opt.instance() == nullptr) - std::cerr << "Error: no DIMACS file given" << std::endl; + std::cerr << "Error: no DIMACS file given" << '\n'; else - std::cerr << "Error: cannot read file '" << opt.instance() << "'" << std::endl; + std::cerr << "Error: cannot read file '" << opt.instance() << "'" << '\n'; return 1; } try { // Read here to report errors before solving starts (void)opt.data(); } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } diff --git a/examples/schurs-lemma.cpp b/examples/schurs-lemma.cpp index 6a699dadf1..0a6a3cff02 100644 --- a/examples/schurs-lemma.cpp +++ b/examples/schurs-lemma.cpp @@ -55,13 +55,13 @@ class SchurOptions : public Options { n = atoi(argv[2]); } /// Print help message - virtual void - help(void) { + void + help(void) override { Options::help(); - std::cerr << "\t(unsigned int) default: " << c << std::endl - << "\t\tparameter c (number of boxes)" << std::endl - << "\t(unsigned int) default: " << n << std::endl - << "\t\tparameter n (number of balls)" << std::endl; + std::cerr << "\t(unsigned int) default: " << c << '\n' + << "\t\tparameter c (number of boxes)" << '\n' + << "\t(unsigned int) default: " << n << '\n' + << "\t\tparameter n (number of balls)" << '\n'; } }; @@ -100,9 +100,9 @@ class Schur : public Script { branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN()); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\t" << box << std::endl; + void + print(std::ostream& os) const override { + os << "\t" << box << '\n'; } /// Constructor for cloning \a s @@ -110,8 +110,8 @@ class Schur : public Script { box.update(*this, s.box); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Schur(*this); } }; diff --git a/examples/scowl.hpp b/examples/scowl.hpp index 7751e80fbc..209dfee3a7 100644 --- a/examples/scowl.hpp +++ b/examples/scowl.hpp @@ -7888,9 +7888,9 @@ Dictionary::word(int l, int i) const { template std::basic_ostream& Dictionary::print(std::basic_ostream& os) const { - os << "Total number of words: " << n_all_words << std::endl << "Maximal length: " << max_len << std::endl; + os << "Total number of words: " << n_all_words << '\n' << "Maximal length: " << max_len << '\n'; for (int i = 1; i <= max_len; i++) - os << "\t#words of length " << i << ": " << n_words[i] << std::endl; + os << "\t#words of length " << i << ": " << n_words[i] << '\n'; return os; } template diff --git a/examples/sports-league.cpp b/examples/sports-league.cpp index c040cada3a..3f125a2f5b 100644 --- a/examples/sports-league.cpp +++ b/examples/sports-league.cpp @@ -248,14 +248,14 @@ class SportsLeague : public Script { /// (h,a) and (a,h) are the same game, focus on home (that is, h(opt); diff --git a/examples/steel-mill.cpp b/examples/steel-mill.cpp index 5e87cfa588..2dd291947f 100644 --- a/examples/steel-mill.cpp +++ b/examples/steel-mill.cpp @@ -85,7 +85,7 @@ class SteelMillOptions : public Options { _maxcapacity(csplib_maxcapacity), _loss(csplib_loss), _orders(&(csplib_orders[0])), _ncolors(csplib_ncolors), _norders(csplib_norders) {} /// Print help text - virtual void help(void); + void help(void) override; /// Parse options from arguments \a argv (number is \a argc) bool parse(int& argc, char* argv[]); @@ -106,7 +106,7 @@ class SteelMillOptions : public Options { } /// Return maximum of capacities int - maxcapacity(void) const { + max_capacity(void) const { return _maxcapacity; } /// Return loss values @@ -183,7 +183,7 @@ class SteelMill : public IntMinimizeScript { //@{ int* capacities; ///< Capacities int ncapacities; ///< Number of capacities - int maxcapacity; ///< Maximum capacity + int max_capacity; ///< Maximum capacity int* loss; ///< Loss for all sizes int ncolors; ///< Number of colors order_t orders; ///< Orders @@ -195,8 +195,8 @@ class SteelMill : public IntMinimizeScript { */ //@{ IntVarArray slab, ///< Slab assigned to order i - slabload, ///< Load of slab j - slabcost; ///< Cost of slab j + slab_load, ///< Load of slab j + slab_cost; ///< Cost of slab j IntVar total_cost; ///< Total cost //@} @@ -212,17 +212,17 @@ class SteelMill : public IntMinimizeScript { SteelMill(const SteelMillOptions& opt) : // Initialize instance data IntMinimizeScript(opt), capacities(opt.capacities()), ncapacities(opt.ncapacities()), - maxcapacity(opt.maxcapacity()), loss(opt.loss()), ncolors(opt.ncolors()), orders(opt.orders()), + max_capacity(opt.max_capacity()), loss(opt.loss()), ncolors(opt.ncolors()), orders(opt.orders()), norders(opt.size()), nslabs(opt.size()), // Initialize problem variables - slab(*this, norders, 0, nslabs - 1), slabload(*this, nslabs, 0, 45), - slabcost(*this, nslabs, 0, Int::Limits::max), total_cost(*this, 0, Int::Limits::max) { + slab(*this, norders, 0, nslabs - 1), slab_load(*this, nslabs, 0, 45), + slab_cost(*this, nslabs, 0, Int::Limits::max), total_cost(*this, 0, Int::Limits::max) { // Boolean variables for slab[o]==s - BoolVarArgs boolslab(norders * nslabs); + BoolVarArgs order_in_slab(norders * nslabs); for (unsigned int i = 0; i < norders; ++i) { BoolVarArgs tmp(nslabs); for (int j = nslabs; j--;) { - boolslab[j + i * nslabs] = tmp[j] = BoolVar(*this, 0, 1); + order_in_slab[j + i * nslabs] = tmp[j] = BoolVar(*this, 0, 1); } channel(*this, tmp, slab[i]); } @@ -233,52 +233,52 @@ class SteelMill : public IntMinimizeScript { BoolVarArgs x(norders); for (int i = norders; i--;) { c[i] = orders[i][order_weight]; - x[i] = boolslab[s + i * nslabs]; + x[i] = order_in_slab[s + i * nslabs]; } - linear(*this, c, x, IRT_EQ, slabload[s]); + linear(*this, c, x, IRT_EQ, slab_load[s]); } // Redundant packing constraint int totalweight = 0; for (unsigned int i = norders; i--;) totalweight += orders[i][order_weight]; - linear(*this, slabload, IRT_EQ, totalweight); + linear(*this, slab_load, IRT_EQ, totalweight); // Color constraints - IntArgs nofcolor(ncolors); + IntArgs color_order_count(ncolors); for (int c = ncolors; c--;) { - nofcolor[c] = 0; + color_order_count[c] = 0; for (int o = norders; o--;) { if (orders[o][order_color] == c) - nofcolor[c] += 1; + color_order_count[c] += 1; } } BoolVar f(*this, 0, 0); for (unsigned int s = 0; s < nslabs; ++s) { - BoolVarArgs hascolor(ncolors); + BoolVarArgs has_color(ncolors); for (int c = ncolors; c--;) { - if (nofcolor[c]) { - BoolVarArgs hasc(nofcolor[c]); + if (color_order_count[c]) { + BoolVarArgs hasc(color_order_count[c]); int pos = 0; for (int o = norders; o--;) { if (orders[o][order_color] == c) - hasc[pos++] = boolslab[s + o * nslabs]; + hasc[pos++] = order_in_slab[s + o * nslabs]; } - assert(pos == nofcolor[c]); - hascolor[c] = BoolVar(*this, 0, 1); - rel(*this, BOT_OR, hasc, hascolor[c]); + assert(pos == color_order_count[c]); + has_color[c] = BoolVar(*this, 0, 1); + rel(*this, BOT_OR, hasc, has_color[c]); } else { - hascolor[c] = f; + has_color[c] = f; } } - linear(*this, hascolor, IRT_LQ, 2); + linear(*this, has_color, IRT_LQ, 2); } - // Compute slabcost - IntArgs l(maxcapacity, loss); + // Compute slab_cost + IntArgs l(max_capacity, loss); for (int s = nslabs; s--;) { - element(*this, l, slabload[s], slabcost[s]); + element(*this, l, slab_load[s], slab_cost[s]); } - linear(*this, slabcost, IRT_EQ, total_cost); + linear(*this, slab_cost, IRT_EQ, total_cost); // Add branching if (opt.symmetry() == SYMMETRY_BRANCHING) { @@ -289,7 +289,7 @@ class SteelMill : public IntMinimizeScript { } else { // opt.symmetry() == SYMMETRY_LDSB // There is one symmetry: the values (slabs) are interchangeable. Symmetries syms; - syms << ValueSymmetry(IntArgs::create(nslabs, 0)); + syms << value_symmetry(IntArgs::create(nslabs, 0)); // For variable order we mimic the custom brancher. We use // min-size domain, breaking ties by maximum weight (preferring @@ -309,47 +309,47 @@ class SteelMill : public IntMinimizeScript { } /// Print solution - virtual void - print(std::ostream& os) const { - os << "What slab=" << slab << std::endl; - os << "Slab load=" << slabload << std::endl; - os << "Slab cost=" << slabcost << std::endl; - os << "Total cost=" << total_cost << std::endl; + void + print(std::ostream& os) const override { + os << "What slab=" << slab << '\n'; + os << "Slab load=" << slab_load << '\n'; + os << "Slab cost=" << slab_cost << '\n'; + os << "Total cost=" << total_cost << '\n'; int nslabsused = 0; int nslabscost = 0; bool unassigned = false; for (int i = nslabs; i--;) { - if (!slabload[i].assigned() || !slabcost[i].assigned()) { + if (!slab_load[i].assigned() || !slab_cost[i].assigned()) { unassigned = true; break; } - if (slabload[i].min() > 0) + if (slab_load[i].min() > 0) ++nslabsused; - if (slabcost[i].min() > 0) + if (slab_cost[i].min() > 0) ++nslabscost; } if (!unassigned) - os << "Number of slabs used=" << nslabsused << ", slabs with cost=" << nslabscost << std::endl; - os << std::endl; + os << "Number of slabs used=" << nslabsused << ", slabs with cost=" << nslabscost << '\n'; + os << '\n'; } /// Constructor for cloning \a s SteelMill(SteelMill& s) - : IntMinimizeScript(s), capacities(s.capacities), ncapacities(s.ncapacities), maxcapacity(s.maxcapacity), + : IntMinimizeScript(s), capacities(s.capacities), ncapacities(s.ncapacities), max_capacity(s.max_capacity), loss(s.loss), ncolors(s.ncolors), orders(s.orders), norders(s.norders), nslabs(s.nslabs) { slab.update(*this, s.slab); - slabload.update(*this, s.slabload); - slabcost.update(*this, s.slabcost); + slab_load.update(*this, s.slab_load); + slab_cost.update(*this, s.slab_cost); total_cost.update(*this, s.total_cost); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new SteelMill(*this); } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return total_cost; } @@ -378,8 +378,8 @@ class SteelMill : public IntMinimizeScript { Choice(const Brancher& b, unsigned int a, int pos0, int val0) : Gecode::Choice(b, a), pos(pos0), val(val0) {} /// Archive into \a e - virtual void - archive(Archive& e) const { + void + archive(Archive& e) const override { Gecode::Choice::archive(e); e << alternatives() << pos << val; } @@ -392,8 +392,8 @@ class SteelMill : public IntMinimizeScript { public: /// Check status of brancher, return true if alternatives left. - virtual bool - status(const Space& home) const { + bool + status(const Space& home) const override { const SteelMill& sm = static_cast(home); for (unsigned int i = start; i < sm.norders; ++i) if (!sm.slab[i].assigned()) { @@ -404,8 +404,8 @@ class SteelMill : public IntMinimizeScript { return false; } /// Return choice - virtual Gecode::Choice* - choice(Space& home) { + Gecode::Choice* + choice(Space& home) override { SteelMill& sm = static_cast(home); assert(!sm.slab[start].assigned()); // Find order with a) minimum size, b) largest weight @@ -427,21 +427,21 @@ class SteelMill : public IntMinimizeScript { unsigned int val = sm.slab[pos].min(); // Find first still empty slab (all such slabs are symmetric) unsigned int firstzero = 0; - while (firstzero < sm.nslabs && sm.slabload[firstzero].min() > 0) + while (firstzero < sm.nslabs && sm.slab_load[firstzero].min() > 0) ++firstzero; assert(pos < sm.nslabs && val < sm.norders); return new Choice(*this, (val < firstzero) ? 2 : 1, pos, val); } - virtual Choice* - choice(const Space&, Archive& e) { + Choice* + choice(const Space&, Archive& e) override { unsigned int alt; int pos, val; e >> alt >> pos >> val; return new Choice(*this, alt, pos, val); } /// Perform commit for choice \a _c and alternative \a a - virtual ExecStatus - commit(Space& home, const Gecode::Choice& _c, unsigned int a) { + ExecStatus + commit(Space& home, const Gecode::Choice& _c, unsigned int a) override { SteelMill& sm = static_cast(home); const Choice& c = static_cast(_c); if (a) @@ -450,14 +450,14 @@ class SteelMill : public IntMinimizeScript { return me_failed(Int::IntView(sm.slab[c.pos]).eq(home, c.val)) ? ES_FAILED : ES_OK; } /// Print explanation - virtual void - print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const { + void + print(const Space&, const Gecode::Choice& _c, unsigned int a, std::ostream& o) const override { const Choice& c = static_cast(_c); o << "slab[" << c.pos << "] " << ((a == 0) ? "=" : "!=") << " " << c.val; } /// Copy brancher - virtual Actor* - copy(Space& home) { + Actor* + copy(Space& home) override { return new (home) SteelMillBranch(home, *this); } /// Post brancher @@ -466,8 +466,8 @@ class SteelMill : public IntMinimizeScript { (void)new (home) SteelMillBranch(home); } /// Delete brancher and return its size - virtual size_t - dispose(Space&) { + size_t + dispose(Space&) override { return sizeof(*this); } }; @@ -493,12 +493,12 @@ main(int argc, char* argv[]) { void SteelMillOptions::help(void) { Options::help(); - std::cerr << "\t(string), optional" << std::endl - << "\t\tBenchmark to load." << std::endl - << "\t\tIf none is given, the standard CSPLib instance is used." << std::endl; - std::cerr << "\t(unsigned int), optional" << std::endl - << "\t\tNumber of orders to use, in the interval [0..norders]." << std::endl - << "\t\tIf none is given, all orders are used." << std::endl; + std::cerr << "\t(string), optional" << '\n' + << "\t\tBenchmark to load." << '\n' + << "\t\tIf none is given, the standard CSPLib instance is used." << '\n'; + std::cerr << "\t(unsigned int), optional" << '\n' + << "\t\tNumber of orders to use, in the interval [0..norders]." << '\n' + << "\t\tIf none is given, all orders are used." << '\n'; } bool @@ -512,7 +512,7 @@ SteelMillOptions::parse(int& argc, char* argv[]) { if (i < argc - 1) std::cerr << ","; } - std::cerr << "})." << std::endl; + std::cerr << "})." << '\n'; return false; } // Parse options @@ -525,8 +525,7 @@ SteelMillOptions::parse(int& argc, char* argv[]) { } else { std::ifstream instance(argv[argc - 1]); if (instance.fail()) { - std::cerr << "Argument \"" << argv[argc - 1] << "\" is neither an integer nor a readable file" - << std::endl; + std::cerr << "Argument \"" << argv[argc - 1] << "\" is neither an integer nor a readable file" << '\n'; return false; } // Read file instance @@ -563,7 +562,7 @@ SteelMillOptions::parse(int& argc, char* argv[]) { } // Check size reasonability if (_size == 0 || _size > _norders) { - std::cerr << "Size must be between 1 and " << _norders << std::endl; + std::cerr << "Size must be between 1 and " << _norders << '\n'; return false; } return true; diff --git a/examples/steiner.cpp b/examples/steiner.cpp index 81a536ffea..ea41ffc782 100644 --- a/examples/steiner.cpp +++ b/examples/steiner.cpp @@ -55,23 +55,23 @@ class Steiner : public Script { /// Order of the Steiner problem int n; /// Number of Steiner triples - int noOfTriples; + int no_of_triples; /// The steiner triples SetVarArray triples; /// Actual model Steiner(const SizeOptions& opt) - : Script(opt), n(opt.size()), noOfTriples((n * (n - 1)) / 6), - triples(*this, noOfTriples, IntSet::empty, 1, n, 3U, 3U) { + : Script(opt), n(opt.size()), no_of_triples((n * (n - 1)) / 6), + triples(*this, no_of_triples, IntSet::empty, 1, n, 3U, 3U) { - for (int i = 0; i < noOfTriples; i++) { - for (int j = i + 1; j < noOfTriples; j++) { + for (int i = 0; i < no_of_triples; i++) { + for (int j = i + 1; j < no_of_triples; j++) { SetVar x = triples[i]; SetVar y = triples[j]; - SetVar atmostOne(*this, IntSet::empty, 1, n, 0U, 1U); - rel(*this, (x & y) == atmostOne); + SetVar atmost_one(*this, IntSet::empty, 1, n, 0U, 1U); + rel(*this, (x & y) == atmost_one); IntVar x1(*this, 1, n); IntVar x2(*this, 1, n); @@ -96,8 +96,8 @@ class Steiner : public Script { * Using matching constraints */ - channelSorted(*this, {x1, x2, x3}, x); - channelSorted(*this, {y1, y2, y3}, y); + channel_sorted(*this, {x1, x2, x3}, x); + channel_sorted(*this, {y1, y2, y3}, y); } else if (opt.model() == MODEL_SEQ) { SetVar sx1 = expr(*this, singleton(x1)); SetVar sx2 = expr(*this, singleton(x2)); @@ -119,26 +119,26 @@ class Steiner : public Script { rel(*this, y1 < y3); linear(*this, {(n + 1) * (n + 1), n + 1, 1, -(n + 1) * (n + 1), -(n + 1), -1}, {x1, x2, x3, y1, y2, y3}, - IRT_LE, 0); + IRT_LT, 0); } } branch(*this, triples, SET_VAR_NONE(), SET_VAL_MIN_INC()); } /// Print solution - virtual void - print(std::ostream& os) const { - for (int i = 0; i < noOfTriples; i++) { - os << "\t[" << i << "] = " << triples[i] << std::endl; + void + print(std::ostream& os) const override { + for (int i = 0; i < no_of_triples; i++) { + os << "\t[" << i << "] = " << triples[i] << '\n'; } } /// Constructor for copying \a s - Steiner(Steiner& s) : Script(s), n(s.n), noOfTriples(s.noOfTriples) { + Steiner(Steiner& s) : Script(s), n(s.n), no_of_triples(s.no_of_triples) { triples.update(*this, s.triples); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Steiner(*this); } }; diff --git a/examples/sudoku-advanced.cpp b/examples/sudoku-advanced.cpp index e79fb45796..178e94c0cd 100644 --- a/examples/sudoku-advanced.cpp +++ b/examples/sudoku-advanced.cpp @@ -177,14 +177,14 @@ class SudokuInt : virtual public Sudoku { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new SudokuInt(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << " "; for (int i = 0; i < nn * nn; i++) { if (x[i].assigned()) { @@ -193,16 +193,16 @@ class SudokuInt : virtual public Sudoku { } else os << ". "; if ((i + 1) % nn == 0) - os << std::endl << " "; + os << '\n' << " "; } - os << std::endl; + os << '\n'; } #ifdef GECODE_HAS_SET_VARS private: /// Post the constraint that \a a and \a b take the same values void - same(Space& home, int nn, IntVarArgs a, IntVarArgs b) { + same(Space& home, int nn, const IntVarArgs& a, const IntVarArgs& b) { SetVar u(home, IntSet::empty, 1, nn); rel(home, SOT_DUNION, a, u); rel(home, SOT_DUNION, b, u); @@ -341,14 +341,14 @@ class SudokuSet : virtual public Sudoku { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new SudokuSet(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << '\t'; for (int i = 0; i < nn * nn; i++) { for (int j = 0; j < nn; j++) { @@ -359,9 +359,9 @@ class SudokuSet : virtual public Sudoku { } } if ((i + 1) % nn == 0) - os << std::endl << '\t'; + os << '\n' << '\t'; } - os << std::endl; + os << '\n'; } }; @@ -377,14 +377,14 @@ class SudokuMixed : public SudokuInt, public SudokuSet { SudokuMixed(const InstanceOptions& opt) : Sudoku(opt), SudokuInt(opt), SudokuSet(opt) { IntSet is0(0, 0); - SetVar dummySet0(*this, is0, is0); - IntVar dummyInt0(*this, 0, 0); + SetVar dummy_set0(*this, is0, is0); + IntVar dummy_int0(*this, 0, 0); SetVarArgs ys(nn + 1); - ys[0] = dummySet0; + ys[0] = dummy_set0; for (int i = 0; i < nn; i++) ys[i + 1] = y[i]; IntVarArgs xs(nn * nn + 1); - xs[0] = dummyInt0; + xs[0] = dummy_int0; for (int i = 0; i < nn * nn; i++) xs[i + 1] = x[i]; @@ -400,14 +400,14 @@ class SudokuMixed : public SudokuInt, public SudokuSet { SudokuMixed(SudokuMixed& s) : Sudoku(s), SudokuInt(s), SudokuSet(s) {} /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new SudokuMixed(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { SudokuInt::print(os); } }; @@ -441,12 +441,11 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); try { if (!SudokuInstance(opt).valid()) { - std::cerr << "Error: instance must be a number between 0 and " << n_examples - 1 << " or a file" - << std::endl; + std::cerr << "Error: instance must be a number between 0 and " << n_examples - 1 << " or a file" << '\n'; return 1; } } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } #ifdef GECODE_HAS_SET_VARS diff --git a/examples/sudoku-instances.hh b/examples/sudoku-instances.hh index d09fdc6963..958ea683b9 100644 --- a/examples/sudoku-instances.hh +++ b/examples/sudoku-instances.hh @@ -38,7 +38,7 @@ namespace { extern const char* examples[]; extern const unsigned int n_examples; int example_size(const char* s); - int sudokuField(const char* s, int n, int i, int j); + int sudoku_field(const char* s, int n, int i, int j); /** \name %Sudoku specifications * @@ -1770,7 +1770,7 @@ namespace { /// Return value at position (\a i,\a j) in the example \a s of size \a n int - sudokuField(const char* s, int n, int i, int j) { + sudoku_field(const char* s, int n, int i, int j) { assert(example_size(s) == std::sqrt(static_cast(n))); assert(i >= 0 && i < n); assert(j >= 0 && j < n); @@ -1842,7 +1842,7 @@ instances { givens = IntArgs(nn * nn); for (int r = 0; r < nn; r++) for (int c = 0; c < nn; c++) - givens[r * nn + c] = sudokuField(examples[i], nn, c, r); + givens[r * nn + c] = sudoku_field(examples[i], nn, c, r); } else if (opt.is_file()) { // The spec has checked the data Instance::Data d = opt.data(); diff --git a/examples/sudoku.cpp b/examples/sudoku.cpp index 349a794b03..457d003020 100644 --- a/examples/sudoku.cpp +++ b/examples/sudoku.cpp @@ -101,14 +101,14 @@ class Sudoku : public Script { } /// Perform copying during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new Sudoku(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << " "; for (int i = 0; i < nn * nn; i++) { if (x[i].assigned()) { @@ -117,9 +117,9 @@ class Sudoku : public Script { } else os << ". "; if ((i + 1) % nn == 0) - os << std::endl << " "; + os << '\n' << " "; } - os << std::endl; + os << '\n'; } }; @@ -135,12 +135,11 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); try { if (!SudokuInstance(opt).valid()) { - std::cerr << "Error: instance must be a number between 0 and " << n_examples - 1 << " or a file" - << std::endl; + std::cerr << "Error: instance must be a number between 0 and " << n_examples - 1 << " or a file" << '\n'; return 1; } } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } Script::run(opt); diff --git a/examples/tsp.cpp b/examples/tsp.cpp index 69fafcf899..559001cc5b 100644 --- a/examples/tsp.cpp +++ b/examples/tsp.cpp @@ -47,22 +47,22 @@ using namespace Gecode; namespace { /// This instance is taken from SICStus Prolog - const int PA_n = 7; - const int PA_d[PA_n * PA_n] = {0, 205, 677, 581, 461, 878, 345, 205, 0, 882, 427, 390, 1105, + const int pa_n = 7; + const int pa_d[pa_n * pa_n] = {0, 205, 677, 581, 461, 878, 345, 205, 0, 882, 427, 390, 1105, 540, 677, 882, 0, 619, 316, 201, 470, 581, 427, 619, 0, 412, 592, 570, 461, 390, 316, 412, 0, 517, 190, 878, 1105, 201, 592, 517, 0, 691, 345, 540, 470, 570, 190, 691, 0}; /// This instance is taken from SICStus Prolog - const int PB_n = 10; - const int PB_d[PB_n * PB_n] = {2, 4, 4, 1, 9, 2, 4, 4, 1, 9, 2, 9, 5, 5, 5, 2, 9, 5, 5, 5, 1, 5, 2, 3, 3, + const int pb_n = 10; + const int pb_d[pb_n * pb_n] = {2, 4, 4, 1, 9, 2, 4, 4, 1, 9, 2, 9, 5, 5, 5, 2, 9, 5, 5, 5, 1, 5, 2, 3, 3, 1, 5, 2, 3, 3, 2, 6, 8, 9, 5, 2, 6, 8, 9, 5, 3, 7, 1, 6, 4, 3, 7, 1, 6, 4, 1, 2, 4, 1, 7, 1, 2, 4, 1, 7, 3, 5, 2, 7, 6, 3, 5, 2, 7, 6, 2, 7, 9, 5, 5, 2, 7, 9, 5, 5, 3, 9, 7, 3, 4, 3, 9, 7, 3, 4, 4, 1, 5, 9, 2, 4, 1, 5, 9, 2}; /// This instance is br17.atsp from TSPLIB - const int PC_n = 17; - const int PC_d[PC_n * PC_n] = { + const int pc_n = 17; + const int pc_d[pc_n * pc_n] = { 0, 3, 5, 48, 48, 8, 8, 5, 5, 3, 3, 0, 3, 5, 8, 8, 5, 3, 0, 3, 48, 48, 8, 8, 5, 5, 0, 0, 3, 0, 3, 8, 8, 5, 5, 3, 0, 72, 72, 48, 48, 24, 24, 3, 3, 5, 3, 0, 48, 48, 24, 48, 48, 74, 0, 0, 6, 6, 12, 12, 48, 48, 48, 48, 74, 6, 6, 12, 48, 48, 74, 0, 0, 6, 6, 12, 12, 48, 48, 48, 48, @@ -76,8 +76,8 @@ namespace { 0, 8, 5, 5, 26, 12, 12, 8, 8, 0, 0, 5, 5, 5, 5, 26, 8, 8, 0}; /// This instance is ftv33.atsp from TSPLIB - const int PD_n = 34; - const int PD_d[PD_n * PD_n] = { + const int pd_n = 34; + const int pd_d[pd_n * pd_n] = { 0, 26, 82, 65, 100, 147, 134, 69, 117, 42, 89, 125, 38, 13, 38, 31, 22, 103, 143, 94, 104, 123, 98, 58, 38, 30, 67, 120, 149, 100, 93, 162, 62, 66, 66, 0, 56, 39, 109, 156, 140, 135, 183, 108, 155, 190, 104, 79, 104, 97, 88, 130, 176, 121, 131, 150, 125, 85, 65, 57, 94, 147, 160, 80, 67, 189, @@ -184,12 +184,12 @@ namespace { return m * _n; } - Problem PA(PA_n, PA_d); - Problem PB(PB_n, PB_d); - Problem PC(PC_n, PC_d); - Problem PD(PD_n, PD_d); + Problem pa(pa_n, pa_d); + Problem pb(pb_n, pb_d); + Problem pc(pc_n, pc_d); + Problem pd(pd_n, pd_d); - Problem ps[] = {PA, PB, PC, PD}; + Problem ps[] = {pa, pb, pc, pd}; const unsigned int ps_n = sizeof(ps) / sizeof(Problem); /** @@ -371,7 +371,7 @@ class TSP : public IntMinimizeScript { { IntVar p0(*this, 0, n - 1); element(*this, succ, p0, 0); - rel(*this, p0, IRT_LE, succ[0]); + rel(*this, p0, IRT_LT, succ[0]); } // First enumerate cost values, prefer those that maximize cost reduction @@ -381,8 +381,8 @@ class TSP : public IntMinimizeScript { branch(*this, succ, INT_VAR_MIN_MIN(), INT_VAL_MIN()); } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return total; } /// Constructor for cloning \a s @@ -391,13 +391,13 @@ class TSP : public IntMinimizeScript { total.update(*this, s.total); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new TSP(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { bool assigned = true; for (int i = 0; i < succ.size(); i++) { if (!succ[i].assigned()) { @@ -412,14 +412,14 @@ class TSP : public IntMinimizeScript { os << i << " -> "; i = succ[i].val(); } while (i != 0); - os << 0 << std::endl; - os << "\tCost: " << total << std::endl; + os << 0 << '\n'; + os << "\tCost: " << total << '\n'; } else { - os << "\tTour: " << std::endl; + os << "\tTour: " << '\n'; for (int i = 0; i < succ.size(); i++) { - os << "\t" << i << " -> " << succ[i] << std::endl; + os << "\t" << i << " -> " << succ[i] << '\n'; } - os << "\tCost: " << total << std::endl; + os << "\tCost: " << total << '\n'; } } }; @@ -437,12 +437,11 @@ main(int argc, char* argv[]) { try { if (!problem(opt).valid()) { - std::cerr << "Error: instance must be a number between 0 and " << ps_n - 1 << " or a TSPLIB file" - << std::endl; + std::cerr << "Error: instance must be a number between 0 and " << ps_n - 1 << " or a TSPLIB file" << '\n'; return 1; } } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } diff --git a/examples/tsptw.cpp b/examples/tsptw.cpp index 92dfe6a661..8a0436332e 100644 --- a/examples/tsptw.cpp +++ b/examples/tsptw.cpp @@ -54,19 +54,19 @@ namespace { }; /// Instance rbg010a (Ascheuer) - const int PA_n = 11; - const int PA_d[PA_n * PA_n] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 0, 85, 85, 85, 96, 85, 85, 97, 85, + const int pa_n = 11; + const int pa_d[pa_n * pa_n] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 0, 85, 85, 85, 96, 85, 85, 97, 85, 77, 50, 65, 0, 77, 77, 62, 77, 77, 62, 77, 74, 64, 74, 88, 0, 88, 80, 88, 88, 82, 88, 87, 44, 54, 68, 68, 0, 60, 68, 68, 62, 68, 67, 51, 75, 51, 51, 51, 0, 51, 51, 80, 51, 65, 53, 64, 78, 78, 78, 68, 0, 78, 69, 78, 76, 51, 67, 69, 69, 69, 75, 69, 0, 75, 69, 63, 43, 61, 71, 71, 71, 43, 71, 71, 0, 71, 68, 53, 64, 78, 78, 78, 68, 78, 78, 69, 0, 80, 42, 66, 52, 52, 52, 70, 52, 52, 70, 52, 0}; - const int PA_w[2 * PA_n] = {0, 9396, 0, 865, 399, 1299, 550, 1450, 685, 1585, 819, + const int pa_w[2 * pa_n] = {0, 9396, 0, 865, 399, 1299, 550, 1450, 685, 1585, 819, 1719, 1208, 2108, 1412, 2312, 1701, 2330, 2413, 3313, 3798, 4698}; /// Instance n20w20.001 (Dumas et al.) - const int PB_n = 21; - const int PB_d[PB_n * PB_n] = { + const int pb_n = 21; + const int pb_d[pb_n * pb_n] = { 0, 19, 17, 34, 7, 20, 10, 17, 28, 15, 23, 29, 23, 29, 21, 20, 9, 16, 21, 13, 12, 19, 0, 10, 41, 26, 3, 27, 25, 15, 17, 17, 14, 18, 48, 17, 6, 21, 14, 17, 13, 31, 17, 10, 0, 47, 23, 13, 26, 15, 25, 22, 26, 24, 27, 44, 7, 5, 23, 21, 25, 18, 29, 34, 41, 47, 0, 36, 39, 25, 51, 36, 24, 27, 38, 25, 44, 54, 45, 25, 28, 26, 28, 27, @@ -83,12 +83,12 @@ namespace { 31, 13, 4, 7, 14, 7, 42, 28, 19, 11, 0, 5, 3, 21, 21, 17, 25, 26, 28, 14, 21, 36, 11, 7, 2, 13, 2, 46, 32, 22, 15, 5, 0, 8, 25, 13, 13, 18, 28, 20, 11, 15, 28, 15, 4, 10, 17, 10, 40, 25, 17, 9, 3, 8, 0, 19, 12, 31, 29, 27, 10, 30, 4, 27, 35, 18, 27, 36, 26, 21, 33, 32, 10, 21, 25, 19, 0}; - const int PB_w[2 * PB_n] = {0, 408, 62, 68, 181, 205, 306, 324, 214, 217, 51, 61, 102, 129, + const int pb_w[2 * pb_n] = {0, 408, 62, 68, 181, 205, 306, 324, 214, 217, 51, 61, 102, 129, 175, 186, 250, 263, 3, 23, 21, 49, 79, 90, 78, 96, 140, 154, 354, 386, 42, 63, 2, 13, 24, 42, 20, 33, 9, 21, 275, 300}; /// The instances - const Builtin instances[] = {{PA_n, PA_d, PA_w}, {PB_n, PB_d, PB_w}}; + const Builtin instances[] = {{pa_n, pa_d, pa_w}, {pb_n, pb_d, pb_w}}; /// Number of instances const unsigned int n_instances = sizeof(instances) / sizeof(Builtin); @@ -251,8 +251,8 @@ class TSPTW : public IntMinimizeScript { branch(*this, x, INT_VAR_NONE(), INT_VALUES_MIN()); } /// Return cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return total; } /// Return the number of positions assigned from the start @@ -321,17 +321,17 @@ class TSPTW : public IntMinimizeScript { total.update(*this, s.total); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new TSPTW(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { os << "\tTour: 0"; for (int i = 0; i < x.size(); i++) os << " -> " << x[i]; - os << " -> 0" << std::endl << "\tTravel time: " << total << std::endl; + os << " -> 0" << '\n' << "\tTravel time: " << total << '\n'; } }; @@ -353,12 +353,11 @@ main(int argc, char* argv[]) { try { Problem p(opt); if (!p.valid()) { - std::cerr << "Error: instance must be a number between 0 and " << n_instances - 1 << " or a file" - << std::endl; + std::cerr << "Error: instance must be a number between 0 and " << n_instances - 1 << " or a file" << '\n'; return 1; } } catch (const Instance::Error& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } switch (opt.search()) { diff --git a/examples/warehouses.cpp b/examples/warehouses.cpp index d52f25138e..009d19fe18 100644 --- a/examples/warehouses.cpp +++ b/examples/warehouses.cpp @@ -144,8 +144,8 @@ class SumCostWarehouses : public Warehouses { c_total = expr(*this, c_fixed * sum(open) + sum(c_store)); } /// Return solution cost - virtual IntVar - cost(void) const { + IntVar + cost(void) const override { return c_total; } /// Constructor for cloning \a s @@ -153,18 +153,18 @@ class SumCostWarehouses : public Warehouses { c_total.update(*this, s.c_total); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new SumCostWarehouses(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tSupplier: " << supplier << std::endl - << "\tOpen warehouses: " << open << std::endl - << "\tStore cost: " << c_store << std::endl - << "\tTotal cost: " << c_total << std::endl - << std::endl; + void + print(std::ostream& os) const override { + os << "\tSupplier: " << supplier << '\n' + << "\tOpen warehouses: " << open << '\n' + << "\tStore cost: " << c_store << '\n' + << "\tTotal cost: " << c_total << '\n' + << '\n'; } }; @@ -184,8 +184,8 @@ class LexCostWarehouses : public Warehouses { c_stores = expr(*this, sum(c_store)); } /// Return solution cost - virtual IntVarArgs - cost(void) const { + IntVarArgs + cost(void) const override { return {c_open, c_stores}; } /// Constructor for cloning \a s @@ -194,18 +194,18 @@ class LexCostWarehouses : public Warehouses { c_stores.update(*this, s.c_stores); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new LexCostWarehouses(*this); } /// Print solution - virtual void - print(std::ostream& os) const { - os << "\tSupplier: " << supplier << std::endl - << "\tOpen warehouses: " << open << std::endl - << "\tOpen cost: " << c_open << std::endl - << "\tStores cost: " << c_stores << std::endl - << std::endl; + void + print(std::ostream& os) const override { + os << "\tSupplier: " << supplier << '\n' + << "\tOpen warehouses: " << open << '\n' + << "\tOpen cost: " << c_open << '\n' + << "\tStores cost: " << c_stores << '\n' + << '\n'; } }; diff --git a/examples/word-square.cpp b/examples/word-square.cpp index 14bd48bb18..92053ac6c0 100644 --- a/examples/word-square.cpp +++ b/examples/word-square.cpp @@ -97,7 +97,7 @@ class WordSquare : public Script { } // Symmetry breaking: the last word must be later in the wordlist - rel(*this, words[0], IRT_LE, words[w_l - 1]); + rel(*this, words[0], IRT_LT, words[w_l - 1]); switch (opt.branching()) { case BRANCH_WORDS: @@ -115,13 +115,13 @@ class WordSquare : public Script { letters.update(*this, s.letters); } /// Copy during cloning - virtual Space* - copy(void) { + Space* + copy(void) override { return new WordSquare(*this); } /// Print solution - virtual void - print(std::ostream& os) const { + void + print(std::ostream& os) const override { Matrix ml(letters, w_l, w_l); for (int i = 0; i < w_l; i++) { os << "\t\t"; @@ -131,9 +131,9 @@ class WordSquare : public Script { } else { os << "."; } - os << std::endl; + os << '\n'; } - os << std::endl; + os << '\n'; } }; @@ -150,7 +150,7 @@ main(int argc, char* argv[]) { opt.parse(argc, argv); dict.init(opt.file()); if (opt.size() > static_cast(dict.len())) { - std::cerr << "Error: size must be between 0 and " << dict.len() << std::endl; + std::cerr << "Error: size must be between 0 and " << dict.len() << '\n'; return 1; } Script::run(opt); diff --git a/gecode/driver.hh b/gecode/driver.hh index 1e132ac556..b631ba7a2a 100644 --- a/gecode/driver.hh +++ b/gecode/driver.hh @@ -134,7 +134,7 @@ namespace Gecode { /// Create heap-allocated copy of string \a s static char* strdup(const char* s); /// Create heap-allocated copy of string \a s with hyphen added - static char* stredup(const char* s); + static char* duplicate_option_flag(const char* s); /// Delete heap-allocated copy of string \a s static void strdel(const char* s); }; @@ -150,8 +150,8 @@ namespace Gecode { void value(uint64_t v); /// Construct an independent generator at the configured initial state. Rnd rnd(void) const; - virtual int parse(int argc, char* argv[]); - virtual void help(void); + int parse(int argc, char* argv[]) override; + void help(void) override; }; /** @@ -169,11 +169,11 @@ namespace Gecode { /// Return current option value const char* value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; /// Destructor - virtual ~StringValueOption(void); + ~StringValueOption(void) override; }; /** @@ -186,7 +186,7 @@ namespace Gecode { /// Initialize for option \a o and explanation \a e StringListOption(const char* o, const char* e); /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; }; /** @@ -216,11 +216,11 @@ namespace Gecode { /// Add option value for value \a v, string \a o, and help text \a h void add(int v, const char* o, const char* h = nullptr); /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; /// Destructor - virtual ~StringOption(void); + ~StringOption(void) override; }; /** @@ -238,9 +238,9 @@ namespace Gecode { /// Return current option value int value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -258,9 +258,9 @@ namespace Gecode { /// Return current option value unsigned int value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -278,9 +278,9 @@ namespace Gecode { /// Return current option value unsigned long long int value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -298,9 +298,9 @@ namespace Gecode { /// Return current option value double value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -318,9 +318,9 @@ namespace Gecode { /// Return current option value bool value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -338,9 +338,9 @@ namespace Gecode { /// Return current option value IntPropLevel value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -358,9 +358,9 @@ namespace Gecode { /// Return current option value int value(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; /** @@ -383,9 +383,9 @@ namespace Gecode { /// Return current execution ID int execution_id(void) const; /// Parse option at first position and return number of parsed arguments - virtual int parse(int argc, char* argv[]); + int parse(int argc, char* argv[]) override; /// Print help text - virtual void help(void); + void help(void) override; }; } // namespace Driver @@ -780,7 +780,7 @@ namespace Gecode { /// Initialize options for script with name \a s SizeOptions(const char* s); /// Print help text - virtual void help(void); + void help(void) override; /// Parse options from arguments \a argv (number is \a argc) void parse(int& argc, char* argv[]); /** @@ -857,7 +857,7 @@ namespace Gecode { */ InstanceOptions(const char* s, const char* spec); /// Print help text - virtual void help(void); + void help(void) override; /// Parse options from arguments \a argv (number is \a argc) void parse(int& argc, char* argv[]); /** @@ -913,7 +913,7 @@ namespace Gecode { */ Instance::Data data(void) const; /// Destructor - ~InstanceOptions(void); + ~InstanceOptions(void) override; }; } // namespace Gecode @@ -958,7 +958,7 @@ namespace Gecode { namespace Driver { private: template class Engine, class Options, template class> class Meta> - static void runMeta(const Options& opt, Script* s); + static void run_meta(const Options& opt, Script* s); }; #ifdef GECODE_HAS_FLOAT_VARS diff --git a/gecode/driver/options.cpp b/gecode/driver/options.cpp index 5ce0520da1..b5c948307b 100644 --- a/gecode/driver/options.cpp +++ b/gecode/driver/options.cpp @@ -62,7 +62,7 @@ namespace Gecode { } char* - BaseOption::stredup(const char* s) { + BaseOption::duplicate_option_flag(const char* s) { if (s == nullptr) return nullptr; size_t l = strlen(s) + 1; @@ -94,13 +94,14 @@ namespace Gecode { if (strcmp(s, eopt)) return nullptr; if (argc == 2) { - std::cerr << "Missing argument for option \"" << iopt << "\"" << std::endl; + std::cerr << "Missing argument for option \"" << iopt << "\"" << '\n' << std::flush; exit(EXIT_FAILURE); } return argv[2]; } - BaseOption::BaseOption(const char* o, const char* e) : eopt(strdup(o)), iopt(stredup(o)), exp(strdup(e)) {} + BaseOption::BaseOption(const char* o, const char* e) + : eopt(strdup(o)), iopt(duplicate_option_flag(o)), exp(strdup(e)) {} BaseOption::~BaseOption(void) { strdel(eopt); @@ -126,7 +127,7 @@ namespace Gecode { const char* arg; if (full) { if (argc < 3) { - std::cerr << "Missing argument for option -state" << std::endl; + std::cerr << "Missing argument for option -state" << '\n' << std::flush; exit(EXIT_FAILURE); } arg = argv[2]; @@ -147,14 +148,14 @@ namespace Gecode { initial.time(); else initial.hw(); - std::cerr << "% Random state: -state " << initial.state() << std::endl; + std::cerr << "% Random state: -state " << initial.state() << '\n' << std::flush; } else { initial.seed(Support::random_seed(arg)); } seed_given = true; } } catch (const std::exception& e) { - std::cerr << "Invalid random option: " << e.what() << std::endl; + std::cerr << "Invalid random option: " << e.what() << '\n' << std::flush; exit(EXIT_FAILURE); } return 2; @@ -165,7 +166,8 @@ namespace Gecode { << "\t\t" << exp << "\n" << "\t-state (complete " << Support::RandomGenerator::name() << " state; mutually exclusive with " << iopt << ")\n" - << "\t\tCurrent initial state: " << initial.state() << std::endl; + << "\t\tCurrent initial state: " << initial.state() << '\n' + << std::flush; } StringValueOption::StringValueOption(const char* o, const char* e, const char* v) @@ -185,8 +187,9 @@ namespace Gecode { } void StringValueOption::help(void) { - std::cerr << '\t' << iopt << " (string) default: " << ((cur == nullptr) ? "NONE" : cur) << std::endl - << "\t\t" << exp << std::endl; + std::cerr << '\t' << iopt << " (string) default: " << ((cur == nullptr) ? "NONE" : cur) << '\n' + << "\t\t" << exp << '\n' + << std::flush; } StringValueOption::~StringValueOption(void) { strdel(cur); @@ -230,7 +233,7 @@ namespace Gecode { cur = v->val; return 2; } - std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << std::endl; + std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << '\n' << std::flush; exit(EXIT_FAILURE); } return 0; @@ -249,10 +252,10 @@ namespace Gecode { std::cerr << ")"; if (d != nullptr) std::cerr << " default: " << d; - std::cerr << std::endl << "\t\t" << exp << std::endl; + std::cerr << '\n' << "\t\t" << exp << '\n' << std::flush; for (Value* v = fst; v != nullptr; v = v->next) if (v->help != nullptr) - std::cerr << "\t\t " << v->opt << ": " << v->help << std::endl; + std::cerr << "\t\t " << v->opt << ": " << v->help << '\n' << std::flush; } StringOption::~StringOption(void) { @@ -277,7 +280,7 @@ namespace Gecode { void IntOption::help(void) { - std::cerr << '\t' << iopt << " (int) default: " << cur << std::endl << "\t\t" << exp << std::endl; + std::cerr << '\t' << iopt << " (int) default: " << cur << '\n' << "\t\t" << exp << '\n' << std::flush; } int @@ -291,7 +294,9 @@ namespace Gecode { void UnsignedIntOption::help(void) { - std::cerr << '\t' << iopt << " (unsigned int) default: " << cur << std::endl << "\t\t" << exp << std::endl; + std::cerr << '\t' << iopt << " (unsigned int) default: " << cur << '\n' + << "\t\t" << exp << '\n' + << std::flush; } int @@ -305,8 +310,9 @@ namespace Gecode { void UnsignedLongLongIntOption::help(void) { - std::cerr << '\t' << iopt << " (unsigned long long int) default: " << cur << std::endl - << "\t\t" << exp << std::endl; + std::cerr << '\t' << iopt << " (unsigned long long int) default: " << cur << '\n' + << "\t\t" << exp << '\n' + << std::flush; } int @@ -321,7 +327,7 @@ namespace Gecode { void DoubleOption::help(void) { using namespace std; - cerr << '\t' << iopt << " (double) default: " << cur << endl << "\t\t" << exp << endl; + cerr << '\t' << iopt << " (double) default: " << cur << '\n' << "\t\t" << exp << '\n' << std::flush; } int @@ -359,8 +365,9 @@ namespace Gecode { void BoolOption::help(void) { using namespace std; - cerr << '\t' << iopt << " (optional: false, 0, true, 1) default: " << (cur ? "true" : "false") << endl - << "\t\t" << exp << endl; + cerr << '\t' << iopt << " (optional: false, 0, true, 1) default: " << (cur ? "true" : "false") << '\n' + << "\t\t" << exp << '\n' + << std::flush; } /* @@ -396,7 +403,8 @@ namespace Gecode { } else if (!strncmp("full", a, e)) { m |= IPL_FULL; } else { - std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << std::endl; + std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << '\n' + << std::flush; exit(EXIT_FAILURE); } @@ -416,7 +424,7 @@ namespace Gecode { void IplOption::help(void) { using namespace std; - cerr << '\t' << iopt << " (def,val,bnd,dom,basic,advanced,full)" << endl << "\t\tdefault: "; + cerr << '\t' << iopt << " (def,val,bnd,dom,basic,advanced,full)" << '\n' << "\t\tdefault: "; switch (vbd(cur)) { case IPL_DEF: cerr << "def"; @@ -441,7 +449,7 @@ namespace Gecode { if (cur & IPL_ADVANCED) cerr << ",advanced"; } - cerr << endl << "\t\t" << exp << endl; + cerr << '\n' << "\t\t" << exp << '\n' << std::flush; } /* @@ -485,7 +493,8 @@ namespace Gecode { } else if (!strncmp("general", a, e)) { cur = (TE_PROPAGATE | TE_COMMIT | TE_POST); } else { - std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << std::endl; + std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << '\n' + << std::flush; exit(EXIT_FAILURE); } @@ -562,7 +571,7 @@ namespace Gecode { cerr << "post"; } } - cerr << endl << "\t\t" << exp << endl; + cerr << '\n' << "\t\t" << exp << '\n' << std::flush; } int @@ -570,7 +579,7 @@ namespace Gecode { if (char* a = argument(argc, argv)) { char* sep = strchr(a, ','); if (!sep) { - std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << std::endl; + std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << '\n' << std::flush; exit(EXIT_FAILURE); } cur_execution_id = static_cast(atoi(a)); @@ -582,9 +591,9 @@ namespace Gecode { void ProfilerOption::help(void) { - std::cerr << '\t' << iopt << " (unsigned int,int) default: " << cur_port << "," << cur_execution_id - << std::endl - << "\t\t" << exp << std::endl; + std::cerr << '\t' << iopt << " (unsigned int,int) default: " << cur_port << "," << cur_execution_id << '\n' + << "\t\t" << exp << '\n' + << std::flush; } } // namespace Driver @@ -609,8 +618,8 @@ namespace Gecode { void BaseOptions::help(void) { - std::cerr << "Gecode configuration information:" << std::endl - << " - Version: " << GECODE_VERSION << std::endl + std::cerr << "Gecode configuration information:" << '\n' + << " - Version: " << GECODE_VERSION << '\n' << " - Variable types: "; #ifdef GECODE_HAS_INT_VARS std::cerr << "BoolVar IntVar "; @@ -619,14 +628,14 @@ namespace Gecode { std::cerr << "SetVar "; #endif #ifdef GECODE_HAS_FLOAT_VARS - std::cerr << "FloatVar " << std::endl << " - Trigonometric and transcendental float constraints: "; + std::cerr << "FloatVar " << '\n' << " - Trigonometric and transcendental float constraints: "; #ifdef GECODE_HAS_MPFR std::cerr << "enabled"; #else std::cerr << "disabled"; #endif #endif - std::cerr << std::endl; + std::cerr << '\n' << std::flush; std::cerr << " - Thread support: "; #ifdef GECODE_HAS_THREADS if (Support::Thread::npu() == 1) @@ -636,23 +645,24 @@ namespace Gecode { #else std::cerr << "disabled"; #endif - std::cerr << std::endl << " - Gist support: "; + std::cerr << '\n' << " - Gist support: "; #ifdef GECODE_HAS_GIST std::cerr << "enabled"; #else std::cerr << "disabled"; #endif - std::cerr << std::endl << " - CPProfiler support: "; + std::cerr << '\n' << " - CPProfiler support: "; #ifdef GECODE_HAS_CPPROFILER std::cerr << "enabled"; #else std::cerr << "disabled"; #endif - std::cerr << std::endl - << std::endl - << "Options for " << name() << ":" << std::endl - << "\t-help, --help, -?" << std::endl - << "\t\tprint this help message" << std::endl; + std::cerr << '\n' + << '\n' + << "Options for " << name() << ":" << '\n' + << "\t-help, --help, -?" << '\n' + << "\t\tprint this help message" << '\n' + << std::flush; for (Driver::BaseOption* o = fst; o != nullptr; o = o->next) o->help(); } @@ -685,7 +695,7 @@ namespace Gecode { /// Report unrecognised argument \a a, print help of \a o, and exit void unrecognised(BaseOptions& o, const char* a) { - std::cerr << "Unrecognised argument \"" << a << "\"" << std::endl; + std::cerr << "Unrecognised argument \"" << a << "\"" << '\n' << std::flush; o.help(); exit(EXIT_FAILURE); } @@ -806,8 +816,9 @@ namespace Gecode { void SizeOptions::help(void) { Options::help(); - std::cerr << "\t(unsigned int) default: " << size() << std::endl - << "\t\twhich version/size for script" << std::endl; + std::cerr << "\t(unsigned int) default: " << size() << '\n' + << "\t\twhich version/size for script" << '\n' + << std::flush; } void @@ -885,8 +896,9 @@ namespace Gecode { void InstanceOptions::help(void) { Options::help(); - std::cerr << "\t(string) default: " << ((instance() == nullptr) ? "NONE" : instance()) << std::endl - << "\t\twhich instance for script (name or file)" << std::endl; + std::cerr << "\t(string) default: " << ((instance() == nullptr) ? "NONE" : instance()) << '\n' + << "\t\twhich instance for script (name or file)" << '\n' + << std::flush; } void diff --git a/gecode/driver/script.hpp b/gecode/driver/script.hpp index bda184d1f5..bc19b13343 100644 --- a/gecode/driver/script.hpp +++ b/gecode/driver/script.hpp @@ -74,8 +74,8 @@ namespace Gecode { namespace Driver { SR_INT = 1 << 4 ///< Interrupted by user }; /// Test whether search must be stopped - virtual bool - stop(const Search::Statistics& s, const Search::Options& o) { + bool + stop(const Search::Statistics& s, const Search::Options& o) override { return sigint || ((ns != nullptr) && ns->stop(s, o)) || ((fs != nullptr) && fs->stop(s, o)) || ((ts != nullptr) && ts->stop(s, o)) || ((rs != nullptr) && rs->stop(s, o)); } @@ -102,7 +102,7 @@ namespace Gecode { namespace Driver { interrupt(DWORD t) noexcept { if (t == CTRL_C_EVENT) { sigint = true; - installCtrlHandler(false, true); + install_ctrl_handler(false, true); return true; } return false; @@ -112,12 +112,12 @@ namespace Gecode { namespace Driver { static void interrupt(int) { sigint = true; - installCtrlHandler(false, true); + install_ctrl_handler(false, true); } #endif /// Install handler for catching Ctrl-C static void - installCtrlHandler(bool install, bool force = false) { + install_ctrl_handler(bool install, bool force = false) { if (force || !sigint) { #ifdef GECODE_THREADS_WINDOWS SetConsoleCtrlHandler((PHANDLER_ROUTINE)interrupt, install); @@ -127,7 +127,7 @@ namespace Gecode { namespace Driver { } } /// Destructor - ~CombinedStop(void) { + ~CombinedStop(void) override { delete ns; delete fs; delete ts; @@ -154,7 +154,7 @@ namespace Gecode { namespace Driver { /// Create cutoff object from options template inline Search::Cutoff* - createCutoff(const Options& o) { + create_cutoff(const Options& o) { switch (o.restart()) { case RM_NONE: return nullptr; @@ -227,7 +227,7 @@ namespace Gecode { namespace Driver { /// Initialize ScriptGetInfo(void); /// Return info for a space (which must be a script) - virtual std::string getInfo(const Space& home) const; + std::string get_info(const Space& home) const override; }; #endif @@ -272,7 +272,7 @@ namespace Gecode { namespace Driver { template std::string - ScriptGetInfo::getInfo(const Space& home) const { + ScriptGetInfo::get_info(const Space& home) const { std::stringstream ss; if (const ScriptBase* sb = dynamic_cast*>(&home)) sb->print(ss); @@ -295,15 +295,15 @@ namespace Gecode { namespace Driver { void ScriptBase::run(const Options& o, Script* s) { if ((o.restart() != RM_NONE) && (o.assets() > 0)) { - std::cerr << "Cannot use restarts and portfolio..." << std::endl; + std::cerr << "Cannot use restarts and portfolio..." << '\n' << std::flush; exit(EXIT_FAILURE); } if (o.restart() != RM_NONE) { - runMeta(o, s); + run_meta(o, s); } else if (o.assets() > 0) { - runMeta(o, s); + run_meta(o, s); } else { - runMeta(o, s); + run_meta(o, s); } } @@ -311,7 +311,7 @@ namespace Gecode { namespace Driver { template class Engine, class Options, template class> class Meta> void - ScriptBase::runMeta(const Options& o, Script* s) { + ScriptBase::run_meta(const Options& o, Script* s) { using namespace std; ofstream sol_file, log_file; @@ -357,12 +357,12 @@ namespace Gecode { namespace Driver { { #ifdef GECODE_HAS_CPPROFILER if (o.profiler_port()) { - CPProfilerSearchTracer::GetInfo* getInfo = nullptr; - getInfo = new ScriptGetInfo; - so.tracer = new CPProfilerSearchTracer(o.profiler_id(), o.name(), o.profiler_port(), getInfo); + CPProfilerSearchTracer::GetInfo* get_info = nullptr; + get_info = new ScriptGetInfo; + so.tracer = new CPProfilerSearchTracer(o.profiler_id(), o.name(), o.profiler_port(), get_info); } #endif - l_out << o.name() << endl; + l_out << o.name() << '\n' << std::flush; Support::Timer t; unsigned long long int s_l = (o.solutions() == 0) ? ULLONG_MAX : o.solutions(); unsigned long long int s_n = 0; @@ -378,14 +378,14 @@ namespace Gecode { namespace Driver { so.assets = o.assets(); so.slice = o.slice(); so.stop = CombinedStop::create(o.node(), o.fail(), o.time(), o.restart_limit(), o.interrupt()); - so.cutoff = createCutoff(o); + so.cutoff = create_cutoff(o); #ifdef GECODE_HAS_EXPERIMENTAL so.guidance = o.guidance(); #endif so.clone = false; so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U; if (o.interrupt()) - CombinedStop::installCtrlHandler(true); + CombinedStop::install_ctrl_handler(true); { Meta e(s, so); if (o.print_last()) { @@ -395,6 +395,7 @@ namespace Gecode { namespace Driver { if (ex == nullptr) { if (px != nullptr) { px->print(s_out); + s_out.flush(); delete px; } break; @@ -410,21 +411,22 @@ namespace Gecode { namespace Driver { if (ex == nullptr) break; ex->print(s_out); + s_out.flush(); delete ex; s_n++; } while (s_n < s_l); } if (o.interrupt()) - CombinedStop::installCtrlHandler(false); + CombinedStop::install_ctrl_handler(false); Search::Statistics stat = e.statistics(); - s_out << endl; + s_out << '\n' << std::flush; if (e.end_reason() == Search::EndReason::Incomplete) { l_out << "Search engine finished without exhausting the search space" << '\n' << '\n'; } else if (e.end_reason() == Search::EndReason::Limit) { - l_out << "Search engine stopped..." << endl << "\treason: "; + l_out << "Search engine stopped..." << '\n' << "\treason: "; int r = static_cast(so.stop)->reason(stat, so); if (r & CombinedStop::SR_INT) - l_out << "user interrupt " << endl; + l_out << "user interrupt " << '\n'; else { if (r & CombinedStop::SR_NODE) l_out << "node "; @@ -434,34 +436,35 @@ namespace Gecode { namespace Driver { l_out << "time "; if (r & CombinedStop::SR_RESTART) l_out << "restart "; - l_out << "limit reached" << endl << endl; + l_out << "limit reached" << '\n' << '\n'; } } - l_out << "Initial" << endl - << "\tpropagators: " << n_p << endl - << "\tbranchers: " << n_b << endl - << endl - << "Summary" << endl + l_out << "Initial" << '\n' + << "\tpropagators: " << n_p << '\n' + << "\tbranchers: " << n_b << '\n' + << '\n' + << "Summary" << '\n' << "\truntime: "; stop(t, l_out); - l_out << endl - << "\tsolutions: " << s_n << endl - << "\tpropagations: " << stat.propagate << endl - << "\tnodes: " << stat.node << endl - << "\tfailures: " << stat.fail << endl - << "\trestarts: " << stat.restart << endl - << "\tno-goods: " << stat.nogood << endl - << "\tpeak depth: " << stat.depth << endl + l_out << '\n' + << "\tsolutions: " << s_n << '\n' + << "\tpropagations: " << stat.propagate << '\n' + << "\tnodes: " << stat.node << '\n' + << "\tfailures: " << stat.fail << '\n' + << "\trestarts: " << stat.restart << '\n' + << "\tno-goods: " << stat.nogood << '\n' + << "\tpeak depth: " << stat.depth << '\n' #ifdef GECODE_PEAKHEAP - << "\tpeak memory: " << static_cast((heap.peak() + 1023) / 1024) << " KB" << endl + << "\tpeak memory: " << static_cast((heap.peak() + 1023) / 1024) << " KB" << '\n' #endif - << endl; + << '\n' + << std::flush; } delete so.stop; delete so.tracer; } break; case SM_STAT: { - l_out << o.name() << endl; + l_out << o.name() << '\n' << std::flush; Support::Timer t; unsigned long long int s_l = (o.solutions() == 0) ? ULLONG_MAX : o.solutions(); unsigned long long int s_n = 0; @@ -479,13 +482,13 @@ namespace Gecode { namespace Driver { so.a_d = o.a_d(); so.d_l = o.d_l(); so.stop = CombinedStop::create(o.node(), o.fail(), o.time(), o.restart_limit(), o.interrupt()); - so.cutoff = createCutoff(o); + so.cutoff = create_cutoff(o); #ifdef GECODE_HAS_EXPERIMENTAL so.guidance = o.guidance(); #endif so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U; if (o.interrupt()) - CombinedStop::installCtrlHandler(true); + CombinedStop::install_ctrl_handler(true); { Meta e(s, so); do { @@ -496,30 +499,31 @@ namespace Gecode { namespace Driver { s_n++; } while (s_n < s_l); if (o.interrupt()) - CombinedStop::installCtrlHandler(false); + CombinedStop::install_ctrl_handler(false); Search::Statistics stat = e.statistics(); - l_out << endl - << "\tpropagators: " << n_p << endl - << "\tbranchers: " << n_b << endl + l_out << '\n' + << "\tpropagators: " << n_p << '\n' + << "\tbranchers: " << n_b << '\n' << "\truntime: "; stop(t, l_out); - l_out << endl - << "\tsolutions: " << s_n << endl - << "\tpropagations: " << stat.propagate << endl - << "\tnodes: " << stat.node << endl - << "\tfailures: " << stat.fail << endl - << "\trestarts: " << stat.restart << endl - << "\tno-goods: " << stat.nogood << endl - << "\tpeak depth: " << stat.depth << endl + l_out << '\n' + << "\tsolutions: " << s_n << '\n' + << "\tpropagations: " << stat.propagate << '\n' + << "\tnodes: " << stat.node << '\n' + << "\tfailures: " << stat.fail << '\n' + << "\trestarts: " << stat.restart << '\n' + << "\tno-goods: " << stat.nogood << '\n' + << "\tpeak depth: " << stat.depth << '\n' #ifdef GECODE_PEAKHEAP - << "\tpeak memory: " << static_cast((heap.peak() + 1023) / 1024) << " KB" << endl + << "\tpeak memory: " << static_cast((heap.peak() + 1023) / 1024) << " KB" << '\n' #endif - << endl; + << '\n' + << std::flush; } delete so.stop; } break; case SM_TIME: { - l_out << o.name() << endl; + l_out << o.name() << '\n' << std::flush; Support::Timer t; double* ts = new double[o.samples()]; bool stopped = false; @@ -538,7 +542,7 @@ namespace Gecode { namespace Driver { sok.a_d = o.a_d(); sok.d_l = o.d_l(); sok.stop = CombinedStop::create(o.node(), o.fail(), o.time(), o.restart_limit(), false); - sok.cutoff = createCutoff(o); + sok.cutoff = create_cutoff(o); #ifdef GECODE_HAS_EXPERIMENTAL sok.guidance = o.guidance(); #endif @@ -560,18 +564,19 @@ namespace Gecode { namespace Driver { ts[ns] = t.stop() / o.iterations(); } if (stopped) { - l_out << "\tSTOPPED" << endl; + l_out << "\tSTOPPED" << '\n' << std::flush; } else { double m = am(ts, o.samples()); double d = dev(ts, o.samples()) * 100.0; l_out << "\truntime: " << setw(20) << right << showpoint << fixed << setprecision(6) << m << "ms" - << setprecision(2) << " (" << d << "% deviation)" << endl; + << setprecision(2) << " (" << d << "% deviation)" << '\n' + << std::flush; } delete[] ts; } break; } } catch (Exception& e) { - cerr << "Exception: " << e.what() << "." << endl << "Stopping..." << endl; + cerr << "Exception: " << e.what() << "." << '\n' << "Stopping..." << '\n' << std::flush; if (sol_file.is_open()) sol_file.close(); if (log_file.is_open()) diff --git a/gecode/flatzinc.hh b/gecode/flatzinc.hh index 4a0efdf5f3..28a5bd9cd7 100644 --- a/gecode/flatzinc.hh +++ b/gecode/flatzinc.hh @@ -111,26 +111,26 @@ namespace Gecode { namespace FlatZinc { std::vector sv_names; #endif AST::Array* _output; - void printElem(std::ostream& out, AST::Node* ai, const Gecode::IntVarArray& iv, const Gecode::BoolVarArray& bv + void print_elem(std::ostream& out, AST::Node* ai, const Gecode::IntVarArray& iv, const Gecode::BoolVarArray& bv #ifdef GECODE_HAS_SET_VARS - , - const Gecode::SetVarArray& sv + , + const Gecode::SetVarArray& sv #endif #ifdef GECODE_HAS_FLOAT_VARS - , - const Gecode::FloatVarArray& fv + , + const Gecode::FloatVarArray& fv #endif ) const; - void printElemDiff(std::ostream& out, AST::Node* ai, const Gecode::IntVarArray& iv1, - const Gecode::IntVarArray& iv2, const Gecode::BoolVarArray& bv1, - const Gecode::BoolVarArray& bv2 + void print_elem_diff(std::ostream& out, AST::Node* ai, const Gecode::IntVarArray& iv1, + const Gecode::IntVarArray& iv2, const Gecode::BoolVarArray& bv1, + const Gecode::BoolVarArray& bv2 #ifdef GECODE_HAS_SET_VARS - , - const Gecode::SetVarArray& sv1, const Gecode::SetVarArray& sv2 + , + const Gecode::SetVarArray& sv1, const Gecode::SetVarArray& sv2 #endif #ifdef GECODE_HAS_FLOAT_VARS - , - const Gecode::FloatVarArray& fv1, const Gecode::FloatVarArray& fv2 + , + const Gecode::FloatVarArray& fv1, const Gecode::FloatVarArray& fv2 #endif ) const; public: @@ -148,56 +148,57 @@ namespace Gecode { namespace FlatZinc { #endif ) const; - void printDiff(std::ostream& out, const Gecode::IntVarArray& iv1, const Gecode::IntVarArray& iv2, - const Gecode::BoolVarArray& bv1, const Gecode::BoolVarArray& bv2 + void print_diff(std::ostream& out, const Gecode::IntVarArray& iv1, const Gecode::IntVarArray& iv2, + const Gecode::BoolVarArray& bv1, const Gecode::BoolVarArray& bv2 #ifdef GECODE_HAS_SET_VARS - , - const Gecode::SetVarArray& sv1, const Gecode::SetVarArray& sv2 + , + const Gecode::SetVarArray& sv1, const Gecode::SetVarArray& sv2 #endif #ifdef GECODE_HAS_FLOAT_VARS - , - const Gecode::FloatVarArray& fv1, const Gecode::FloatVarArray& fv2 + , + const Gecode::FloatVarArray& fv1, const Gecode::FloatVarArray& fv2 #endif ) const; ~Printer(void); - void addIntVarName(const std::string& n); + void add_int_var_name(const std::string& n); const std::string& - intVarName(int i) const { + int_var_name(int i) const { return iv_names[i]; } - void addBoolVarName(const std::string& n); + void add_bool_var_name(const std::string& n); const std::string& - boolVarName(int i) const { + bool_var_name(int i) const { return bv_names[i]; } #ifdef GECODE_HAS_FLOAT_VARS - void addFloatVarName(const std::string& n); + void add_float_var_name(const std::string& n); const std::string& - floatVarName(int i) const { + float_var_name(int i) const { return fv_names[i]; } #endif #ifdef GECODE_HAS_SET_VARS - void addSetVarName(const std::string& n); + void add_set_var_name(const std::string& n); const std::string& - setVarName(int i) const { + set_var_name(int i) const { return sv_names[i]; } #endif - void shrinkElement(AST::Node* node, std::map& iv, std::map& bv, std::map& sv, - std::map& fv); + void shrink_element(AST::Node* node, std::map& iv, std::map& bv, std::map& sv, + std::map& fv); - void shrinkArrays(Space& home, int& optVar, bool optVarIsInt, Gecode::IntVarArray& iv, Gecode::BoolVarArray& bv + void shrink_arrays(Space& home, int& opt_var, bool opt_var_is_int, Gecode::IntVarArray& iv, + Gecode::BoolVarArray& bv #ifdef GECODE_HAS_SET_VARS - , - Gecode::SetVarArray& sv + , + Gecode::SetVarArray& sv #endif #ifdef GECODE_HAS_FLOAT_VARS - , - Gecode::FloatVarArray& fv + , + Gecode::FloatVarArray& fv #endif ); @@ -215,7 +216,7 @@ namespace Gecode { namespace FlatZinc { /// \name Search options //@{ Gecode::Driver::IntOption _solutions; ///< How many solutions - Gecode::Driver::BoolOption _allSolutions; ///< Return all solutions + Gecode::Driver::BoolOption _all_solutions; ///< Return all solutions Gecode::Driver::DoubleOption _threads; ///< How many threads to use Gecode::Driver::BoolOption _free; ///< Use free search Gecode::Driver::DoubleOption _decay; ///< Decay option @@ -251,7 +252,7 @@ namespace Gecode { namespace FlatZinc { /// Constructor FlatZincOptions(const char* s) : Gecode::BaseOptions(s), _solutions("n", "number of solutions (0 = all, -1 = one/best)", -1), - _allSolutions("a", "return all solutions (equal to -n 0)"), + _all_solutions("a", "return all solutions (equal to -n 0)"), _threads("p", "number of threads (0 = #processing units)", Gecode::Search::Config::threads), _free("f", "free search, no need to follow search-specification"), _decay("decay", "decay factor", 0.99), _c_d("c-d", "recomputation commit distance", Gecode::Search::Config::c_d), @@ -289,7 +290,7 @@ namespace Gecode { namespace FlatZinc { add(_threads); add(_c_d); add(_a_d); - add(_allSolutions); + add(_all_solutions); add(_free); add(_decay); add(_node); @@ -316,7 +317,7 @@ namespace Gecode { namespace FlatZinc { void parse(int& argc, char* argv[]) { Gecode::BaseOptions::parse(argc, argv); - if (_allSolutions.value() && _solutions.value() == -1) { + if (_all_solutions.value() && _solutions.value() == -1) { _solutions.value(0); } if (_time_limit.value()) { @@ -326,11 +327,12 @@ namespace Gecode { namespace FlatZinc { _mode.value(Gecode::SM_STAT); } - virtual void - help(void) { - std::cerr << "Gecode FlatZinc interpreter" << std::endl - << " - FlatZinc text interface" << std::endl - << std::endl; + void + help(void) override { + std::cerr << "Gecode FlatZinc interpreter" << '\n' + << " - FlatZinc text interface" << '\n' + << '\n' + << std::flush; Gecode::BaseOptions::help(); } @@ -339,8 +341,8 @@ namespace Gecode { namespace FlatZinc { return _solutions.value(); } bool - allSolutions(void) const { - return _allSolutions.value(); + all_solutions(void) const { + return _all_solutions.value(); } double threads(void) const { @@ -451,8 +453,8 @@ namespace Gecode { namespace FlatZinc { #endif void - allSolutions(bool b) { - _allSolutions.value(b); + all_solutions(bool b) { + _all_solutions.value(b); } }; @@ -497,20 +499,20 @@ namespace Gecode { namespace FlatZinc { protected: /// Initialisation data (only used for posting constraints) - FlatZincSpaceInitData* _initData; + FlatZincSpaceInitData* _init_data; /// Number of integer variables - int intVarCount; + int int_var_count; /// Number of Boolean variables - int boolVarCount; + int bool_var_count; /// Number of float variables - int floatVarCount; + int float_var_count; /// Number of set variables - int setVarCount; + int set_var_count; /// Index of the variable to optimize - int _optVar; + int _opt_var; /// Whether variable to optimize is integer (or float) - bool _optVarIsInt; + bool _opt_var_is_int; /// Whether to solve as satisfaction or optimization problem Meth _method; @@ -519,13 +521,13 @@ namespace Gecode { namespace FlatZinc { unsigned int _lns; /// Initial solution to start the LNS (or nullptr for no LNS) - IntSharedArray _lnsInitialSolution; + IntSharedArray _lns_initial_solution; /// Random number generator Rnd _random; /// Annotations on the solve item - AST::Array* _solveAnnotations; + AST::Array* _solve_annotations; /// Copy constructor FlatZincSpace(FlatZincSpace&); @@ -534,12 +536,12 @@ namespace Gecode { namespace FlatZinc { friend class BlackBoxAccess; /// Run the search engine template