Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ jobs:
shell: bash
run: >
ctest --test-dir "$GITHUB_WORKSPACE/build-ninja"
--output-on-failure -R '^(build-gecode-test|test)$'
--output-on-failure -R '^(build-gecode-test|test|hub-spoke-api-.*)$'

- name: Configure CMake Debug audit smoke
shell: bash
Expand Down
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,35 @@ if(BUILD_TESTING)
message(WARNING "Skipping public test harness targets because required modules are disabled")
endif()

# Overrides of the hub()/spoke() Space hooks must compile, and a Gecode 6
# master() or slave() override must not, even without override. Each fail
# case overrides one old hook and must fail with the deleted-function
# diagnostic, not for another reason. MSVC words it differently (C2282),
# so there the test only requires the build to fail.
foreach(api pass fail-master fail-slave)
add_library(hub-spoke-api-${api} OBJECT EXCLUDE_FROM_ALL test/search/hub-spoke-api-${api}.cpp)
target_link_libraries(hub-spoke-api-${api} PRIVATE gecodekernel)
add_test(NAME hub-spoke-api-${api}
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}"
--target hub-spoke-api-${api} --config $<CONFIG>)
endforeach()
set_tests_properties(hub-spoke-api-pass PROPERTIES
FIXTURES_SETUP hub-spoke-api
RESOURCE_LOCK gecode-test-build)
foreach(hook master slave)
# The failing fixtures stay out of the compilation database used for lint.
set_target_properties(hub-spoke-api-fail-${hook} PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
set_tests_properties(hub-spoke-api-fail-${hook} PROPERTIES
FIXTURES_REQUIRED hub-spoke-api
RESOURCE_LOCK gecode-test-build)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_tests_properties(hub-spoke-api-fail-${hook} PROPERTIES WILL_FAIL TRUE)
else()
set_tests_properties(hub-spoke-api-fail-${hook} PROPERTIES
PASS_REGULAR_EXPRESSION "cannot override a deleted function;overriding deleted function")
endif()
endforeach()

set(GECODE_CAN_BUILD_TESTS ${GECODE_CAN_BUILD_TEST_HARNESS})
foreach(required minimodel driver)
if(NOT TARGET gecode${required})
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ The tutorial *Modeling and Programming with Gecode* explains how to model
and solve problems with Gecode, and the reference documentation describes
the complete API.

For source-level breaking changes, see the
[Gecode 7 migration notes](docs/gecode-7-migration.md).

## Download Gecode

Gecode 6.5.0 is distributed as source code. Source archives can be downloaded from
Expand Down
12 changes: 12 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ Date: unreleased
[DESCRIPTION]
This is the development changelog for the next Gecode release.

[ENTRY]
Module: search
What: change
Rank: major
[DESCRIPTION]
Rename the meta-search Space hooks master() and slave() to hub() and spoke().
[MORE]
There are no compatibility aliases. Space declares master() and slave() as
deleted, so an old override fails to compile with or without override. This
includes the FlatZincSpace override of slave(). See
docs/gecode-7-migration.md.

[ENTRY]
Module: search
What: change
Expand Down
42 changes: 42 additions & 0 deletions docs/gecode-7-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Gecode 7 migration notes

## Meta-search hooks: master() and slave() are now hub() and spoke()

Rename the overrides. Their signatures and return values are unchanged:

```cpp
// Gecode 6
bool master(const Gecode::MetaInfo& mi) override;
bool slave(const Gecode::MetaInfo& mi) override;

// Gecode 7
bool hub(const Gecode::MetaInfo& mi) override;
bool spoke(const Gecode::MetaInfo& mi) override;
```

There are no compatibility aliases. `Space` declares `master()` and
`slave()` as deleted, so an old override fails to compile whether or not it
is marked `override`. Restart-based search (RBS) and portfolio-based search
(PBS) call the renamed hooks at the same points and with the same defaults
as before.

The hooks run on these spaces:

- RBS calls `hub()` after each solution and at each restart. The hub
carries the last solution and the no-goods from one restart to the next.
RBS calls `spoke()` on each new spoke, a clone of the hub, including the
first. The default `hub()` constrains the hub with the last solution, if
any, and posts the no-goods.
- PBS calls `hub()` once, then calls `spoke()` with the asset number on the
spoke of each asset, the hub or a clone of it. The default `hub()`
removes all branchers, so `spoke()` must post the branching of each
asset.

The examples show typical overrides:

- `examples/crossword.cpp`: a `hub()` that posts no-goods and continues
after a solution instead of restarting.
- `examples/photo.cpp`: an RBS `spoke()` that relaxes the last solution for
large neighbourhood search.
- `examples/qcp.cpp`: a PBS `spoke()` that posts a different branching for
each asset.
2 changes: 1 addition & 1 deletion examples/crossword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Crossword : public Script {
<< n;
}
/// Do not perform a restart when a solution is found
bool master(const MetaInfo& mi) {
bool hub(const MetaInfo& mi) {
if (mi.type() == MetaInfo::RESTART)
// Post no-goods
mi.nogoods().post(*this);
Expand Down
30 changes: 15 additions & 15 deletions examples/job-shop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,16 +700,16 @@ solve(const JobShopOptions& opt) {
{
Support::Timer t; t.start();
Search::Statistics stat;
JobShopProbe* master = new JobShopProbe(opt);
JobShopProbe* root = new JobShopProbe(opt);

if (master->status() != SS_SOLVED) {
delete master;
if (root->status() != SS_SOLVED) {
delete root;
std::cerr << "Error: has no solution..." << std::endl;
return;
}

l = master->cost().min();
u = master->cost().max();
l = root->cost().min();
u = root->cost().max();

FailTimeStop fts(opt.fail_probe(),opt.time_probe());
CommonOptions so(opt);
Expand All @@ -722,7 +722,7 @@ solve(const JobShopOptions& opt) {
<< std::endl;

for (unsigned int p=0; p<opt.probes(); p++) {
JobShopProbe* jsp = static_cast<JobShopProbe*>(master->clone());
JobShopProbe* jsp = static_cast<JobShopProbe*>(root->clone());
jsp->branch(p,rnd);
DFS<JobShopProbe> dfs(jsp,so);
JobShopProbe* s = dfs.next();
Expand All @@ -740,7 +740,7 @@ solve(const JobShopOptions& opt) {
}
stat += statj;
}
delete master;
delete root;

print(stat,false);
std::cout << "\t\t\truntime: ";
Expand All @@ -756,11 +756,11 @@ solve(const JobShopOptions& opt) {

// Dichotomic search
{
JobShopSolve* master = new JobShopSolve(opt);
JobShopSolve* model = new JobShopSolve(opt);


if (master->status() == SS_FAILED) {
delete master;
if (model->status() == SS_FAILED) {
delete model;
std::cerr << "Error: has no solution..." << std::endl;
return;
}
Expand All @@ -775,7 +775,7 @@ solve(const JobShopOptions& opt) {
while (l < u) {
std::cout << "\t\tBounds: [" << l << "," << u << "]"
<< std::endl;
JobShopSolve* jss = static_cast<JobShopSolve*>(master->clone());
JobShopSolve* jss = static_cast<JobShopSolve*>(model->clone());
int m = (l + u) / 2;
rel(*jss, jss->cost() >= l);
rel(*jss, jss->cost() <= m);
Expand Down Expand Up @@ -810,7 +810,7 @@ solve(const JobShopOptions& opt) {
}

if (l == u) {
delete master;
delete model;
std::cout << std::endl
<< "\tFound best solution and proved optimality."
<< std::endl;
Expand All @@ -822,15 +822,15 @@ solve(const JobShopOptions& opt) {
Support::Timer t; t.start();
std::cout << std::endl << "\tSolving..." << std::endl;

rel(*master, master->cost() >= l);
rel(*master, master->cost() < u);
rel(*model, model->cost() >= l);
rel(*model, model->cost() < u);

CommonOptions so(opt);
if (opt.time_solve() > 0U)
so.stop = Search::Stop::time(opt.time_solve());
so.cutoff = Search::Cutoff::geometric(JobShopConfig::restart_scale,
JobShopConfig::restart_base);
RBS<JobShopSolve,BAB> rbs(master,so);
RBS<JobShopSolve,BAB> rbs(model,so);
while (JobShopSolve* s = rbs.next()) {
s->print(std::cout);
u = s->cost().val();
Expand Down
4 changes: 2 additions & 2 deletions examples/photo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class Photo : public IntMinimizeScript {
break;
}
}
/// Slave function for restarts
bool slave(const MetaInfo& mi) {
/// Spoke function for restarts
bool spoke(const MetaInfo& mi) {
if ((mi.type() == MetaInfo::RESTART) &&
(mi.restart() > 0) && (p > 0.0)) {
const Photo& l = static_cast<const Photo&>(*mi.last());
Expand Down
4 changes: 2 additions & 2 deletions examples/qcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ class QCP : public Script {
}
}
}
/// Slave function for portfolio search
virtual bool slave(const MetaInfo& mi) {
/// Spoke function for portfolio search
virtual bool spoke(const MetaInfo& mi) {
if (mi.type() == MetaInfo::PORTFOLIO) {
double tbf = opt.tbf();
Rnd r(seeds[mi.asset() % n_seeds]);
Expand Down
4 changes: 2 additions & 2 deletions gecode/flatzinc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ namespace Gecode { namespace FlatZinc {
virtual void constrain(const Space& s);
/// Copy function
virtual Gecode::Space* copy(void);
/// Slave function for restarts
virtual bool slave(const MetaInfo& mi);
/// Spoke function for restarts
virtual bool spoke(const MetaInfo& mi);

/// \name AST to variable and value conversion
//@{
Expand Down
2 changes: 1 addition & 1 deletion gecode/flatzinc/flatzinc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ namespace Gecode { namespace FlatZinc {
}

bool
FlatZincSpace::slave(const MetaInfo& mi) {
FlatZincSpace::spoke(const MetaInfo& mi) {
if (mi.type() == MetaInfo::RESTART) {
if (restart_data.initialized() && restart_data().mark_complete) {
// Fail the space
Expand Down
4 changes: 2 additions & 2 deletions gecode/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ namespace Gecode {
}

bool
Space::master(const MetaInfo& mi) {
Space::hub(const MetaInfo& mi) {
switch (mi.type()) {
case MetaInfo::RESTART:
if (mi.last() != nullptr)
Expand All @@ -920,7 +920,7 @@ namespace Gecode {
}

bool
Space::slave(const MetaInfo&) {
Space::spoke(const MetaInfo&) {
return true;
}

Expand Down
Loading
Loading