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
90 changes: 90 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,96 @@ Date: unreleased
This release contains breaking changes. See the entries below for the
changes downstream code needs.

[ENTRY]
Module: other
What: change
Rank: major
[DESCRIPTION]
Give abbreviated constants descriptive names, and remove the old spellings
without compatibility aliases. Values and semantics are unchanged, as are the
command-line option values and the "AOE" that StdSearchTracer prints.
[MORE]
The public renames are:
RestartMode: RM_NONE, RM_CONSTANT, RM_LINEAR, RM_LUBY, and RM_GEOMETRIC to
RESTART_NONE, RESTART_CONSTANT, RESTART_LINEAR, RESTART_LUBY, and
RESTART_GEOMETRIC, because ReifyMode also uses the prefix RM_.
ReifyMode: RM_PMI to RM_RIMP.
TaskType: TT_FIXP, TT_FIXS, and TT_FIXE to TT_FIXED_PROCESSING, TT_FIXED_START,
and TT_FIXED_END.
SetRelType: SRT_DISJ and SRT_CMPL to SRT_DISJOINT and SRT_COMPLEMENT.
SetOpType: SOT_DUNION and SOT_INTER to SOT_DISJOINT_UNION and SOT_INTERSECTION.
ScriptMode: SM_STAT to SM_STATISTICS.
MetaInfo::RestartReason: RR_NO, RR_SOL, RR_CMPL, and RR_LIM to RR_NONE,
RR_SOLUTION, RR_COMPLETE, and RR_LIMIT.
SearchTracer::EngineType: AOE to OTHER.
The test component renames are:
Test::Float::AssignmentType: CPLT_ASSIGNMENT to COMPLETE_ASSIGNMENT.
Test::MatchType: MT_ANY, MT_NOT, and MT_FIRST to MATCH_ANY, MATCH_NOT, and
MATCH_FIRST.
The internal renames are:
Int::GCC::Edge::EdgeFlag: EF_MRKLB, EF_MRKUB, EF_LM, EF_UM, and EF_DEL to
EF_MARKED_LBC, EF_MARKED_UBC, EF_MATCHED_LBC, EF_MATCHED_UBC, and EF_DELETED.
Int::NValues::RangeEventType: RET_FST and RET_LST to RET_START and RET_FINISH.
Support::IntType: IT_SHRT to IT_SHORT.
Int::BoolTest: BT_COMP to BT_COMPLEMENT.
Int::Cumulatives::EventType: EVENT_CHCK and EVENT_PRUN to EVENT_CHECK and
EVENT_PRUNE.

[ENTRY]
Module: other
What: change
Rank: major
[DESCRIPTION]
Make 68 enums enum class, with using enum at their scope or, in class templates,
static constexpr aliases, so existing spellings such as IRT_EQ,
Gecode::SS_FAILED, and IntVarBranch::SEL_RND still compile. Their values stop converting to int and stop mixing with other enums.
Code that stores such a value in an int, does arithmetic or bitwise operations
on it, streams it, uses it as an array index or a bit position such as
1 << RM_EQV, or compares it with an integer no longer compiles. Convert
explicitly with std::to_underlying or static_cast. Installed headers now use
std::to_underlying, so code that does not build through the exported CMake
targets needs C++23 as well.
[MORE]
The scoped enums are:
Kernel: ExecStatus, SpaceStatus, ActorProperty, PropCost::ActualCost,
PropCost::Mod, ViewTraceInfo::What, PropagateTraceInfo::Status,
PostTraceInfo::Status, NGL::Status, MetaInfo::Type, MetaInfo::RestartReason,
TFE::NodeType.
Search: SearchTracer::EngineType, SearchTracer::NodeType,
Search::HeuristicGuidance::Sense, Search::Beam::Offer,
Search::Seq::ExpansionStep::State, Search::Par::Engine::Cmd,
CPProfiler::NodeStatus, CPProfiler::MessageMarshalling::Field.
Integer: ReifyMode, IntRelType, BoolOpType, IntPropLevel, TaskType,
TupleSet::Data::State, IntVarBranch::Select, BoolVarBranch::Select,
IntValBranch::Select, BoolValBranch::Select, IntAssign::Select,
BoolAssign::Select, Int::Cumulatives::EventType (formerly the typedef ev_t),
Int::Extensional::CompactStatus::StatusType, Int::GCC::BC,
Int::NValues::RangeEventType, Int::Sequence::TakesStatus, Int::SortTaskOrder,
Int::Event::Type, Int::RelTest, Int::BoolTest.
Set: SetRelType, SetOpType, SetVarBranch::Select, SetValBranch::Select,
SetAssign::Select.
Float: FloatRelType, FloatVarBranch::Select, FloatValBranch::Select,
FloatAssign::Select, Float::RelTest.
MiniModel: LinIntExpr::NodeType, LinFloatExpr::NodeType, SetExpr::NodeType,
BoolExpr::NodeType.
Driver: ScriptMode, RestartMode.
FlatZinc: FlatZinc::FlatZincSpace::Meth, FlatZinc::IntBoolVarBranch::Select,
FlatZinc::SymbolType.
Gist, support, and iterators: Gist::NodeStatus, Support::BitSetStatus,
Support::IntType, Iter::Ranges::CompareStatus.
Test component: Test::MatchType, Test::Int::ConTestLevel,
Test::Float::MaybeType, Test::Float::AssignmentType.

[ENTRY]
Module: int
What: change
Rank: major
[DESCRIPTION]
IntPropLevel is enum class with underlying type unsigned int and gains
operator|, operator&, and operator|=, so levels combine without casts. Test a
bit with (ipl & IPL_BASIC) != IPL_DEF, since the result no longer converts to
bool. Remove IPL_BITS_, which was a bit-field width rather than a level.

[ENTRY]
Module: kernel
What: change
Expand Down
50 changes: 49 additions & 1 deletion docs/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ Representative API changes include:
| Previous spelling | Current spelling |
|---|---|
| `IRT_LE`, `FRT_LE`, `SRT_LE` | `IRT_LT`, `FRT_LT`, `SRT_LT` |
| `RM_NONE`, `RM_CONSTANT`, `RM_LINEAR`, `RM_LUBY`, `RM_GEOMETRIC` | `RESTART_NONE`, `RESTART_CONSTANT`, `RESTART_LINEAR`, `RESTART_LUBY`, `RESTART_GEOMETRIC` |
| `RM_PMI` | `RM_RIMP` |
| `TT_FIXP`, `TT_FIXS`, `TT_FIXE` | `TT_FIXED_PROCESSING`, `TT_FIXED_START`, `TT_FIXED_END` |
| `SRT_DISJ`, `SRT_CMPL` | `SRT_DISJOINT`, `SRT_COMPLEMENT` |
| `SOT_DUNION`, `SOT_INTER` | `SOT_DISJOINT_UNION`, `SOT_INTERSECTION` |
| `SM_STAT` | `SM_STATISTICS` |
| `RR_NO`, `RR_SOL`, `RR_CMPL`, `RR_LIM` | `RR_NONE`, `RR_SOLUTION`, `RR_COMPLETE`, `RR_LIMIT` |
| `SearchTracer::AOE` | `SearchTracer::OTHER` |
| `CPLT_ASSIGNMENT` | `COMPLETE_ASSIGNMENT` |
| `MT_ANY`, `MT_NOT`, `MT_FIRST` | `MATCH_ANY`, `MATCH_NOT`, `MATCH_FIRST` |
| `EF_MRKLB`, `EF_MRKUB`, `EF_LM`, `EF_UM`, `EF_DEL` | `EF_MARKED_LBC`, `EF_MARKED_UBC`, `EF_MATCHED_LBC`, `EF_MATCHED_UBC`, `EF_DELETED` |
| `RET_FST`, `RET_LST` | `RET_START`, `RET_FINISH` |
| `IT_SHRT` | `IT_SHORT` |
| `BT_COMP` | `BT_COMPLEMENT` |
| `EVENT_CHCK`, `EVENT_PRUN` | `EVENT_CHECK`, `EVENT_PRUNE` |
| `nooverlap(...)` | `no_overlap(...)` |
| `binpacking(...)` | `bin_packing(...)` |
| `modeventdelta(...)` | `modification_event_delta(...)` |
Expand All @@ -66,11 +81,44 @@ Representative API changes include:
| `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.
The former `_LE` names have no compatibility aliases, and neither do the other
former constant spellings in the table.

Qt overrides and other external interfaces retain the spellings their APIs
require. Parser tokens and protocol strings remain unchanged.

## Enums

New enums are `enum class`. Use a plain `enum` only where an existing API
requires it, or where the values are bits or bit positions held in an `int`,
as with `TraceEvent`.

A public enum converted from a plain enum keeps its `UPPER_CASE` constants
usable without qualification through `using enum`, on the line after the enum
and at the same scope:

```cpp
enum class IntRelType { IRT_EQ, IRT_NQ, ... };
using enum IntRelType;
```

`using enum` cannot name a dependent type, so an enum in a class template
declares one `static constexpr` alias per constant instead, as
`CompactStatus<Advisor>::StatusType` does.

A new enum names its constants in `PascalCase` and is always used qualified,
as in `MetaEvent::Solution`, so it has no `using enum`.

Give an enum operators only if its values form a real bit set. `IntPropLevel`
is the one such enum, with `operator|`, `operator&`, and `operator|=`. Test a
bit with `(ipl & IPL_BASIC) != IPL_DEF`. Its underlying type is unsigned
because `IntPropLevels` stores levels in bit-fields, where a signed type would
change their values.

All other conversions are explicit: `std::to_underlying` or `static_cast` for
an array index, a bit position, a packed field, or an `int`-valued option, and
`static_cast` back to the enum.

## Checking changes

Put LLVM 22 tools on `PATH`, or set `CLANG_FORMAT` and `CLANG_TIDY` to their
Expand Down
12 changes: 6 additions & 6 deletions examples/sudoku-advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class SudokuInt : virtual public Sudoku {
void
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);
rel(home, SOT_DISJOINT_UNION, a, u);
rel(home, SOT_DISJOINT_UNION, b, u);
}

/// The fields of column \a c outside box row \a j
Expand Down Expand Up @@ -303,18 +303,18 @@ class SudokuSet : virtual public Sudoku {

IntSet full(1, nn * nn);
// All x must be pairwise disjoint and partition the field indices
rel(*this, SOT_DUNION, y, SetVar(*this, full, full));
rel(*this, SOT_DISJOINT_UNION, y, SetVar(*this, full, full));

// The x must intersect in exactly one element with each
// row, column, and block
for (int i = 0; i < nn; i++)
for (int j = 0; j < nn; j++) {
SetVar inter_row(*this, IntSet::empty, full, 1U, 1U);
rel(*this, y[i], SOT_INTER, row[j], SRT_EQ, inter_row);
rel(*this, y[i], SOT_INTERSECTION, row[j], SRT_EQ, inter_row);
SetVar inter_col(*this, IntSet::empty, full, 1U, 1U);
rel(*this, y[i], SOT_INTER, col[j], SRT_EQ, inter_col);
rel(*this, y[i], SOT_INTERSECTION, col[j], SRT_EQ, inter_col);
SetVar inter_block(*this, IntSet::empty, full, 1U, 1U);
rel(*this, y[i], SOT_INTER, block[j], SRT_EQ, inter_block);
rel(*this, y[i], SOT_INTERSECTION, block[j], SRT_EQ, inter_block);
}

// Fill-in predefined fields
Expand Down
24 changes: 13 additions & 11 deletions gecode/driver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,26 @@ namespace Gecode {
* \brief Different modes for executing scripts
* \ingroup TaskDriverCmd
*/
enum ScriptMode {
SM_SOLUTION, ///< Print solution and some statistics
SM_TIME, ///< Measure average runtime
SM_STAT, ///< Print statistics for script
SM_GIST, ///< Run script in Gist
enum class ScriptMode {
SM_SOLUTION, ///< Print solution and some statistics
SM_TIME, ///< Measure average runtime
SM_STATISTICS, ///< Print statistics for script
SM_GIST, ///< Run script in Gist
};
using enum ScriptMode;

/**
* \brief Different modes for restart-based search
* \ingroup TaskDriverCmd
*/
enum RestartMode {
RM_NONE, ///< No restarts
RM_CONSTANT, ///< Restart with constant sequence
RM_LINEAR, ///< Restart with linear sequence
RM_LUBY, ///< Restart with Luby sequence
RM_GEOMETRIC ///< Restart with geometric sequence
enum class RestartMode {
RESTART_NONE, ///< No restarts
RESTART_CONSTANT, ///< Restart with constant sequence
RESTART_LINEAR, ///< Restart with linear sequence
RESTART_LUBY, ///< Restart with Luby sequence
RESTART_GEOMETRIC ///< Restart with geometric sequence
};
using enum RestartMode;

class BaseOptions;

Expand Down
33 changes: 17 additions & 16 deletions gecode/driver/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ namespace Gecode {
int
IplOption::parse(int argc, char* argv[]) {
if (char* a = argument(argc, argv)) {
int b = IPL_DEF;
int m = IPL_DEF;
IntPropLevel b = IPL_DEF;
IntPropLevel m = IPL_DEF;
do {
// Search for a comma
char* c = a;
Expand Down Expand Up @@ -415,7 +415,7 @@ namespace Gecode {

} while (*a != 0);

cur = static_cast<IntPropLevel>(b | m);
cur = b | m;
return 2;
}
return 0;
Expand Down Expand Up @@ -444,9 +444,9 @@ namespace Gecode {
if ((cur & IPL_FULL) == IPL_FULL)
cerr << ",full";
else {
if (cur & IPL_BASIC)
if ((cur & IPL_BASIC) != IPL_DEF)
cerr << ",basic";
if (cur & IPL_ADVANCED)
if ((cur & IPL_ADVANCED) != IPL_DEF)
cerr << ",advanced";
}
cerr << '\n' << "\t\t" << exp << '\n' << std::flush;
Expand Down Expand Up @@ -730,7 +730,7 @@ namespace Gecode {
_time("time", "time (in ms) cutoff (0 = none, solution mode)"),
_assets("assets", "#portfolio assets (#engines)", 0),
_slice("slice", "portfolio slice (in #failures)", Search::Config::slice),
_restart("restart", "restart sequence type", RM_NONE),
_restart("restart", "restart sequence type", static_cast<int>(RESTART_NONE)),
_r_base("restart-base", "base for geometric restart sequence", Search::Config::base),
_r_scale("restart-scale", "scale factor for restart sequence", Search::Config::slice),
_r_limit("restart-limit", "restart cutoff (0 = none, solution mode)"),
Expand All @@ -742,7 +742,8 @@ namespace Gecode {
#ifdef GECODE_HAS_EXPERIMENTAL
_guidance(nullptr),
#endif
_mode("mode", "how to execute script", SM_SOLUTION), _samples("samples", "how many samples (time mode)", 1),
_mode("mode", "how to execute script", static_cast<int>(SM_SOLUTION)),
_samples("samples", "how many samples (time mode)", 1),
_iterations("iterations", "iterations per sample (time mode)", 1),
_print_last("print-last", "whether to only print the last solution (solution mode)", false),
_out_file("file-sol",
Expand All @@ -761,16 +762,16 @@ namespace Gecode {
#endif
{

_mode.add(SM_SOLUTION, "solution");
_mode.add(SM_TIME, "time");
_mode.add(SM_STAT, "stat");
_mode.add(SM_GIST, "gist");
_mode.add(static_cast<int>(SM_SOLUTION), "solution");
_mode.add(static_cast<int>(SM_TIME), "time");
_mode.add(static_cast<int>(SM_STATISTICS), "stat");
_mode.add(static_cast<int>(SM_GIST), "gist");

_restart.add(RM_NONE, "none");
_restart.add(RM_CONSTANT, "constant");
_restart.add(RM_LINEAR, "linear");
_restart.add(RM_LUBY, "luby");
_restart.add(RM_GEOMETRIC, "geometric");
_restart.add(static_cast<int>(RESTART_NONE), "none");
_restart.add(static_cast<int>(RESTART_CONSTANT), "constant");
_restart.add(static_cast<int>(RESTART_LINEAR), "linear");
_restart.add(static_cast<int>(RESTART_LUBY), "luby");
_restart.add(static_cast<int>(RESTART_GEOMETRIC), "geometric");

add(_model);
add(_symmetry);
Expand Down
4 changes: 2 additions & 2 deletions gecode/driver/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ namespace Gecode {

inline void
Options::restart(RestartMode rm) {
_restart.value(rm);
_restart.value(static_cast<int>(rm));
}
inline RestartMode
Options::restart(void) const {
Expand Down Expand Up @@ -491,7 +491,7 @@ namespace Gecode {
*/
inline void
Options::mode(ScriptMode sm) {
_mode.value(sm);
_mode.value(static_cast<int>(sm));
}
inline ScriptMode
Options::mode(void) const {
Expand Down
16 changes: 8 additions & 8 deletions gecode/driver/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ namespace Gecode { namespace Driver {
inline Search::Cutoff*
create_cutoff(const Options& o) {
switch (o.restart()) {
case RM_NONE:
case RESTART_NONE:
return nullptr;
case RM_CONSTANT:
case RESTART_CONSTANT:
return Search::Cutoff::constant(o.restart_scale());
case RM_LINEAR:
case RESTART_LINEAR:
return Search::Cutoff::linear(o.restart_scale());
case RM_LUBY:
case RESTART_LUBY:
return Search::Cutoff::luby(o.restart_scale());
case RM_GEOMETRIC:
case RESTART_GEOMETRIC:
return Search::Cutoff::geometric(o.restart_scale(), o.restart_base());
default:
GECODE_NEVER;
Expand Down Expand Up @@ -291,11 +291,11 @@ namespace Gecode { namespace Driver {
template <class Script, template <class> class Engine, class Options>
void
ScriptBase<BaseSpace>::run(const Options& o, Script* s) {
if ((o.restart() != RM_NONE) && (o.assets() > 0)) {
if ((o.restart() != RESTART_NONE) && (o.assets() > 0)) {
std::cerr << "Cannot use restarts and portfolio..." << '\n' << std::flush;
exit(EXIT_FAILURE);
}
if (o.restart() != RM_NONE) {
if (o.restart() != RESTART_NONE) {
run_meta<Script, Engine, Options, RBS>(o, s);
} else if (o.assets() > 0) {
run_meta<Script, Engine, Options, PBS>(o, s);
Expand Down Expand Up @@ -460,7 +460,7 @@ namespace Gecode { namespace Driver {
delete so.stop;
delete so.tracer;
} break;
case SM_STAT: {
case SM_STATISTICS: {
l_out << o.name() << '\n' << std::flush;
Support::Timer t;
unsigned long long int s_l = (o.solutions() == 0) ? ULLONG_MAX : o.solutions();
Expand Down
Loading
Loading