Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5348193
Add open integer variable sequences
zayenz Aug 22, 2026
fff1c38
Compact sparse DFA state identifiers
zayenz Aug 23, 2026
1576b5b
Fix open sequence lifetime and materialization
zayenz Oct 4, 2026
544cacc
Fix open sequence commits and regular edge cases
zayenz Oct 4, 2026
d36ca39
Fix open sequence compilation on Windows
zayenz Oct 4, 2026
db9b4b6
Generalize open sequences and reuse standard branching selectors
zayenz Oct 5, 2026
1e99432
Fix open sequence no-good extraction and clone cleanup
zayenz Oct 5, 2026
b9bd560
Keep delayed open-sequence constraints in their posting group
zayenz Oct 5, 2026
1f7866f
Rename open variable sequences to lists
zayenz Oct 6, 2026
d1ee1db
Use the standard harness for closed open-list constraints
Oct 12, 2026
5e20c4f
Harden open-list branching and clarify its public contract
zayenz Oct 12, 2026
55dc729
Simplify open-list branching and add a route example
zayenz Oct 13, 2026
806e837
Add constrained common-pattern mining example
zayenz Oct 13, 2026
4f929ea
Add reproducible common-pattern comparisons
zayenz Oct 13, 2026
cc1aee2
Model constrained frequent subsequences with open lists
zayenz Oct 13, 2026
47fc164
Reduce projection work in common-pattern mining
zayenz Oct 13, 2026
0d1c499
Rename open-list prefix query to known_length
zayenz Oct 13, 2026
de4f810
Apply coding style guidance to pattern benchmark
zayenz Oct 13, 2026
60325e4
Add BAB 15-puzzle example with open and fixed models
zayenz Oct 14, 2026
81fff38
Defer open puzzle goal checks until board assignment
zayenz Oct 14, 2026
fc26a2a
Prune open puzzle states using the remaining move budget
zayenz Oct 14, 2026
8d300cd
Add scoped suppression of global propagator information
zayenz Oct 14, 2026
8b7df67
Add scoped GPI opt-in and fix CBS cache iteration
zayenz Oct 14, 2026
6d83edb
Place posting flag in CBS alignment padding
zayenz Oct 14, 2026
2be74e7
Use NoGPI for open-list factories and transitions
zayenz Oct 14, 2026
462123d
Document NoGPI scopes on open-list materialization methods
zayenz Oct 14, 2026
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
1,325 changes: 909 additions & 416 deletions Makefile.dep

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ INTSRC0 = \
int-set.cpp var-imp/int.cpp var-imp/bool.cpp var/int.cpp \
var/bool.cpp array.cpp bool.cpp bool/eqv.cpp \
extensional/dfa.cpp extensional/tuple-set.cpp \
extensional-regular.cpp extensional-tuple-set.cpp \
extensional-regular.cpp extensional-open-regular.cpp \
extensional-tuple-set.cpp \
open-var-list.cpp \
dom.cpp rel.cpp precede.cpp element.cpp count.cpp \
arithmetic.cpp exec.cpp \
exec/when.cpp element/pair.cpp \
Expand All @@ -348,6 +350,7 @@ INTSRC0 = \
exception.cpp

INTHDR0 = \
open-var-list.hpp \
limits.hpp support-values.hh support-values.hpp \
idx-view.hh idx-view.hpp div.hh div.hpp \
exec.hh exec/when.hpp \
Expand Down Expand Up @@ -906,7 +909,7 @@ INTEXAMPLESRC0 = \
word-square crossword open-shop car-sequencing sat \
bin-packing knights tsp perfect-square schurs-lemma \
dominating-queens colored-matrix multi-bin-packing \
qcp job-shop
qcp job-shop open-route common-pattern fifteen-puzzle


INTEXAMPLEHDR = $(INTEXAMPLEHDR0:%=examples/%.hpp)
Expand Down Expand Up @@ -1119,7 +1122,7 @@ EXETARGETS = $(FLATZINCEXE) $(FLATZINCLAUNCHER)

INTTESTSRC00 = \
channel arithmetic basic bool count dom distinct element extensional \
rel linear gcc sorted unshare exec sequence \
rel linear gcc sorted unshare exec sequence open-var-list \
mm-arithmetic mm-bool mm-lin mm-count mm-rel \
bin-packing order unary cumulative cumulatives circuit \
no-overlap precede nvalues member min-distance
Expand Down
40 changes: 40 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,46 @@ Date: unreleased
[DESCRIPTION]
This is the development changelog for the next Gecode release.

[ENTRY]
Module: int
What: new
Rank: major
[DESCRIPTION]
Add OpenIntVarList and OpenBoolVarList for lists whose length is decided
during propagation and search. OpenVarList supports other variable types
through a factory. Constraints follow the growing prefix, including regular
language constraints. Branching assigns prefix values before closing or
extending the list, using standard variable and value selectors. Posting a
brancher on the length first selects the length before list values. The
common-pattern example demonstrates constrained frequent subsequence mining
without padding, with support thresholds and integer database input;
open-route provides a smaller introduction.
Open-list factories and transitions run inside Space::NoGPI scopes by
default, including transitions called by direct append. Callback-local
Space::UseGPI scopes enable global information for selected postings;
nested list construction starts its own NoGPI scope.

[ENTRY]
Module: kernel
What: new
Rank: minor
[DESCRIPTION]
Add Space::NoGPI for scoped posting without globally shared propagator
information. Scoped propagators keep their identifiers and groups in the
space, have zero AFC, and copy their information when cloned. Rewriting
preserves the original propagator information. Space::UseGPI enables global
information for selected posting calls inside a NoGPI scope. Both contexts
restore the previous setting when they leave scope.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Fix iterator invalidation when counting-based search removes expired
propagator cache entries. The invalid iterator could skip remaining entries
and leave the brancher without a choice.

[ENTRY]

Module: int
Expand Down
3 changes: 3 additions & 0 deletions cmake/GecodeSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ set(GECODE_INT_SOURCES
gecode/int/exec.cpp
gecode/int/exec/when.cpp
gecode/int/extensional-regular.cpp
gecode/int/extensional-open-regular.cpp
gecode/int/extensional-tuple-set.cpp
gecode/int/open-var-list.cpp
gecode/int/extensional/dfa.cpp
gecode/int/extensional/tuple-set.cpp
gecode/int/gcc.cpp
Expand Down Expand Up @@ -426,6 +428,7 @@ set(GECODE_TEST_SOURCES
test/int/no-overlap.cpp
test/int/nvalues.cpp
test/int/order.cpp
test/int/open-var-list.cpp
test/int/precede.cpp
test/int/rel.cpp
test/int/sequence.cpp
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(GECODE_EXAMPLE_SOURCES
car-sequencing.cpp
cartesian-heart.cpp
colored-matrix.cpp
common-pattern.cpp
crew.cpp
crossword.cpp
crowded-chess.cpp
Expand All @@ -22,6 +23,7 @@ set(GECODE_EXAMPLE_SOURCES
donald.cpp
efpa.cpp
eq20.cpp
fifteen-puzzle.cpp
golden-spiral.cpp
golf.cpp
golomb-ruler.cpp
Expand All @@ -40,6 +42,7 @@ set(GECODE_EXAMPLE_SOURCES
money.cpp
multi-bin-packing.cpp
nonogram.cpp
open-route.cpp
open-shop.cpp
ortho-latin.cpp
partition.cpp
Expand Down
251 changes: 251 additions & 0 deletions examples/common-pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main author:
* Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
*
* Copyright:
* Mikael Zayenz Lagerkvist, 2026
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.dev
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

#include <gecode/driver.hh>

#include "common-pattern.hh"

#include <fstream>
#include <memory>

using namespace Gecode;

/// Sequence database and restrictions on the patterns to mine
class CommonPatternOptions : public Options {
protected:
Driver::StringValueOption _sequences, _file, _support, _required;
Driver::StringOption _format, _language;
Driver::UnsignedIntOption _min_length;
Driver::BoolOption _motif;
std::unique_ptr<PatternMining::Database> input;
std::vector<int> required_items;
int threshold;
public:
CommonPatternOptions(void)
: Options("CommonPattern"),
_sequences("sequences","comma-separated sequences over A..Z","ABCBC,BABC,ABDC"),
_file("file","sequence database; one sequence per line",""),
_support("support","minimum supporting sequences, as a percentage","100"),
_required("required","items that must occur, comma-separated letters or IDs",""),
_format("format","database format",PatternMining::LETTERS),
_language("language","pattern language",PatternMining::DEFAULT),
_min_length("min-length","minimum pattern length",1),
_motif("motif","default language starts with A and ends with C",true),
threshold(0) {
_format.add(PatternMining::LETTERS,"letters");
_format.add(PatternMining::INTEGERS,"integers");
_format.add(PatternMining::SPMF,"spmf");
_language.add(PatternMining::DEFAULT,"default","use -motif");
_language.add(PatternMining::NONE,"none");
_language.add(PatternMining::MOTIF,"motif");
_language.add(PatternMining::RE10,"re10");
_language.add(PatternMining::RE14,"re14");
_language.add(PatternMining::RE2,"re2");
add(_sequences); add(_file); add(_format); add(_support);
add(_min_length); add(_required); add(_language); add(_motif);
}

/// Validate external input before constructing a space
void read(void) {
if (_min_length.value() < 1 || _min_length.value() > Int::Limits::max)
throw std::invalid_argument("Minimum length must be a positive Gecode integer");
PatternMining::Sequences sequences;
const std::string filename(_file.value());
if (filename.empty()) {
if (_format.value() != PatternMining::LETTERS)
throw std::invalid_argument("Integer and SPMF formats require -file");
const std::string text(_sequences.value());
if (text.empty() || text.back() == ',')
throw std::invalid_argument("Expected comma-separated nonempty A..Z sequences");
std::istringstream stream(text);
std::string sequence;
while (std::getline(stream,sequence,','))
sequences.push_back(PatternMining::read_sequence(sequence,PatternMining::LETTERS));
} else {
std::ifstream stream(filename);
sequences = PatternMining::read_database(stream,
static_cast<PatternMining::Format>(_format.value()));
}
input.reset(new PatternMining::Database(sequences));
threshold = PatternMining::minimum_support(_support.value(),input->ends.size());
const std::string items(_required.value());
if (!items.empty()) {
if (items.back() == ',')
throw std::invalid_argument("Empty required item");
std::istringstream stream(items);
std::string item;
while (std::getline(stream,item,',')) {
const std::vector<int> parsed = PatternMining::read_sequence(item,
letters() ? PatternMining::LETTERS : PatternMining::INTEGERS);
if (parsed.size() != 1)
throw std::invalid_argument("Required items must be single letters or IDs");
required_items.push_back(parsed[0]);
}
}
}

const PatternMining::Database& database(void) const { return *input; }
const std::vector<int>& required(void) const { return required_items; }
int support(void) const { return threshold; }
int min_length(void) const { return static_cast<int>(_min_length.value()); }
bool letters(void) const { return _format.value() == PatternMining::LETTERS; }
PatternMining::Language language(void) const {
if (_language.value() == PatternMining::DEFAULT)
return _motif.value() ? PatternMining::MOTIF : PatternMining::NONE;
return static_cast<PatternMining::Language>(_language.value());
}
};

/**
* \brief %Example: constrained frequent subsequences of unknown length
*
* A pattern must occur in at least -support percent of the input sequences.
* Matching preserves order and may skip items; repeated items match distinct
* positions. Support counts records, including duplicate records, once each.
* By default the inputs ABCBC, BABC, ABDC must all support the pattern, which
* must start with A and end with C. AC and ABC are feasible; ABC is longest.
*
* The decision is an ordered list of items with unknown length. The frequency
* constraint requires sufficiently many records to contain that list as a
* subsequence. Ordinary length and regular constraints restrict the pattern:
* they do not restrict the matching positions in the input records. Default
* DFS enumerates every qualifying pattern; -search bab finds a longest one.
* These are different queries from closed, maximal, or top-k frequent mining.
*
* An OpenIntVarList constructs pattern positions as needed, without an end
* marker or unused suffix variables. Pattern languages therefore describe
* just the pattern, without padding transitions. The private frequency
* constraint maintains supporting suffixes after the assigned prefix and
* removes items with insufficient support. This prefix projection follows
* Kemmar et al., "PREFIX-PROJECTION Global Constraint for Sequential Pattern
* Mining", CP 2015, doi:10.1007/978-3-319-23219-5_17, with an additional
* remaining-suffix length bound. Projection is a filtering method, independent
* of the pattern's length, item and language restrictions. OpenRoute is the
* simpler introduction to open lists.
*
* The paper's Table 1 can be mined with:
* -sequences ABCBC,BABC,AB,BCD -support 50 -language none.
* -min-length and -required constrain length and item membership. -language
* also accepts motif (A, any items, C), re10, re14, re2 (comparison presets
* from the paper). Their letters mean item IDs A=1 through Z=26; integer data
* must use the corresponding mapping for these named expressions.
*
* -file reads one sequence per line in -format letters, integers, or spmf.
* Integer IDs are positive and preserved in output. SPMF records must have
* singleton itemsets: "1 -1 2 -1 3 -1 -2" is the sequence ABC. Multi-item
* itemsets are rejected because they define a different mining problem.
* No gap or time restrictions are supported. The comparison runner in
* misc/common-pattern/README.md uses identical mining queries across models.
*
* \ingroup Example
*/
class CommonPattern : public IntMaximizeScript {
protected:
OpenIntVarList pattern;
IntVar frequency;
PatternMining::Database database;
bool letters;
public:
enum { SEARCH_BAB, SEARCH_DFS };

CommonPattern(const CommonPatternOptions& opt)
: IntMaximizeScript(opt), database(opt.database()), letters(opt.letters()) {
pattern = OpenIntVarList(*this,database.domain(),database.max_length());
rel(*this,pattern.length(),IRT_GQ,opt.min_length());
frequency = PatternMining::frequent(*this,pattern,database,opt.support());
if (opt.language() != PatternMining::NONE)
extensional(*this,pattern,PatternMining::language(opt.language(),database));
if (!opt.required().empty()) {
REG alphabet(IntArgs(database.alphabet));
for (int item : opt.required())
extensional(*this,pattern,*alphabet + REG(item) + *alphabet);
}
branch(*this,pattern,INT_VAR_NONE(),INT_VAL_MIN());
}

virtual IntVar cost(void) const { return pattern.length(); }

CommonPattern(CommonPattern& s)
: IntMaximizeScript(s), database(s.database), letters(s.letters) {
pattern.update(*this,s.pattern);
frequency.update(*this,s.frequency);
}

virtual Space* copy(void) { return new CommonPattern(*this); }

virtual void print(std::ostream& os) const {
os << "\t";
for (int i=0; i<pattern.known_length(); i++) {
if (i && !letters)
os << ' ';
if (pattern[i].assigned()) {
const int item = pattern[i].val();
if (letters)
os << static_cast<char>('A'+item-1);
else
os << item;
} else {
os << pattern[i];
}
}
os << " (length " << pattern.length()
<< ", support " << frequency << '/' << database.ends.size()
<< ")" << std::endl;
}
};

/** \brief Main-function
* \relates CommonPattern
*/
int
main(int argc, char* argv[]) {
CommonPatternOptions opt;
opt.solutions(0);
opt.search(CommonPattern::SEARCH_DFS);
opt.search(CommonPattern::SEARCH_BAB,"bab","find a longest pattern");
opt.search(CommonPattern::SEARCH_DFS,"dfs","enumerate frequent patterns");
opt.parse(argc,argv);
try {
opt.read();
} catch (const std::invalid_argument& error) {
std::cerr << error.what() << std::endl;
return 1;
}
if (opt.search() == CommonPattern::SEARCH_DFS)
IntMaximizeScript::run<CommonPattern,DFS,CommonPatternOptions>(opt);
else
IntMaximizeScript::run<CommonPattern,BAB,CommonPatternOptions>(opt);
return 0;
}

// STATISTICS: example-any
Loading
Loading