Conflicts:
	configure
This commit is contained in:
Vitor Santos Costa 2011-08-09 08:12:43 -03:00
commit 0ed341ed83
27 changed files with 6833 additions and 446 deletions

View File

@ -677,6 +677,7 @@ mycb: $(srcdir)/mycb.c
$(CC) $(CFLAGS) $(srcdir)/mycb.c -o mycb
all: startup.yss
@ENABLE_GECODE@ @INSTALL_DLLS@ (cd library/gecode; $(MAKE))
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE))
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE))
@INSTALL_DLLS@ (cd library/matrix; $(MAKE))
@ -749,6 +750,7 @@ install_unix: startup.yss libYap.a
@INSTALL_DLLS@ (cd library/rltree; $(MAKE) install)
@INSTALL_DLLS@ (cd library/system; $(MAKE) install)
@INSTALL_DLLS@ (cd library/tries; $(MAKE) install)
@ENABLE_GECODE@ @INSTALL_DLLS@ (cd library/gecode; $(MAKE) install)
@ENABLE_CLIB@ @INSTALL_DLLS@ (cd packages/clib; $(MAKE) install)
@ENABLE_HTTP@ @INSTALL_DLLS@ (cd packages/http; $(MAKE) install)
@ENABLE_PLDOC@ @INSTALL_DLLS@ (cd packages/pldoc; $(MAKE) install)
@ -856,6 +858,7 @@ depend: $(HEADERS) $(C_SOURCES)
clean: clean_docs
rm -f *.o *~ *.BAK *.a
@ENABLE_GECODE@ @INSTALL_DLLS@ (cd library/gecode; $(MAKE) clean)
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE) clean)
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE) clean)
@INSTALL_DLLS@ (cd library/matrix; $(MAKE) clean)

1359
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -56,6 +56,31 @@ AC_SUBST(GCC)
AC_SUBST(C_INTERF_FLAGS)
AC_SUBST(C_PARSER_FLAGS)
dnl Gecode support
AC_CHECK_HEADER(gecode/support/config.hpp,
have_gecode=yes, have_gecode=no)
use_gecode_default=no
AC_SUBST(PYTHON)
if test "$have_gecode" = yes; then
AC_CHECK_PROGS(PYTHON, [python2.78 python], [none])
if test "$PYTHON" != none; then
use_gecode_default=yes
fi
else
PYTHON=none
fi
AC_ARG_ENABLE(gecode,
[ --enable-gecode install gecode library],
[use_gecode="$enableval"
if test "$use_gecode" = yes; then
if test "$have_gecode" = no; then
AC_MSG_ERROR([cannot enable gecode: gecode library not found])
fi
if test "$PYTHON" = none; then
AC_MSG_ERROR([cannot enable gecode: python not found])
fi
fi], use_gecode=$use_gecode_default)
AC_ARG_ENABLE(tabling,
[ --enable-tabling support tabling ],
tabling="$enableval", tabling=no)
@ -747,6 +772,13 @@ fi
CMFLAGS=-fpic
CIFLAGS=-I.
if test "$use_gecode" = no; then
ENABLE_GECODE="@# "
else
ENABLE_GECODE=""
fi
AC_SUBST(ENABLE_GECODE)
if test "$use_chr" = no; then
ENABLE_CHR="@# "
elif test -e "$srcdir"/packages/chr/Makefile.in; then
@ -2225,5 +2257,9 @@ if test "$ENABLE_CLPBN_BP" = ""; then
AC_CONFIG_FILES([packages/CLPBN/clpbn/bp/Makefile])
fi
if test "$ENABLE_GECODE" = ""; then
AC_CONFIG_FILES([library/gecode/Makefile])
fi
AC_OUTPUT()

167
library/gecode/DOC.txt Normal file
View File

@ -0,0 +1,167 @@
USING THE GECODE MODULE
=======================
:- use_module(gecode).
or
:- use_module(library(gecode)).
if it is installed as a library module
CREATING A SPACE
================
Space := space
CREATING VARIABLES
==================
Unlike in Gecode, variable objects are not bound to a specific Space. Each one
actually contains an index with which it is possible to access a Space-bound
Gecode variable. Variables can be created using the following expressions:
IVar := intvar(Space,SPEC...)
BVar := boolvar(Space)
SVar := setvar(Space,SPEC...)
where SPEC... is the same as in Gecode. For creating lists of variables use
the following variants:
IVars := intvars(Space,N,SPEC...)
BVars := boolvars(Space,N,SPEC...)
SVars := setvars(Space,N,SPEC...)
where N is the number of variables to create (just like for XXXVarArray in
Gecode). Sometimes an IntSet is necessary:
ISet := intset([SPEC...])
where each SPEC is either an integer or a pair (I,J) of integers. An IntSet
describes a set of ints by providing either intervals, or integers (which stand
for an interval of themselves). It might be tempting to simply represent an
IntSet as a list of specs, but this would be ambiguous with IntArgs which,
here, are represented as lists of ints.
CONSTRAINTS AND BRANCHINGS
==========================
all constraint and branching posting functions are available just like in
Gecode. Wherever a XXXArgs or YYYSharedArray is expected, simply use a list.
At present, there is no support for minimodel-like constraint posting.
Constraints and branchings are added to a space using:
Space += CONSTRAINT
Space += BRANCHING
For example:
Space += rel(X,'IRT_EQ',Y)
arrays of variables are represented by lists of variables, and constants are
represented by atoms with the same name as the Gecode constant
(e.g. 'INT_VAR_SIZE_MIN').
SEARCHING FOR SOLUTIONS
=======================
SolSpace := search(Space)
This is a backtrackable predicate that enumerates all solution spaces
(SolSpace).
EXTRACTING INFO FROM A SOLUTION
===============================
An advantage of non Space-bound variables, is that you can use them both to
post constraints in the original space AND to consult their values in
solutions. Below are methods for looking up information about variables. Each
of these methods can either take a variable as argument, or a list of
variables, and returns resp. either a value, or a list of values:
Val := assigned(Space,X)
Val := min(Space,X)
Val := max(Space,X)
Val := med(Space,X)
Val := val(Space,X)
Val := size(Space,X)
Val := width(Space,X)
Val := regret_min(Space,X)
Val := regret_max(Space,X)
Val := glbSize(Space,V)
Val := lubSize(Space,V)
Val := unknownSize(Space,V)
Val := cardMin(Space,V)
Val := cardMax(Space,V)
Val := lubMin(Space,V)
Val := lubMax(Space,V)
Val := glbMin(Space,V)
Val := glbMax(Space,V)
Val := glb_ranges(Space,V)
Val := lub_ranges(Space,V)
Val := unknown_ranges(Space,V)
Val := glb_values(Space,V)
Val := lub_values(Space,V)
Val := unknown_values(Space,V)
DISJUNCTORS
===========
Disjunctors provide support for disjunctions of clauses, where each clause is a
conjunction of constraints:
C1 or C2 or ... or Cn
Each clause is executed "speculatively": this means it does not affect the main
space. When a clause becomes failed, it is discarded. When only one clause
remains, it is committed: this means that it now affects the main space.
Example:
Consider the problem where either X=Y=0 or X=Y+(1 or 2) for variable X and Y
that take values in 0..3.
Space := space,
[X,Y] := intvars(Space,2,0,3),
First, we must create a disjunctor as a manager for our 2 clauses:
Disj := disjunctor(Space),
We can now create our first clause:
C1 := clause(Disj),
This clause wants to constrain X and Y to 0. However, since it must be
executed "speculatively", it must operate on new variables X1 and Y1 that
shadow X and Y:
[X1,Y1] := intvars(C1,2,0,3),
C1 += forward([X,Y],[X1,Y1]),
The forward(...) stipulation indicates which global variable is shadowed by
which clause-local variable. Now we can post the speculative clause-local
constraints for X=Y=0:
C1 += rel(X1,'IRT_EQ',0),
C1 += rel(Y1,'IRT_EQ',0),
We now create the second clause which uses X2 and Y2 to shadow X and Y:
C2 := clause(Disj),
[X2,Y2] := intvars(C2,2,0,3),
C2 += forward([X,Y],[X2,Y2]),
However, this clause also needs a clause-local variable Z2 taking values 1 or
2 in order to post the clause-local constraint X2=Y2+Z2:
Z2 := intvar(C2,1,2),
C2 += linear([-1,1,1],[X2,Y2,Z2],'IRT_EQ',0),
Finally, we can branch and search:
Space += branch([X,Y],'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
SolSpace := search(Space),
and lookup values of variables in each solution:
[X_,Y_] := val(SolSpace,[X,Y]).

View File

@ -0,0 +1,90 @@
#
# default base directory for YAP installation
# (EROOT for architecture-dependent files)
#
prefix = @prefix@
exec_prefix = @exec_prefix@
ROOTDIR = $(prefix)
EROOTDIR = @exec_prefix@
abs_top_builddir = @abs_top_builddir@
#
# where the binary should be
#
BINDIR = $(EROOTDIR)/bin
#
# where YAP should look for libraries
#
LIBDIR=@libdir@
YAPLIBDIR=@libdir@/Yap
#
# where YAP should look for architecture-independent Prolog libraries
#
SHAREDIR=$(ROOTDIR)/share
#
#
CXX=@CXX@
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include $(CPPFLAGS)
CXXFLAGS= @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include $(CPPFLAGS)
#
#
# You shouldn't need to change what follows.
#
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
SHELL=/bin/sh
RANLIB=@RANLIB@
srcdir=@srcdir@
SO=@SO@
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
CWD=$(PWD)
#
OBJS=gecode_yap.o
SOBJS=gecode_yap.@SO@
CODEGEN=$(srcdir)/code-generator.py
DISJUNCTOR = -DDISJUNCTOR
PYTHON = @PYTHON@
export PYTHONPATH:=$(srcdir):$(PYTHONPATH)
all: $(SOBJS) gecode.yap
gecode_yap.o: \
$(srcdir)/gecode_yap.cc \
$(srcdir)/gecode-common.icc \
gecode_yap_cc_impl_auto_generated.icc \
gecode_yap_cc_init_auto_generated.icc \
gecode_yap_cc_forward_auto_generated.icc \
$(srcdir)/disjunctor.icc \
$(srcdir)/disjunctor.hh
$(CXX) -c $(CXXFLAGS) $(DISJUNCTOR) -o $@ $<
@DO_SECOND_LD@gecode_yap.@SO@: gecode_yap.o
@DO_SECOND_LD@ @SHLIB_LD@ -o gecode_yap.@SO@ gecode_yap.o $(LDFLAGS) -lgecodeint -lgecodeset -lgecodesearch @EXTRA_LIBS_FOR_DLLS@
gecode_yap_cc_init_auto_generated.icc: $(CODEGEN)
$(PYTHON) $< -t yap-cc-init -s $(srcdir) > $@
gecode_yap_cc_impl_auto_generated.icc: $(CODEGEN)
$(PYTHON) $< -t yap-cc-impl -s $(srcdir) > $@
gecode_yap_cc_forward_auto_generated.icc: $(CODEGEN)
$(PYTHON) $< -t yap-cc-forward -s $(srcdir) > $@
gecode_yap_auto_generated.yap: $(CODEGEN)
$(PYTHON) $< -t yap-prolog -s $(srcdir) > $@
gecode.yap: $(srcdir)/gecode_yap_hand_written.yap gecode_yap_auto_generated.yap
cat $^ > $@
.PHONY: all clean install
clean:
-rm -f *.o *.so *~ *_auto_generated* gecode.yap *.pyc
install: all
mkdir -p $(DESTDIR)$(YAPLIBDIR)
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR)
$(INSTALL) gecode.yap $(DESTDIR)$(SHAREDIR)/Yap

View File

@ -0,0 +1,34 @@
CODEGEN=code-generator.py
DISJUNCTOR = -DDISJUNCTOR
yap: gecode_yap.so gecode.yap
gecode_yap.o: gecode_yap.cc gecode-common.icc \
gecode_yap_cc_impl_auto_generated.icc \
gecode_yap_cc_init_auto_generated.icc \
gecode_yap_cc_forward_auto_generated.icc \
disjunctor.icc disjunctor.hh
$(CXX) -Wall -ggdb -c -shared -fPIC $(DISJUNCTOR) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $<
gecode_yap.so: gecode_yap.o
$(CXX) -shared $(LDFLAGS) -o $@ $< -lgecodeint -lgecodeset -lgecodesearch
gecode_yap_cc_init_auto_generated.icc: $(CODEGEN)
python $< -t yap-cc-init > $@
gecode_yap_cc_impl_auto_generated.icc: $(CODEGEN)
python $< -t yap-cc-impl > $@
gecode_yap_cc_forward_auto_generated.icc: $(CODEGEN)
python $< -t yap-cc-forward > $@
gecode_yap_auto_generated.yap: $(CODEGEN)
python $< -t yap-prolog > $@
gecode.yap: gecode_yap_hand_written.yap gecode_yap_auto_generated.yap
cat $^ > $@
.PHONY: yap
clean:
-rm -f *.o *.so *~ *_auto_generated* gecode.yap

View File

@ -0,0 +1,708 @@
# -*- python -*-
#==============================================================================
# Copyright (C) 2011 by Denys Duchier
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http:##www.gnu.org/licenses/>.
#==============================================================================
import re
NOTICE_CC = """// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
"""
NOTICE_PROLOG="""%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
"""
def prolog_print_notice():
print NOTICE_PROLOG
def cc_print_notice():
print NOTICE_CC
class Type(object):
DEFAULT = re.compile("""^(.+)=(.+)$""")
CONST = re.compile("""^const\\b(.+)$""")
UNSIGNED = re.compile("""^unsigned\\b(.+)$""")
REFERENCE = re.compile("""^(.+)&$""")
def __init__(self, text):
if isinstance(text, Type):
self.clone_from(text)
return
text = text.strip()
m = self.DEFAULT.match(text)
if m:
self.default = m.group(2).strip()
text = m.group(1).strip()
else:
self.default = None
m = self.CONST.match(text)
if m:
self.const = True
text = m.group(1).strip()
else:
self.const = False
m = self.UNSIGNED.match(text)
if m:
self.unsigned = True
text = m.group(1).strip()
else:
self.unsigned = False
m = self.REFERENCE.match(text)
if m:
self.reference = True
text = m.group(1).strip()
else:
self.reference = False
self.type = text
def __str__(self):
l = []
if self.const: l.append("const ")
if self.unsigned: l.append("unsigned ")
l.append(self.type)
if self.reference: l.append("&")
if self.default is not None:
l.append("=")
l.append(self.default)
return ''.join(l)
def clone_from(self, other):
self.const = other.const
self.unsigned = other.unsigned
self.type = other.type
self.reference = other.reference
self.default = other.default
def clone(self):
return type(self)(self)
class Constraint(object):
DECL = re.compile("""^([^(]+)\\b(\w+)\((.*)\);$""")
ARG = re.compile("""((?:[^,<(]|<[^>]*>|\([^)]*\))+),?""")
def __init__(self, line):
if isinstance(line, Constraint):
self.clone_from(line)
return
line = line.strip()
m = self.DECL.match(line)
self.rettype = Type(m.group(1).strip())
self.name = m.group(2)
argtypes = []
for x in self.ARG.finditer(m.group(3).strip()):
argtypes.append(Type(x.group(1)))
self.argtypes = tuple(argtypes)
self.api = None
def __str__(self):
l = []
l.append(str(self.rettype))
l.append(" ")
l.append(self.name)
sep = "("
for x in self.argtypes:
l.append(sep)
sep = ", "
l.append(str(x))
l.append(")")
if self.api is not None:
l.append(" -> ")
l.append(self.api)
l.append(";")
return ''.join(l)
def clone_from(self, other):
self.rettype = other.rettype.clone()
self.name = other.name
self.argtypes = tuple(t.clone() for t in other.argtypes)
def clone(self):
return type(self)(self)
COMMENT = re.compile("""^\\s*//.*$""")
def load_decls(filename):
decls = []
for line in open(filename):
line = line.strip()
if not line: continue
m = COMMENT.match(line)
if m: continue
decls.append(Constraint(line))
return decls
class DeclsLoader(object):
def __init__(self, filename):
self.decls = load_decls(filename)
def print_decls(self):
for con in self.decls:
print str(con)
class PredGenerator(DeclsLoader):
OMIT = ("DFA", # NOT YET SUPPORTED!!!
"TupleSet", # NOT YET SUPPORTED!!!
"VarBranchOptions",
"ValBranchOptions",
"TieBreakVarBranch<IntVarBranch>",
"TieBreakVarBranchOptions",
"TieBreakVarBranch<SetVarBranch>")
def __init__(self, filename):
super(PredGenerator, self).__init__(filename)
self._change_home_to_space()
self._change_intsharedarray_to_intargs()
self._generate()
self._number()
def _change_home_to_space(self):
for p in self.decls:
for t in p.argtypes:
if t.type=="Home":
t.type="Space"
def _change_intsharedarray_to_intargs(self):
for p in self.decls:
for t in p.argtypes:
if t.type=="IntSharedArray":
t.type="IntArgs"
def _generate(self):
# drop the constraints and optional arguments we can't handle
preds = []
for con in self.decls:
if self._con_ok(con):
con = con.clone()
con.argtypes = tuple(self._drop_deco(t) for t in con.argtypes
if t.type not in self.OMIT)
preds.append(con)
# for each pred that has an argument with a default produce
# 2 preds (1 without, 1 with). repeat until all defaults have
# been removed.
again = True
while again:
preds_ = []
again = False
for con in preds:
i = self._defaulted(con.argtypes)
if i is None:
preds_.append(con)
else:
again = True
before = con.argtypes[:i]
# without the default argument
# and therefore without the args that follow
con1 = con.clone()
con1.argtypes = before
preds_.append(con1)
# with the default argument (not default anymore)
con2 = con.clone()
arg = con.argtypes[i].clone()
arg.default=None
after = con.argtypes[i+1:]
con2.argtypes = before + (arg,) + after
preds_.append(con2)
preds = preds_
self.preds = preds
def _con_ok(self, con):
for t in con.argtypes:
if (t.type in self.OMIT) and (t.default is None):
return False
return True
def _drop_deco(self, t):
# drop const, ref, and unsigned indications
t.const = False
t.reference = False
t.unsigned = False
return t
def _defaulted(self, argtypes):
i = 0
for x in argtypes:
if x.default is not None:
return i
i += 1
return None
def _number(self):
i = 1
for x in self.preds:
x.api = "%s_%d" % (x.name,i)
i += 1
def print_preds(self):
for p in self.preds:
print str(p)
class Cluster(object):
def __init__(self, name, arity):
self.name = name
self.arity = arity
self.preds = []
# discriminating tree based on argument types
class DTree(object):
def __init__(self, i, preds):
self.index = i
if len(preds) == 1 and len(preds[0].argtypes) == i:
self.is_leaf = True
self.pred = preds[0]
return
self.is_leaf = False
# i is the index of the current arg
# preds are the predicates to be indexed under this tree node
dispatch = {}
for p in preds:
t = p.argtypes[i]
d = dispatch.get(t.type, None)
if d is None:
d = []
dispatch[t.type] = d
d.append(p)
self.subtrees = tuple((t2,DTree(i+1,p2))
for t2,p2 in dispatch.iteritems())
def _generate_body(self, user_vars, lib_vars):
if self.is_leaf:
return PrologLiteral("gecode_constraint_%s(%s)" % (self.pred.api, ",".join(lib_vars)))
X = user_vars[self.index]
Y = lib_vars[self.index]
return self._generate_dispatch(0, user_vars, lib_vars)
def _generate_dispatch(self, i, user_vars, lib_vars):
if i == len(self.subtrees):
return PrologLiteral("throw(gecode_argument_error)")
typ, dtree = self.subtrees[i]
idx = self.index
X = user_vars[idx]
Y = lib_vars[idx]
# hack for disjunctor support
if typ=="Space":
typ = "Space_or_Clause"
return PrologIF(
PrologLiteral("is_%s(%s,%s)" % (typ,X,Y)),
dtree._generate_body(user_vars, lib_vars),
self._generate_dispatch(i+1, user_vars, lib_vars))
def _cc_descriptors(self, name, argtypes):
if self.is_leaf:
return (CCDescriptor(name, argtypes, self.pred.api),)
descriptors = []
for typ,dtree in self.subtrees:
descriptors.extend(dtree._cc_descriptors(name,(argtypes+(typ,))))
return descriptors
class YAPConstraintGeneratorBase(PredGenerator):
def __init__(self, filename):
super(YAPConstraintGeneratorBase, self).__init__(filename)
self._classify()
self._dtreefy()
# create clusters (predicate,arity)
def _classify(self):
clusters = {}
for pred in self.preds:
name = pred.name
arity = len(pred.argtypes)
key = (name,arity)
cluster = clusters.get(key, None)
if cluster is None:
cluster = Cluster(name, arity)
clusters[key] = cluster
cluster.preds.append(pred)
self.clusters = clusters
# for each cluster, create a dtree
def _dtreefy(self):
dtrees = {}
for key, cluster in self.clusters.iteritems():
dtree = DTree(0, cluster.preds)
dtrees[key] = dtree
self.dtrees = dtrees
def _user_vars(self, arity):
return tuple(("X%d" % i) for i in range(arity))
def _lib_vars(self, arity):
return tuple(("Y%d" % i) for i in range(arity))
class YAPConstraintPrologGenerator(YAPConstraintGeneratorBase):
def __init__(self, filename):
super(YAPConstraintPrologGenerator, self).__init__(filename)
def _prolog_clauses(self):
clauses = []
for (name, arity), dtree in self.dtrees.iteritems():
user_vars = self._user_vars(arity)
lib_vars = self._lib_vars(arity)
head = "%s(%s)" % (name, ",".join(user_vars))
body = dtree._generate_body(user_vars, lib_vars)
clause = PrologClause(head, body)
clauses.append(clause)
return clauses
def generate(self):
out = OStream(sys.stdout)
for clause in self._prolog_clauses():
clause.pp(out, 0)
class YAPConstraintCCGenerator(YAPConstraintGeneratorBase):
def __init__(self, filename):
super(YAPConstraintCCGenerator, self).__init__(filename)
def _cc_descriptors(self):
descriptors = []
for (name, arity), dtree in self.dtrees.iteritems():
descriptors.extend(dtree._cc_descriptors(name,()))
return descriptors
def generate_impl(self):
for d in self._cc_descriptors():
d.generate_impl()
def generate_init(self):
for d in self._cc_descriptors():
d.generate_init()
# output stream that keeps track of the current column
# to facilitate proper indentation
import sys
class OStream(object):
def __init__(self, fd=sys.stdout):
self.file = fd
self.column = 0
def write(self, s):
reset = False
for x in s.split('\n'):
if reset:
self.newline()
else:
reset = True
self.file.write(x)
self.column += len(x)
def newline(self):
self.file.write("\n")
self.column = 0
def writeln(self, s=None):
if s is not None:
self.write(s)
self.newline()
def indent_to(self, n):
if n<self.column:
self.newline()
n = n - self.column
while n>0:
self.write(' ')
n -= 1
# representation of prolog code that automatically supports proper indentation
class PrologObject(object):
pass
class PrologClause(PrologObject):
def __init__(self, head, body):
self.head = head
self.body = body
def pp(self, out, offset):
out.indent_to(offset)
out.write(self.head)
out.writeln(" :-")
self.body.pp(out, offset+8)
out.writeln(".")
out.writeln()
class PrologLiteral(PrologObject):
def __init__(self, lit):
self.literal = lit
def pp(self, out, offset):
out.indent_to(offset)
out.write(self.literal)
class PrologIF(PrologObject):
def __init__(self, cond, left, right):
self.cond = cond
self.left = left
self.right = right
def pp(self, out, offset):
out.indent_to(offset)
out.write("("),
indent = offset+1
self.cond.pp(out, indent)
out.writeln()
out.indent_to(indent)
out.write("-> ")
self.left.pp(out, indent+3)
out.writeln()
out.indent_to(indent)
out.write("; ")
self.right.pp(out, indent+3)
out.write(")")
ENUM_CLASSES = None
ENUM_CLASSES_AVOID = ('ScriptMode','ViewSelStatus','ExecStatus',
'ActorProperty','SpaceStatus')
def enum_classes():
global ENUM_CLASSES
filename = "gecode-enums-%s.py" % gecode_version()
if SRCDIR is not None:
import os.path
filename = os.path.join(SRCDIR,filename)
if ENUM_CLASSES is None:
import imp
ENUM_CLASSES = imp.load_source(
"gecode_enums",
filename).ENUM_CLASSES
ENUM_CLASSES = (x for x in ENUM_CLASSES if x.TYPE not in ENUM_CLASSES_AVOID)
return ENUM_CLASSES
class YAPEnumImpl(object):
def generate(self):
self._generate_atoms()
self._generate_from_term()
def _generate_atoms(self):
for x in self.ENUM:
print "static YAP_Term gecode_%s;" % x
print
def _generate_from_term(self):
print "static %s gecode_%s_from_term(YAP_Term X)" % (self.TYPE,self.TYPE)
print "{"
for x in self.ENUM:
print " if (X==gecode_%s) return %s;" % (x,x)
print ' cerr << "this should never happen" << endl; exit(1);'
print "}"
print
def _generate_from_term_forward_decl(self):
print "static %s gecode_%s_from_term(YAP_Term);" % (self.TYPE,self.TYPE)
class YAPEnumImplGenerator(object):
def generate(self):
for c in enum_classes():
class C(c,YAPEnumImpl): pass
o = C()
o.generate()
class YAPEnumForwardGenerator(object):
def generate(self):
for c in enum_classes():
class C(c,YAPEnumImpl): pass
o = C()
o._generate_from_term_forward_decl()
class YAPEnumInit(object):
def generate(self):
for x in self.ENUM:
print '{ YAP_Atom X= YAP_LookupAtom("%s");' % x
print ' gecode_%s = YAP_MkAtomTerm(X);' % x
print ' YAP_AtomGetHold(X); }'
print
class YAPEnumInitGenerator(object):
def generate(self):
for c in enum_classes():
class C(c,YAPEnumInit): pass
o = C()
o.generate()
class YAPEnumProlog(object):
def generate(self):
for x in self.ENUM:
print "is_%s_('%s')." % (self.TYPE, x)
print
for x in self.ENUM:
print "is_%s_('%s','%s')." % (self.TYPE, x, x)
print
print "is_%s(X,Y) :- nonvar(X), is_%s_(X,Y)." % (self.TYPE,self.TYPE)
print "is_%s(X) :- is_%s(X,_)." % (self.TYPE,self.TYPE)
print
class YAPEnumPrologGenerator(object):
def generate(self):
for c in enum_classes():
class C(c,YAPEnumProlog): pass
o = C()
o.generate()
class CCDescriptor(object):
def __init__(self, name, argtypes, api):
self.name = name
self.argtypes = argtypes
self.api = api
def generate_impl(self):
print "static int gecode_constraint_%s(void)" % self.api
print "{"
i = 1
args = []
for t in self.argtypes:
v = "X%d" % i
a = "YAP_ARG%d" % i
if t=="Space":
v = "*space"
print " GenericSpace* space = gecode_Space_from_term(%s);" % a
else:
extra = ""
if t in ("IntVar","BoolVar","SetVar","IntVarArgs","BoolVarArgs","SetVarArgs"):
extra = "space,"
print " %s %s = gecode_%s_from_term(%s%s);" % (t,v,t,extra,a)
args.append(v)
i += 1
print " %s(%s);" % (self.name, ",".join(args))
print " return TRUE;"
print "}"
print
def generate_init(self):
print 'YAP_UserCPredicate("gecode_constraint_%s", gecode_constraint_%s, %d);' \
% (self.api, self.api, len(self.argtypes))
GECODE_VERSION = None
def gecode_version():
global GECODE_VERSION
if GECODE_VERSION is not None:
return GECODE_VERSION
from distutils.ccompiler import new_compiler, customize_compiler
import os
cxx = new_compiler()
customize_compiler(cxx)
file_hh = "_gecode_version.hh"
file_txt = "_gecode_version.txt"
f = file(file_hh,"w")
f.write("""#include "gecode/support/config.hpp"
@@GECODE_VERSION""")
f.close()
cxx.preprocess(file_hh,output_file=file_txt)
f = open(file_txt)
version = ""
for line in f:
if line.startswith("@@"):
version = line[3:-2]
break
f.close()
os.remove(file_hh)
os.remove(file_txt)
GECODE_VERSION = version
return version
SRCDIR = None
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
description="code generator for gecode bindings")
parser.add_argument(
"-t", "--target", choices=("yap-prolog","yap-cc-impl","yap-cc-init",
"yap-cc-forward"),
default=None, metavar="TARGET", required=True,
help="type of code to generate")
parser.add_argument(
"-s", "--srcdir", metavar="DIR", default=None,
help="source directory")
args = parser.parse_args()
if args.srcdir is not None:
import os.path
SRCDIR = os.path.abspath(args.srcdir)
filename = "gecode-prototypes-%s.hh" % gecode_version()
if SRCDIR is not None:
filename = os.path.join(SRCDIR,filename)
if args.target == "yap-prolog":
prolog_print_notice()
YAPEnumPrologGenerator().generate()
YAPConstraintPrologGenerator(filename).generate()
elif args.target == "yap-cc-impl":
cc_print_notice()
YAPEnumImplGenerator().generate()
YAPConstraintCCGenerator(filename).generate_impl()
elif args.target == "yap-cc-init":
cc_print_notice()
YAPEnumInitGenerator().generate()
YAPConstraintCCGenerator(filename).generate_init()
elif args.target == "yap-cc-forward":
cc_print_notice()
YAPEnumForwardGenerator().generate()
else:
raise NotImplementedError("target not yet suported: %s" % args.target)

View File

@ -0,0 +1,156 @@
// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
#ifndef __GECODE_DISJUNCTOR_HH__
#define __GECODE_DISJUNCTOR_HH__
#include <gecode/kernel.hh>
#include <gecode/int.hh>
#include <gecode/set.hh>
namespace Gecode { namespace Disjunctor_ {
using namespace generic_gecode;
//=========================================================================
// from a user perspective, a Disjunctor corresponds to a set of
// speculative clauses:
//
// - when a non-committed clause fails, it is simply discarded
// - when a single clause remains, it is committed
//
// from an implementation perspective, a Disjunctor is an object shared by
// several clauses, that contains a counter keeping track of how many
// clauses remain. when the counter reaches 1, the remaining clause
// becomes committed.
//=========================================================================
// following the example in MPG
struct Disjunctor: public LocalHandle
{
Disjunctor();
Disjunctor(Space& home);
Disjunctor(const Disjunctor& d);
int get() const;
void incr();
void decr();
void dispose(Space& home);
};
//=========================================================================
// a Clause encapsulates the speculative execution of a set of propagators.
// Therefore, these propagators must be posted in a separate (sub)space.
// However they normally want to constrain variables of the original home
// space: for each such variable X, a variable Y local to the subspace must
// be created and used instead, and a forwarder must be created from X to
// Y. A Clause is then a Propagator that subscribes to the Xs. Whenever a
// X changes, the domains of the Xs are forwarded into the Ys and
// constraint propagation is run in the subspace. When a clause is
// committed, after propagation, the domains of Ys are forwarded back into
// the Xs.
//=========================================================================
// TODO: copy (difficulty is forwarder list)
class SubSpace;
class Clause: public Propagator {
Disjunctor disj;
SubSpace*const subhome;
public:
Clause(Space& home_, Disjunctor disj_);
Clause(Space& home, bool share, Clause& c);
virtual Propagator* copy(Space& home, bool share);
virtual size_t dispose(Space& home);
virtual PropCost cost(const Space&, const ModEventDelta&) const;
virtual ExecStatus propagate(Space& home, const ModEventDelta&);
// user API
operator GenericSpace&();
operator Space&();
operator Home();
GenericSpace* generic_space() const;
Space* space() const;
void forward(Space& home, IntVar outer, IntVar inner);
void forward(Space& home, BoolVar outer, BoolVar inner);
void forward(Space& home, SetVar outer, SetVar inner);
protected:
ExecStatus forward_in();
ExecStatus forward_out(Space& outer_home);
bool committed() const;
};
//=========================================================================
// a SubSpace is the Space associated with a Clause. It also contains the
// forwarder linked-list because we want it to manage the memory for that
// list.
//=========================================================================
class BasicForwarder;
using Int::IntView;
using Int::BoolView;
using Set::SetView;
class SubSpace: public GenericSpace
{
private:
Space* homeDuringCloning;
// linked-list of pairs of a variable in the parent space and a
// corresponding variable in the subspace
BasicForwarder* forwarder;
// auxiliary methods for adding an entry to the forwarder list
void forward(IntView outer, IntView inner);
void forward(BoolView outer, BoolView inner);
void forward(SetView outer, SetView inner);
// for forwarding domains into and out of the subhome
ExecStatus forward_in();
ExecStatus forward_out(Space&);
// for cancelling subscriptions
void cancel(Space& home, Clause&);
// allow Clause to use this private API
friend class Clause;
public:
SubSpace();
SubSpace(bool share, SubSpace& s);
virtual Space* copy(bool share);
SubSpace* copy(Space& home, bool share);
};
}}
namespace Gecode
{
using Disjunctor_::Disjunctor;
class Clause
{
generic_gecode::GenericSpace& _home;
Disjunctor_::Clause* _clause;
public:
Clause(generic_gecode::GenericSpace& home, Disjunctor disj);
operator generic_gecode::GenericSpace&();
operator Space&();
operator Home();
generic_gecode::GenericSpace* generic_space();
generic_gecode::GenericSpace* generic_parent();
Space* space();
void forward(IntVar outer, IntVar inner);
void forward(BoolVar outer, BoolVar inner);
void forward(SetVar outer, SetVar inner);
};
}
#endif

View File

@ -0,0 +1,380 @@
// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
#include "disjunctor.hh"
namespace Gecode { namespace Disjunctor_ {
//=========================================================================
// Disjunctor (following example in MPG)
//=========================================================================
struct DisjunctorObject: public LocalObject
{
int n;
DisjunctorObject(Space& home) : LocalObject(home), n(0) {}
DisjunctorObject(Space& home, bool share, DisjunctorObject& d)
: LocalObject(home, share, d), n(d.n) {}
virtual LocalObject* copy(Space& home, bool share)
{ return new (home) DisjunctorObject(home, share, *this); }
virtual size_t dispose(Space&) { return sizeof(*this); }
};
Disjunctor::Disjunctor(): LocalHandle() {}
Disjunctor::Disjunctor(Space& home)
: LocalHandle(new (home) DisjunctorObject(home)) {}
Disjunctor::Disjunctor(const Disjunctor& d): LocalHandle(d) {}
int Disjunctor::get() const { return static_cast<DisjunctorObject*>(object())->n; }
void Disjunctor::incr() { static_cast<DisjunctorObject*>(object())->n += 1; }
void Disjunctor::decr() { static_cast<DisjunctorObject*>(object())->n -= 1; }
void Disjunctor::dispose(Space& home)
{ static_cast<DisjunctorObject*>(object())->dispose(home); }
//=========================================================================
// Forwarder<View>
// used to forward the domain of a view V1 into a view V2 located in a
// subspace (the subspace of a speculative clause). V2 represents V1 in
// that space.
//
// BasicForwarder
// base class of all Forwarders. It declares the virtual functions
// that must be implemented to do the actual work, and contains the pointer
// implementing the singly-linked list of Forwarders associated with each
// clause. It also redefines new and delete to manage memory in the
// subspace.
//=========================================================================
struct BasicForwarder
{
BasicForwarder* next;
BasicForwarder() : next(NULL) {}
// forward V1's domain into V2. This is used each time the Clause (as a
// a propagator) is woken to perform propagation.
virtual ExecStatus forward_in(Space& inner_home) = 0;
// forward V2's domain into V1. This is used after propagation in the
// case where the Clause has been committed to (because it is the last
// one remaining).
virtual void forward_out(Space& outer_home) = 0;
// needed by delete to know how much to free
virtual size_t size() const = 0;
// usage: new (home) FRWRDR(...);
// to allocate the instance of FRWRDR on home's heap
static void* operator new(size_t n, Space& home)
{ return home.ralloc(n); }
// usage: delete (home) PTR;
// to free the instance pointed to by PTR from home's heap
static void operator delete(void* ptr, Space& home)
{ home.rfree(ptr, ((BasicForwarder*)ptr)->size()); }
virtual BasicForwarder*
copy(Space& outer_home, Space& inner_home, bool share) = 0;
virtual void cancel(Space& home, Clause&) = 0;
};
// Forwarder parametrized by View
template <typename View>
struct Forwarder: public BasicForwarder
{
View outer;
View inner;
Forwarder(View v1, View v2): outer(v1), inner(v2) {}
Forwarder() {}
virtual ExecStatus forward_in(Space& home);
virtual void forward_out(Space& home);
virtual size_t size() const { return sizeof(*this); }
virtual BasicForwarder* copy(Space& outer_home, Space& inner_home, bool share)
{
Forwarder<View>* fwd = new (inner_home) Forwarder<View>();
fwd->outer.update(outer_home, share, outer);
fwd->inner.update(inner_home, share, inner);
return fwd;
}
virtual void cancel(Space& home, Clause& c);
};
// instances of Forwarder that we actually use
typedef Forwarder<Int::IntView> IntForwarder;
typedef Forwarder<Int::BoolView> BoolForwarder;
typedef Forwarder<Set::SetView> SetForwarder;
//=========================================================================
// IntForwarder
//=========================================================================
template <>
ExecStatus IntForwarder::forward_in(Space& home) // inner home
{
Int::ViewRanges<Int::IntView> r(outer);
GECODE_ME_CHECK(inner.inter_r(home,r));
return ES_OK;
}
template <>
void IntForwarder::forward_out(Space& home) // outer home
{
// it is guaranteed by design that after successful propagation the
// domain of the inner variable is a non-empty narrowing of the domain of
// the outer variable. therefore, we can simply replace the domain of
// the outer variable with the domain of the inner variable.
Int::ViewRanges<Int::IntView> r(inner);
outer.narrow_r(home, r, false);
}
template <>
void IntForwarder::cancel(Space& home, Clause& c)
{ outer.cancel(home, c, Int::PC_INT_DOM); }
//=========================================================================
// BoolForwarder
//=========================================================================
template <>
ExecStatus BoolForwarder::forward_in(Space& home)
{
Int::ViewRanges<Int::BoolView> r(outer);
GECODE_ME_CHECK(inner.inter_r(home,r));
return ES_OK;
}
template <>
void BoolForwarder::forward_out(Space& home)
{
Int::ViewRanges<Int::BoolView> r(inner);
outer.narrow_r(home, r, false);
}
template <>
void BoolForwarder::cancel(Space& home, Clause& c)
{ outer.cancel(home, c, Int::PC_INT_DOM); }
//=========================================================================
// SetForwarder
//=========================================================================
template <>
ExecStatus SetForwarder::forward_in(Space& home)
{
Set::GlbRanges<SetView> gr(outer);
GECODE_ME_CHECK(inner.includeI(home,gr));
Set::LubRanges<SetView> lr(outer);
GECODE_ME_CHECK(inner.intersectI(home,lr));
GECODE_ME_CHECK(inner.cardMin(home, outer.cardMin()));
GECODE_ME_CHECK(inner.cardMax(home, outer.cardMax()));
return ES_OK;
}
template <>
void SetForwarder::forward_out(Space& home)
{
Set::GlbRanges<SetView> gr(inner);
outer.includeI(home, gr);
Set::LubRanges<SetView> lr(inner);
outer.intersectI(home, lr);
outer.cardMin(home, inner.cardMin());
outer.cardMax(home, inner.cardMax());
}
template <>
void SetForwarder::cancel(Space& home, Clause& c)
{ outer.cancel(home, c, Set::PC_SET_ANY); }
//=========================================================================
// SubSpace
//=========================================================================
void SubSpace::forward(IntView outer, IntView inner)
{
BasicForwarder* fwd = new (*this) IntForwarder(outer, inner);
fwd->next = forwarder;
forwarder = fwd;
}
void SubSpace::forward(BoolView outer, BoolView inner)
{
BasicForwarder* fwd = new (*this) BoolForwarder(outer, inner);
fwd->next = forwarder;
forwarder = fwd;
}
void SubSpace::forward(SetView outer, SetView inner)
{
BasicForwarder* fwd = new (*this) SetForwarder(outer, inner);
fwd->next = forwarder;
forwarder = fwd;
}
ExecStatus SubSpace::forward_in()
{
for (BasicForwarder* p=forwarder; p!=NULL; p=p->next)
GECODE_ES_CHECK(p->forward_in(*this));
return ES_OK;
}
ExecStatus SubSpace::forward_out(Space& home) // outer home
{
for (BasicForwarder* p=forwarder; p!=NULL; p=p->next)
p->forward_out(home);
return ES_OK;
}
SubSpace::SubSpace(): GenericSpace(), forwarder(NULL) {}
SubSpace::SubSpace(bool share, SubSpace& s)
: GenericSpace(share, s), forwarder(NULL)
{
BasicForwarder** prev = &forwarder;
for (BasicForwarder* p=s.forwarder; p!=NULL; p=p->next)
{
BasicForwarder* fwd = p->copy(*s.homeDuringCloning, *this, share);
*prev = fwd;
prev = &fwd->next;
}
}
Space* SubSpace::copy(bool share)
{ return new SubSpace(share,*this); }
SubSpace* SubSpace::copy(Space& home, bool share)
{ homeDuringCloning = &home; return static_cast<SubSpace*>(clone(share)); }
void SubSpace::cancel(Space& home, Clause& c)
{
for (BasicForwarder*p = forwarder; p!=NULL; p=p->next)
p->cancel(home, c);
}
//=========================================================================
// Clause
//=========================================================================
Clause::operator GenericSpace&() { return *subhome; }
Clause::operator Space&() { return *subhome; }
Clause::operator Home() { return *subhome; }
GenericSpace* Clause::generic_space() const { return subhome; }
Space* Clause::space() const { return subhome; }
Clause::Clause(Space& home_, Disjunctor disj_)
: Propagator(home_), disj(disj_), subhome(new SubSpace())
{
disj.incr();
}
Clause::Clause(Space& home, bool share, Clause& c)
: Propagator(home, share, c), subhome(c.subhome->copy(home, share))
{
disj.update(home, share, c.disj);
}
Propagator* Clause::copy(Space& home, bool share)
{ return new (home) Clause(home, share, *this); }
void Clause::forward(Space& home, IntVar outer, IntVar inner)
{
IntView oview(outer);
IntView iview(inner);
subhome->forward(oview, iview);
oview.subscribe(home, *this, Int::PC_INT_DOM);
}
void Clause::forward(Space& home, BoolVar outer, BoolVar inner)
{
BoolView oview(outer);
BoolView iview(inner);
subhome->forward(oview, iview);
oview.subscribe(home, *this, Int::PC_INT_DOM);
}
void Clause::forward(Space& home, SetVar outer, SetVar inner)
{
SetView oview(outer);
SetView iview(inner);
subhome->forward(oview, iview);
oview.subscribe(home, *this, Set::PC_SET_ANY);
}
ExecStatus Clause::forward_in()
{ return subhome->forward_in(); }
ExecStatus Clause::forward_out(Space& home) // outer home
{ return subhome->forward_out(home); }
inline bool Clause::committed() const { return disj.get() == 1; }
ExecStatus Clause::propagate(Space& home, const ModEventDelta&)
{
if (forward_in() == ES_FAILED ||
subhome->status() == SS_FAILED )
{
if (committed()) return ES_FAILED;
disj.decr();
return home.ES_SUBSUMED(*this);
}
if (committed()) forward_out(home);
// maybe do something clever about subsumption later
return ES_FIX;
}
size_t Clause::dispose(Space& home)
{
subhome->cancel(home, *this);
delete subhome;
// the memory for the disj's LocalObject is not recovered
(void) Propagator::dispose(home);
return sizeof(*this);
}
PropCost Clause::cost(const Space&, const ModEventDelta&) const
{
// consider a clause to be crazy expensive
return PropCost::crazy(PropCost::HI,10);
}
}
//===========================================================================
// Clause (user API)
//===========================================================================
Clause::Clause(generic_gecode::GenericSpace& home, Disjunctor disj)
: _home(home), _clause(new (home) Disjunctor_::Clause(home, disj)) {}
Clause::operator generic_gecode::GenericSpace&() { return *_clause; }
Clause::operator Space&() { return *_clause; }
Clause::operator Home() { return *_clause; }
generic_gecode::GenericSpace* Clause::generic_space() { return _clause->generic_space(); }
generic_gecode::GenericSpace* Clause::generic_parent() { return &_home; }
Space* Clause::space() { return _clause->space(); }
void Clause::forward(IntVar outer, IntVar inner)
{ _clause->forward(_home, outer, inner); }
void Clause::forward(BoolVar outer, BoolVar inner)
{ _clause->forward(_home, outer, inner); }
void Clause::forward(SetVar outer, SetVar inner)
{ _clause->forward(_home, outer, inner); }
}

View File

@ -0,0 +1,37 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- use_module(gecode).
disjunctor1(X_,Y_) :-
Space := space,
[X,Y] := intvars(Space,2,0,3),
D := disjunctor(Space),
C1 := clause(D),
[X1,Y1] := intvars(C1,2,0,3),
C1 += rel(X1,'IRT_EQ',1),
C1 += rel(Y1,'IRT_EQ',1),
C1 += forward([X,Y],[X1,Y1]),
C2 := clause(D),
[X2,Y2] := intvars(C2,2,0,3),
C2 += rel(X2,'IRT_EQ',2),
C2 += rel(Y2,'IRT_EQ',2),
C2 += forward([X,Y],[X2,Y2]),
Space += branch([X,Y],'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
SolSpace := search(Space),
[X_,Y_] := val(SolSpace,[X,Y]).

View File

@ -0,0 +1,37 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- use_module(gecode).
disjunctor2(X_,Y_) :-
Space := space,
[X,Y] := intvars(Space,2,0,3),
D := disjunctor(Space),
C1 := clause(D),
[X1,Y1] := intvars(C1,2,0,3),
C1 += forward([X,Y],[X1,Y1]),
C1 += rel(X1,'IRT_EQ',0),
C1 += rel(Y1,'IRT_EQ',0),
C2 := clause(D),
[X2,Y2] := intvars(C2,2,0,3),
C2 += forward([X,Y],[X2,Y2]),
Z2 := intvar(C2,1,2),
C2 += linear([-1,1,1],[X2,Y2,Z2],'IRT_EQ',0),
Space += branch([X,Y],'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
SolSpace := search(Space),
[X_,Y_] := val(SolSpace,[X,Y]).

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
GECODEDIR := $(shell g++ -q $(CPPFLAGS) $(CXXFLAGS) -H -E gecodedir.hh 2>&1 >/dev/null | grep gecode/kernel.hh | awk '{print $$2}' | sed 's|/kernel.hh||')
GECODECONFIG := $(GECODEDIR)/support/config.hpp
GECODEVERSION := $(shell cat $(GECODECONFIG) | egrep GECODE_VERSION | awk '{print $$3}' | sed 's/"//g')
PROTOTYPES = gecode-prototypes-$(GECODEVERSION).hh
ENUMS = gecode-enums-$(GECODEVERSION).py
all: $(PROTOTYPES) $(ENUMS)
$(PROTOTYPES): % : xml/namespaceGecode.xml extract-prototypes.xsl
cat notice.hh > $@
xsltproc extract-prototypes.xsl $< \
| sed 's/Gecode:://g' \
| sed 's/< /</g' \
| sed 's/ >/>/g' \
| sed 's/ \&/\&/g' \
| sed 's/, /,/g' \
| sed 's/forceinline //g' \
| sed 's/GECODE_INT_EXPORT //g' \
| sed 's/GECODE_SET_EXPORT //g' \
| grep -v '*' | sort >> $@
$(ENUMS): % : xml/namespaceGecode.xml extract-enums.xsl
cat notice.py > $@
xsltproc extract-enums.xsl $< >> $@
xml/namespaceGecode.xml: Doxyfile
doxygen Doxyfile
Doxyfile: Doxyfile.in
cat $< | sed "s#@GECODEDIR@#$(GECODEDIR)#" > $@
clean:
-rm -rf *~ gecode-prototypes-*.hh gecode-enums-*.py Doxyfile xml

View File

@ -0,0 +1,2 @@
This directory contains support code for automatically extracting
prototypes from the local Gecode installation.

View File

@ -0,0 +1,31 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" version="1.0"/>
<xsl:template match="/">
<xsl:text>ENUM_CLASSES = []
</xsl:text>
<xsl:for-each select="/doxygen/compounddef/sectiondef[@kind='enum']/memberdef">
<xsl:text>class </xsl:text>
<xsl:value-of select="name"/>
<xsl:text>(object):
</xsl:text>
<xsl:text> TYPE = '</xsl:text>
<xsl:value-of select="name"/>
<xsl:text>'
ENUM = [</xsl:text>
<xsl:for-each select="enumvalue">
<xsl:if test="position()!=1"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>'</xsl:text>
<xsl:value-of select="name"/>
<xsl:text>'</xsl:text>
</xsl:for-each>
<xsl:text>]
ENUM_CLASSES.append(</xsl:text>
<xsl:value-of select="name"/>
<xsl:text>)
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,21 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" version="1.0"/>
<xsl:template match="/">
<xsl:for-each select="/doxygen/compounddef/sectiondef[@kind='func']/memberdef[starts-with(@id,'group__TaskModel') and not(starts-with(name,'operator')) and name!='tiebreak' and name!='wait' and not(starts-with(@id,'group__TaskModelMiniModel'))]">
<xsl:value-of select="type"/>
<xsl:text> </xsl:text>
<xsl:value-of select="name"/>
<xsl:for-each select="param">
<xsl:if test="position()=1"><xsl:text>(</xsl:text></xsl:if>
<xsl:if test="position()!=1"><xsl:text>,</xsl:text></xsl:if>
<xsl:value-of select="type"/>
<xsl:for-each select="defval">
<xsl:text>=</xsl:text>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:for-each>
<xsl:text>);
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1 @@
#include "gecode/kernel.hh"

View File

@ -0,0 +1,3 @@
// This file was automatically extracted from Gecode source files.
// It is subject to the same Copyright as the source files from which
// it is derived, and is distributed under the same Licensing conditions.

View File

@ -0,0 +1,3 @@
# This file was automatically extracted from Gecode source files.
# It is subject to the same Copyright as the source files from which
# it is derived, and is distributed under the same Licensing conditions.

View File

@ -0,0 +1,259 @@
// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
#ifndef GECODE_COMMON
#define GECODE_COMMON
#include "gecode/int.hh"
#include "gecode/set.hh"
#include "gecode/search.hh"
#include <vector>
namespace generic_gecode
{
using namespace std;
using namespace Gecode;
// description of the optimization criterion
struct Optimizing
{
enum What { OPT_NONE, OPT_INT, OPT_RATIO };
enum How { OPT_MIN, OPT_MAX };
int num;
int den;
What what;
How how;
Optimizing(): num(-1), den(-1), what(OPT_NONE), how(OPT_MAX) {}
Optimizing(Optimizing& o)
: num(o.num), den(o.den), what(o.what), how(o.how) {}
void maximize(int i)
{ what = OPT_INT; how = OPT_MAX; num = i; };
void maximize(int i,int j)
{ what = OPT_RATIO; how = OPT_MAX; num = i; den = j; };
void minimize(int i)
{ what = OPT_INT; how = OPT_MIN; num = i; };
void minimize(int i,int j)
{ what = OPT_RATIO; how = OPT_MIN; num = i; den = j; };
};
struct GenericSpace;
struct GenericEngine
{
virtual GenericSpace* next(void)=0;
virtual ~GenericEngine() {};
};
struct GenericDFS: GenericEngine
{
DFS<GenericSpace> engine;
GenericDFS(GenericSpace* s) : engine(s) {}
virtual GenericSpace* next(void) { return engine.next(); }
};
struct GenericBAB: GenericEngine
{
BAB<GenericSpace> engine;
GenericBAB(GenericSpace* s) : engine(s) {}
virtual GenericSpace* next(void) { return engine.next(); }
};
struct GenericSpace: Space
{
Optimizing optim;
IntVarArray ivars;
BoolVarArray bvars;
SetVarArray svars;
vector<IntVar>* _ivars;
vector<BoolVar>* _bvars;
vector<SetVar>* _svars;
Space* space() { return this; }
GenericSpace(bool share, GenericSpace& s)
: Space(share, s), optim(s.optim),
_ivars(NULL), _bvars(NULL), _svars(NULL)
{
ivars.update(*this, share, s.ivars);
bvars.update(*this, share, s.bvars);
svars.update(*this, share, s.svars);
}
Space* copy(bool share)
{ freeze(); return new GenericSpace(share, *this); }
GenericSpace() : _ivars(NULL), _bvars(NULL), _svars(NULL) {}
// freeze the space before handing it off to a search engine
void freeze()
{
if (_ivars)
{
int n = _ivars->size();
ivars = IntVarArray(*this, n);
vector<IntVar>& v(*_ivars);
for (; n--;) ivars[n] = v[n];
delete _ivars;
_ivars = NULL;
}
if (_bvars)
{
int n = _bvars->size();
bvars = BoolVarArray(*this, n);
vector<BoolVar>& v(*_bvars);
for (; n--;) bvars[n] = v[n];
delete _bvars;
_bvars = NULL;
}
if (_svars)
{
int n = _svars->size();
svars = SetVarArray(*this, n);
vector<SetVar>& v(*_svars);
for (; n--;) svars[n] = v[n];
delete _svars;
_svars = NULL;
}
}
IntVar get_ivar(int i) const { return (_ivars) ? (*_ivars)[i] : ivars[i]; }
BoolVar get_bvar(int i) const { return (_bvars) ? (*_bvars)[i] : bvars[i]; }
SetVar get_svar(int i) const { return (_svars) ? (*_svars)[i] : svars[i]; }
GenericEngine* new_engine()
{
freeze();
return (optim.what == Optimizing::OPT_NONE)
? static_cast<GenericEngine*>(new GenericDFS(this))
: static_cast<GenericEngine*>(new GenericBAB(this));
}
int _new_ivar(IntVar& v)
{
if (!_ivars) _ivars = new vector<IntVar>;
int i = _ivars->size();
_ivars->push_back(v);
return i;
}
int new_ivar(int lo, int hi)
{
IntVar v(*this, lo, hi);
return _new_ivar(v);
}
int new_ivar(IntSet& s)
{
IntVar v(*this, s);
return _new_ivar(v);
}
int _new_bvar(BoolVar& v)
{
if (!_bvars) _bvars = new vector<BoolVar>;
int i = _bvars->size();
_bvars->push_back(v);
return i;
}
int new_bvar()
{
BoolVar v(*this, 0, 1);
return _new_bvar(v);
}
int _new_svar(SetVar& v)
{
if (!_svars) _svars = new vector<SetVar>;
int i = _svars->size();
_svars->push_back(v);
return i;
}
int new_svar(int glbMin, int glbMax, int lubMin, int lubMax,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glbMin, glbMax, lubMin, lubMax, cardMin, cardMax);
return _new_svar(v);
}
int new_svar(IntSet glb, int lubMin, int lubMax,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glb, lubMin, lubMax, cardMin, cardMax);
return _new_svar(v);
}
int new_svar(int glbMin, int glbMax, IntSet lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glbMin, glbMax, lub, cardMin, cardMax);
return _new_svar(v);
}
int new_svar(IntSet glb, IntSet lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glb, lub, cardMin, cardMax);
return _new_svar(v);
}
void minimize(int i) { optim.minimize(i); }
void minimize(int i, int j) { optim.minimize(i,j); }
void maximize(int i) { optim.maximize(i); }
void maximize(int i, int j) { optim.maximize(i,j); }
virtual void constrain(const Space& s)
{
const GenericSpace& sol = static_cast<const GenericSpace&>(s);
switch (optim.what)
{
case Optimizing::OPT_NONE:
break;
case Optimizing::OPT_INT:
rel(*this, ivars[optim.num],
((optim.how==Optimizing::OPT_MIN) ? IRT_LE : IRT_GR),
sol.ivars[optim.num].val());
break;
case Optimizing::OPT_RATIO:
{
IntArgs c(2, sol.ivars[optim.den].val(),
- sol.ivars[optim.num].val());
IntVarArgs v(2);
v[0] = ivars[optim.num];
v[1] = ivars[optim.den];
linear(*this, c, v,
((optim.how==Optimizing::OPT_MIN) ? IRT_LE : IRT_GR), 0);
break;
}
}
}
};
}
#ifdef DISJUNCTOR
#include "disjunctor.icc"
#endif
#endif

View File

@ -0,0 +1,113 @@
# This file was automatically extracted from Gecode source files.
# It is subject to the same Copyright as the source files from which
# it is derived, and is distributed under the same Licensing conditions.
ENUM_CLASSES = []
class ScriptMode(object):
TYPE = 'ScriptMode'
ENUM = ['SM_SOLUTION','SM_TIME','SM_STAT','SM_GIST']
ENUM_CLASSES.append(ScriptMode)
class IntRelType(object):
TYPE = 'IntRelType'
ENUM = ['IRT_EQ','IRT_NQ','IRT_LQ','IRT_LE','IRT_GQ','IRT_GR']
ENUM_CLASSES.append(IntRelType)
class BoolOpType(object):
TYPE = 'BoolOpType'
ENUM = ['BOT_AND','BOT_OR','BOT_IMP','BOT_EQV','BOT_XOR']
ENUM_CLASSES.append(BoolOpType)
class IntConLevel(object):
TYPE = 'IntConLevel'
ENUM = ['ICL_VAL','ICL_BND','ICL_DOM','ICL_DEF']
ENUM_CLASSES.append(IntConLevel)
class TaskType(object):
TYPE = 'TaskType'
ENUM = ['TT_FIXP','TT_FIXS','TT_FIXE']
ENUM_CLASSES.append(TaskType)
class ExtensionalPropKind(object):
TYPE = 'ExtensionalPropKind'
ENUM = ['EPK_DEF','EPK_SPEED','EPK_MEMORY']
ENUM_CLASSES.append(ExtensionalPropKind)
class IntVarBranch(object):
TYPE = 'IntVarBranch'
ENUM = ['INT_VAR_NONE','INT_VAR_RND','INT_VAR_DEGREE_MIN','INT_VAR_DEGREE_MAX','INT_VAR_AFC_MIN','INT_VAR_AFC_MAX','INT_VAR_MIN_MIN','INT_VAR_MIN_MAX','INT_VAR_MAX_MIN','INT_VAR_MAX_MAX','INT_VAR_SIZE_MIN','INT_VAR_SIZE_MAX','INT_VAR_SIZE_DEGREE_MIN','INT_VAR_SIZE_DEGREE_MAX','INT_VAR_SIZE_AFC_MIN','INT_VAR_SIZE_AFC_MAX','INT_VAR_REGRET_MIN_MIN','INT_VAR_REGRET_MIN_MAX','INT_VAR_REGRET_MAX_MIN','INT_VAR_REGRET_MAX_MAX']
ENUM_CLASSES.append(IntVarBranch)
class IntValBranch(object):
TYPE = 'IntValBranch'
ENUM = ['INT_VAL_MIN','INT_VAL_MED','INT_VAL_MAX','INT_VAL_RND','INT_VAL_SPLIT_MIN','INT_VAL_SPLIT_MAX','INT_VAL_RANGE_MIN','INT_VAL_RANGE_MAX','INT_VALUES_MIN','INT_VALUES_MAX']
ENUM_CLASSES.append(IntValBranch)
class IntAssign(object):
TYPE = 'IntAssign'
ENUM = ['INT_ASSIGN_MIN','INT_ASSIGN_MED','INT_ASSIGN_MAX','INT_ASSIGN_RND']
ENUM_CLASSES.append(IntAssign)
class ViewSelStatus(object):
TYPE = 'ViewSelStatus'
ENUM = ['VSS_BEST','VSS_BETTER','VSS_TIE','VSS_WORSE']
ENUM_CLASSES.append(ViewSelStatus)
class ExecStatus(object):
TYPE = 'ExecStatus'
ENUM = ['__ES_SUBSUMED','ES_FAILED','ES_NOFIX','ES_OK','ES_FIX','ES_NOFIX_FORCE','__ES_PARTIAL']
ENUM_CLASSES.append(ExecStatus)
class ActorProperty(object):
TYPE = 'ActorProperty'
ENUM = ['AP_DISPOSE','AP_WEAKLY']
ENUM_CLASSES.append(ActorProperty)
class SpaceStatus(object):
TYPE = 'SpaceStatus'
ENUM = ['SS_FAILED','SS_SOLVED','SS_BRANCH']
ENUM_CLASSES.append(SpaceStatus)
class SetRelType(object):
TYPE = 'SetRelType'
ENUM = ['SRT_EQ','SRT_NQ','SRT_SUB','SRT_SUP','SRT_DISJ','SRT_CMPL']
ENUM_CLASSES.append(SetRelType)
class SetOpType(object):
TYPE = 'SetOpType'
ENUM = ['SOT_UNION','SOT_DUNION','SOT_INTER','SOT_MINUS']
ENUM_CLASSES.append(SetOpType)
class SetVarBranch(object):
TYPE = 'SetVarBranch'
ENUM = ['SET_VAR_NONE','SET_VAR_RND','SET_VAR_DEGREE_MIN','SET_VAR_DEGREE_MAX','SET_VAR_AFC_MIN','SET_VAR_AFC_MAX','SET_VAR_MIN_MIN','SET_VAR_MIN_MAX','SET_VAR_MAX_MIN','SET_VAR_MAX_MAX','SET_VAR_SIZE_MIN','SET_VAR_SIZE_MAX','SET_VAR_SIZE_DEGREE_MIN','SET_VAR_SIZE_DEGREE_MAX','SET_VAR_SIZE_AFC_MIN','SET_VAR_SIZE_AFC_MAX']
ENUM_CLASSES.append(SetVarBranch)
class SetValBranch(object):
TYPE = 'SetValBranch'
ENUM = ['SET_VAL_MIN_INC','SET_VAL_MIN_EXC','SET_VAL_MED_INC','SET_VAL_MED_EXC','SET_VAL_MAX_INC','SET_VAL_MAX_EXC','SET_VAL_RND_INC','SET_VAL_RND_EXC']
ENUM_CLASSES.append(SetValBranch)
class SetAssign(object):
TYPE = 'SetAssign'
ENUM = ['SET_ASSIGN_MIN_INC','SET_ASSIGN_MIN_EXC','SET_ASSIGN_MED_INC','SET_ASSIGN_MED_EXC','SET_ASSIGN_MAX_INC','SET_ASSIGN_MAX_EXC','SET_ASSIGN_RND_INC','SET_ASSIGN_RND_EXC']
ENUM_CLASSES.append(SetAssign)

Binary file not shown.

View File

@ -0,0 +1,209 @@
// This file was automatically extracted from Gecode source files.
// It is subject to the same Copyright as the source files from which
// it is derived, and is distributed under the same Licensing conditions.
void abs(Home,IntVar,IntVar,IntConLevel=ICL_DEF);
void assign(Home,BoolVar,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
void assign(Home,const BoolVarArgs&,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
void assign(Home,const IntVarArgs&,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
void assign(Home,const SetVarArgs&,SetAssign,const ValBranchOptions&=ValBranchOptions::def);
void assign(Home,IntVar,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
void assign(Home,SetVar,SetAssign,const ValBranchOptions&=ValBranchOptions::def);
void atmostOne(Home,const SetVarArgs&,unsigned int);
void binpacking(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void branch(Home,BoolVar,IntValBranch,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,const BoolVarArgs&,const TieBreakVarBranch<IntVarBranch>&,IntValBranch,const TieBreakVarBranchOptions&=TieBreakVarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,const BoolVarArgs&,IntVarBranch,IntValBranch,const VarBranchOptions&=VarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,const IntVarArgs&,const TieBreakVarBranch<IntVarBranch>&,IntValBranch,const TieBreakVarBranchOptions&=TieBreakVarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,const IntVarArgs&,IntVarBranch,IntValBranch,const VarBranchOptions&=VarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,const SetVarArgs&,const TieBreakVarBranch<SetVarBranch>&,SetValBranch,const TieBreakVarBranchOptions&=TieBreakVarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,const SetVarArgs&,SetVarBranch,SetValBranch,const VarBranchOptions&=VarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,IntVar,IntValBranch,const ValBranchOptions&=ValBranchOptions::def);
void branch(Home,SetVar,SetValBranch,const ValBranchOptions&=ValBranchOptions::def);
void cardinality(Home,SetVar,IntVar);
void cardinality(Home,SetVar,unsigned int,unsigned int);
void channel(Home,BoolVar,IntVar,IntConLevel=ICL_DEF);
void channel(Home,const BoolVarArgs&,IntVar,int=0,IntConLevel=ICL_DEF);
void channel(Home,const BoolVarArgs&,SetVar);
void channel(Home,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void channel(Home,const IntVarArgs&,const SetVarArgs&);
void channel(Home,const IntVarArgs&,int,const IntVarArgs&,int,IntConLevel=ICL_DEF);
void channel(Home,IntVar,BoolVar,IntConLevel=ICL_DEF);
void channelSorted(Home,const IntVarArgs&,SetVar);
void circuit(Home,const IntArgs&,const IntVarArgs&,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void circuit(Home,const IntArgs&,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void circuit(Home,const IntArgs&,int,const IntVarArgs&,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void circuit(Home,const IntArgs&,int,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void circuit(Home,const IntVarArgs&,IntConLevel=ICL_DEF);
void circuit(Home,int,const IntVarArgs&,IntConLevel=ICL_DEF);
void clause(Home,BoolOpType,const BoolVarArgs&,const BoolVarArgs&,BoolVar,IntConLevel=ICL_DEF);
void clause(Home,BoolOpType,const BoolVarArgs&,const BoolVarArgs&,int,IntConLevel=ICL_DEF);
void convex(Home,SetVar);
void convex(Home,SetVar,SetVar);
void count(Home,const IntVarArgs&,const IntArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,const IntArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,const IntSetArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,const IntSetArgs&,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,const IntSet&,const IntArgs&,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,int,IntRelType,int,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,int,IntRelType,IntVar,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,IntVar,IntRelType,int,IntConLevel=ICL_DEF);
void count(Home,const IntVarArgs&,IntVar,IntRelType,IntVar,IntConLevel=ICL_DEF);
void cumulative(Home,int,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,int,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,int,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,int,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,int,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,int,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,IntVar,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,IntVar,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,IntVar,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,IntVar,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,IntVar,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void cumulative(Home,IntVar,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
void distinct(Home,const IntArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void distinct(Home,const IntVarArgs&,IntConLevel=ICL_DEF);
void div(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void divmod(Home,IntVar,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void dom(Home,const IntVarArgs&,const IntSet&,IntConLevel=ICL_DEF);
void dom(Home,const IntVarArgs&,int,IntConLevel=ICL_DEF);
void dom(Home,const IntVarArgs&,int,int,IntConLevel=ICL_DEF);
void dom(Home,IntVar,const IntSet&,BoolVar,IntConLevel=ICL_DEF);
void dom(Home,IntVar,const IntSet&,IntConLevel=ICL_DEF);
void dom(Home,IntVar,int,BoolVar,IntConLevel=ICL_DEF);
void dom(Home,IntVar,int,int,BoolVar,IntConLevel=ICL_DEF);
void dom(Home,IntVar,int,IntConLevel=ICL_DEF);
void dom(Home,IntVar,int,int,IntConLevel=ICL_DEF);
void dom(Home,SetVar,SetRelType,const IntSet&);
void dom(Home,SetVar,SetRelType,const IntSet&,BoolVar);
void dom(Home,SetVar,SetRelType,int);
void dom(Home,SetVar,SetRelType,int,BoolVar);
void dom(Home,SetVar,SetRelType,int,int);
void dom(Home,SetVar,SetRelType,int,int,BoolVar);
void element(Home,const BoolVarArgs&,IntVar,BoolVar,IntConLevel=ICL_DEF);
void element(Home,const BoolVarArgs&,IntVar,int,IntConLevel=ICL_DEF);
void element(Home,const BoolVarArgs&,IntVar,int,IntVar,int,BoolVar,IntConLevel=ICL_DEF);
void element(Home,const IntSetArgs&,IntVar,int,IntVar,int,SetVar);
void element(Home,const IntSetArgs&,IntVar,SetVar);
void element(Home,const IntVarArgs&,IntVar,int,IntConLevel=ICL_DEF);
void element(Home,const IntVarArgs&,IntVar,int,IntVar,int,IntVar,IntConLevel=ICL_DEF);
void element(Home,const IntVarArgs&,IntVar,IntVar,IntConLevel=ICL_DEF);
void element(Home,const SetVarArgs&,IntVar,int,IntVar,int,SetVar);
void element(Home,const SetVarArgs&,IntVar,SetVar);
void element(Home,IntSharedArray,IntVar,BoolVar,IntConLevel=ICL_DEF);
void element(Home,IntSharedArray,IntVar,int,IntConLevel=ICL_DEF);
void element(Home,IntSharedArray,IntVar,int,IntVar,int,BoolVar,IntConLevel=ICL_DEF);
void element(Home,IntSharedArray,IntVar,int,IntVar,int,IntVar,IntConLevel=ICL_DEF);
void element(Home,IntSharedArray,IntVar,IntVar,IntConLevel=ICL_DEF);
void element(Home,SetOpType,const IntSetArgs&,SetVar,SetVar,const IntSet&=IntSet(Set::Limits::min,Set::Limits::max));
void element(Home,SetOpType,const SetVarArgs&,SetVar,SetVar,const IntSet&=IntSet(Set::Limits::min,Set::Limits::max));
void extensional(Home,const BoolVarArgs&,const TupleSet&,ExtensionalPropKind=EPK_DEF,IntConLevel=ICL_DEF);
void extensional(Home,const BoolVarArgs&,DFA,IntConLevel=ICL_DEF);
void extensional(Home,const IntVarArgs&,const TupleSet&,ExtensionalPropKind=EPK_DEF,IntConLevel=ICL_DEF);
void extensional(Home,const IntVarArgs&,DFA,IntConLevel=ICL_DEF);
void linear(Home,const BoolVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const BoolVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void linear(Home,const BoolVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const BoolVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
void linear(Home,const IntVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const IntVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void linear(Home,const IntVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
void linear(Home,const IntVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
void max(Home,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void max(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void max(Home,SetVar,IntVar);
void max(Home,SetVar,IntVar,BoolVar);
void min(Home,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void min(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void min(Home,SetVar,IntVar);
void min(Home,SetVar,IntVar,BoolVar);
void mod(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void mult(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void nooverlap(Home,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void nooverlap(Home,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void nooverlap(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void nooverlap(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void notMax(Home,SetVar,IntVar);
void notMin(Home,SetVar,IntVar);
void path(Home,const IntArgs&,const IntVarArgs&,IntVar,IntVar,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void path(Home,const IntArgs&,const IntVarArgs&,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void path(Home,const IntArgs&,int,const IntVarArgs&,IntVar,IntVar,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
void path(Home,const IntArgs&,int,const IntVarArgs&,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
void path(Home,const IntVarArgs&,IntVar,IntVar,IntConLevel=ICL_DEF);
void path(Home,int,const IntVarArgs&,IntVar,IntVar,IntConLevel=ICL_DEF);
void precede(Home,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void precede(Home,const IntVarArgs&,int,int,IntConLevel=ICL_DEF);
void precede(Home,const SetVarArgs&,const IntArgs&);
void precede(Home,const SetVarArgs&,int,int);
void rel(Home,BoolOpType,const BoolVarArgs&,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,BoolOpType,const BoolVarArgs&,int,IntConLevel=ICL_DEF);
void rel(Home,BoolVar,BoolOpType,BoolVar,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,BoolVar,BoolOpType,BoolVar,int,IntConLevel=ICL_DEF);
void rel(Home,BoolVar,IntRelType,BoolVar,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,BoolVar,IntRelType,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,BoolVar,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,BoolVar,IntRelType,int,IntConLevel=ICL_DEF);
void rel(Home,const BoolVarArgs&,IntRelType,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,const BoolVarArgs&,IntRelType,const BoolVarArgs&,IntConLevel=ICL_DEF);
void rel(Home,const BoolVarArgs&,IntRelType,IntConLevel=ICL_DEF);
void rel(Home,const BoolVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void rel(Home,const IntSet&,SetOpType,SetVar,SetRelType,const IntSet&);
void rel(Home,const IntSet&,SetOpType,SetVar,SetRelType,SetVar);
void rel(Home,const IntVarArgs&,IntRelType,const IntVarArgs&,IntConLevel=ICL_DEF);
void rel(Home,const IntVarArgs&,IntRelType,IntConLevel=ICL_DEF);
void rel(Home,const IntVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
void rel(Home,const IntVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
void rel(Home,IntVar,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,IntVar,IntRelType,int,IntConLevel=ICL_DEF);
void rel(Home,IntVar,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
void rel(Home,IntVar,IntRelType,IntVar,IntConLevel=ICL_DEF);
void rel(Home,IntVar,IntRelType,SetVar);
void rel(Home,IntVar,SetRelType,SetVar);
void rel(Home,IntVar,SetRelType,SetVar,BoolVar);
void rel(Home,SetOpType,const IntVarArgs&,const IntSet&,SetVar);
void rel(Home,SetOpType,const IntVarArgs&,SetVar);
void rel(Home,SetOpType,const SetVarArgs&,const IntSet&,SetVar);
void rel(Home,SetOpType,const SetVarArgs&,SetVar);
void rel(Home,SetVar,IntRelType,IntVar);
void rel(Home,SetVar,SetOpType,const IntSet&,SetRelType,const IntSet&);
void rel(Home,SetVar,SetOpType,const IntSet&,SetRelType,SetVar);
void rel(Home,SetVar,SetOpType,SetVar,SetRelType,const IntSet&);
void rel(Home,SetVar,SetOpType,SetVar,SetRelType,SetVar);
void rel(Home,SetVar,SetRelType,IntVar);
void rel(Home,SetVar,SetRelType,IntVar,BoolVar);
void rel(Home,SetVar,SetRelType,SetVar);
void rel(Home,SetVar,SetRelType,SetVar,BoolVar);
void sequence(Home,const BoolVarArgs&,const IntSet&,int,int,int,IntConLevel=ICL_DEF);
void sequence(Home,const IntVarArgs&,const IntSet&,int,int,int,IntConLevel=ICL_DEF);
void sequence(Home,const SetVarArgs&);
void sequence(Home,const SetVarArgs&,SetVar);
void sorted(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void sorted(Home,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void sqr(Home,IntVar,IntVar,IntConLevel=ICL_DEF);
void sqrt(Home,IntVar,IntVar,IntConLevel=ICL_DEF);
void unary(Home,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void unary(Home,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void unary(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void unary(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
void unary(Home,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
void unary(Home,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
void unshare(Home,BoolVarArgs&,IntConLevel=ICL_DEF);
void unshare(Home,IntVarArgs&,IntConLevel=ICL_DEF);
void weights(Home,const IntArgs&,const IntArgs&,SetVar,IntVar);

1045
library/gecode/gecode_yap.cc Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,746 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- module(gecode, [(:=)/2, op(500, xfx, ':='),
(+=)/2, op(500, xfx, '+=')]).
:- op(500, xfx, ':=').
:- op(500, xfx, '+=').
:- load_foreign_files([gecode_yap],[],gecode_init).
is_int(X,Y) :- integer(X), Y=X.
is_int(X) :- integer(X).
is_bool_(true,true).
is_bool_(false,false).
is_bool(X,Y) :- nonvar(X), Y=X.
is_bool(X) :- is_bool(X,_).
is_IntVar_('IntVar'(I),I) :- integer(I).
is_BoolVar_('BoolVar'(I),I) :- integer(I).
is_SetVar_('SetVar'(I),I) :- integer(I).
is_IntVar(X,I) :- nonvar(X), is_IntVar_(X,I).
is_BoolVar(X,I) :- nonvar(X), is_BoolVar_(X,I).
is_SetVar(X,I) :- nonvar(X), is_SetVar_(X,I).
is_IntVar(X) :- is_IntVar(X,_).
is_BoolVar(X) :- is_BoolVar(X,_).
is_SetVar(X) :- is_SetVar(X,_).
is_IntVarArgs_([],[]).
is_IntVarArgs_([H|T],[H2|T2]) :- is_IntVar(H,H2), is_IntVarArgs(T,T2).
is_IntVarArgs(X,Y) :- nonvar(X), is_IntVarArgs_(X,Y).
is_IntVarArgs(X) :- \+ \+ is_IntVarArgs(X,_).
is_BoolVarArgs_([],[]).
is_BoolVarArgs_([H|T],[H2|T2]) :- is_BoolVar(H,H2), is_BoolVarArgs(T,T2).
is_BoolVarArgs(X,Y) :- nonvar(X), is_BoolVarArgs_(X,Y).
is_BoolVarArgs(X) :- \+ \+ is_BoolVarArgs(X,_).
is_SetVarArgs_([],[]).
is_SetVarArgs_([H|T],[H2|T2]) :- is_SetVar(H,H2), is_SetVarArgs(T,T2).
is_SetVarArgs(X,Y) :- nonvar(X), is_SetVarArgs_(X,Y).
is_SetVarArgs(X) :- \+ \+ is_SetVarArgs(X,_).
is_IntArgs_([],[]).
is_IntArgs_([H|T],[H|T2]) :- integer(H), is_IntArgs(T,T2).
is_IntArgs(X,Y) :- nonvar(X), is_IntArgs_(X,Y).
is_IntArgs(X) :- \+ \+ is_IntArgs(X,_).
is_IntSharedArray(X) :- is_IntArgs(X).
is_IntSharedArray(X,Y) :- is_IntArgs(X,Y).
is_TaskTypeArgs_([],[]).
is_TaskTypeArgs_([H|T],[H2|T2]) :- is_TaskType(H,H2), is_TaskTypeArgs(T,T2).
is_TaskTypeArgs(X,Y) :- nonvar(X), is_TaskTypeArgs_(X,Y).
is_TaskTypeArgs(X) :- \+ \+ is_TaskTypeArgs(X,_).
is_IntSet_('IntSet'(L),L).
is_IntSet(X,Y) :- nonvar(X), is_IntSet_(X,Y).
is_IntSet(X) :- is_IntSet(X,_).
is_IntSetArgs_([],[]).
is_IntSetArgs_([H|T],[H2|T2]) :- is_IntSet(H,H2), is_IntSetArgs(T,T2).
is_IntSetArgs(X,Y) :- nonvar(X), is_IntSetArgs_(X,Y).
is_IntSetArgs(X) :- \+ \+ is_IntSetArgs(X,_).
new_intset(X,I,J) :- intset(X,I,J).
new_intset(X,L) :- intset(X,L).
intset(X, I, J) :-
integer(I),
integer(J),
X='IntSet'([(I,J)]).
intset(X, L) :-
is_list_of_intset_specs(L,L2),
X='IntSet'(L2).
is_list_of_intset_specs(X,Y) :-
nonvar(X), is_list_of_intset_specs_(X,Y).
is_list_of_intset_specs_([],[]).
is_list_of_intset_specs_([H|T],[H2|T2]) :-
is_intset_spec(H,H2),
is_list_of_intset_specs(T,T2).
is_intset_spec(X,Y) :- nonvar(X), is_intset_spec_(X,Y).
is_intset_spec_((I,J),(I,J)) :- !, integer(I), integer(J).
is_intset_spec_(I,(I,I)) :- integer(I).
assert_var(X,Y) :-
var(X) -> X=Y; throw(gecode_error(expected(var))).
assert_is_int(X,Y) :-
integer(X) -> X=Y ; throw(gecode_error(expected(int))).
assert_is_Space(X,Y) :-
is_Space(X,Y) -> true ; throw(gecode_error(expected(space))).
assert_is_IntSet(X,Y) :-
is_IntSet(X,Y) -> true ; throw(gecode_error(expected(intset))).
assert_is_IntVar(X,Y) :-
is_IntVar(X,Y) -> true ; throw(gecode_error(expected(intvar))).
assert_is_BoolVar(X,Y) :-
is_BoolVar(X,Y) -> true ; throw(gecode_error(expected(boolvar))).
assert_is_SetVar(X,Y) :-
is_SetVar(X,Y) -> true ; throw(gecode_error(expected(setvar))).
assert_is_IntArgs(X,Y) :-
is_IntArgs(X,Y) -> true ; throw(gecode_error(expected(intargs))).
assert_is_IntVarArgs(X,Y) :-
is_IntVarArgs(X,Y) -> true ; throw(gecode_error(expected(intvarargs))).
assert_is_BoolVarArgs(X,Y) :-
is_BoolVarArgs(X,Y) -> true ; throw(gecode_error(expected(boolvarargs))).
assert_is_SetVarArgs(X,Y) :-
is_SetVarArgs(X,Y) -> true ; throw(gecode_error(expected(setvarargs))).
assert_var(X) :- assert_var(X,_).
assert_is_int(X) :- assert_is_int(X,_).
assert_is_Space(X) :- assert_is_Space(X,_).
assert_is_IntSet(X) :- assert_is_IntSet(X,_).
assert_is_IntVar(X) :- assert_is_IntVar(X,_).
assert_is_BoolVar(X) :- assert_is_BoolVar(X,_).
assert_is_SetVar(X) :- assert_is_SetVar(X,_).
assert_is_IntArgs(X) :- assert_is_IntArgs(X,_).
assert_is_IntVarArgs(X) :- assert_is_IntVarArgs(X,_).
assert_is_BoolVarArgs(X) :- assert_is_BoolVarArgs(X,_).
assert_is_SetVarArgs(X) :- assert_is_SetVarArgs(X,_).
new_space(Space) :-
assert_var(Space),
gecode_new_space(Space_),
Space='Space'(Space_).
is_Space_('Space'(X),X).
is_Space(X,Y) :- nonvar(X), is_Space_(X,Y).
is_Space(X) :- is_Space(X,_).
%% AUTOGENERATE ALL VARIANTS LATER!
new_intvars([], Space, Lo, Hi).
new_intvars([IVar|IVars], Space, Lo, Hi) :-
new_intvar(IVar, Space, Lo, Hi),
new_intvars(IVars, Space, Lo, Hi).
new_intvars([], Space, IntSet).
new_intvars([IVar|IVars], Space, IntSet) :-
new_intvar(IVar, Space, IntSet),
new_intvars(IVars, Space, IntSet).
new_boolvars([], Space).
new_boolvars([BVar|BVars], Space) :-
new_boolvar(BVar, Space),
new_boolvars(BVars, Space).
new_setvars([], Space, X1, X2, X3, X4, X5, X6).
new_setvars([SVar|SVars], Space, X1, X2, X3, X4, X5, X6) :-
new_setvar(SVar, Space, X1, X2, X3, X4, X5, X6),
new_setvars(SVars, Space, X1, X2, X3, X4, X5, X6).
new_setvars([], Space, X1, X2, X3, X4, X5).
new_setvars([SVar|SVars], Space, X1, X2, X3, X4, X5) :-
new_setvar(SVar, Space, X1, X2, X3, X4, X5),
new_setvars(SVars, Space, X1, X2, X3, X4, X5).
new_setvars([], Space, X1, X2, X3, X4).
new_setvars([SVar|SVars], Space, X1, X2, X3, X4) :-
new_setvar(SVar, Space, X1, X2, X3, X4),
new_setvars(SVars, Space, X1, X2, X3, X4).
new_setvars([], Space, X1, X2, X3).
new_setvars([SVar|SVars], Space, X1, X2, X3) :-
new_setvar(SVar, Space, X1, X2, X3),
new_setvars(SVars, Space, X1, X2, X3).
new_setvars([], Space, X1, X2).
new_setvars([SVar|SVars], Space, X1, X2) :-
new_setvar(SVar, Space, X1, X2),
new_setvars(SVars, Space, X1, X2).
%% AUTOGENERATE LATER
assert_integer(X) :- assert_is_int(X).
new_intvar(IVar, Space, Lo, Hi) :- !,
assert_var(IVar),
assert_is_Space_or_Clause(Space,Space_),
assert_integer(Lo),
assert_integer(Hi),
gecode_new_intvar_from_bounds(Idx,Space_,Lo,Hi),
IVar='IntVar'(Idx).
new_intvar(IVar, Space, IntSet) :- !,
assert_var(IVar),
assert_is_Space_or_Clause(Space,Space_),
assert_is_IntSet(IntSet, L),
gecode_new_intvar_from_intset(Idx,Space_,L),
IVar='IntVar'(Idx).
new_boolvar(BVar, Space) :- !,
assert_var(BVar),
assert_is_Space_or_Clause(Space,Space_),
gecode_new_boolvar(Idx,Space_),
BVar='BoolVar'(Idx).
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin,CardMax) 6 new_setvar_1
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin) 5 new_setvar_2
%% (GlbMin,GlbMax,LubMin,LubMax) 4 new_setvar_3
%% (Glb,LubMin,LubMax,CardMin,CardMax) 5 new_setvar_4
%% (Glb,LubMin,LubMax,CardMin) 4 new_setvar_5
%% (Glb,LubMin,LubMax) 3 new_setvar_6
%% (GlbMin,GlbMax,Lub,CardMin,CardMax) 5 new_setvar_7
%% (GlbMin,GlbMax,Lub,CardMin) 4 new_setvar_8
%% (GlbMin,GlbMax,Lub) 3 new_setvar_9
%% (Glb,Lub,CardMin,CardMax) 4 new_setvar_10
%% (Glb,Lub,CardMin) 3 new_setvar_11
%% (Glb,Lub) 2 new_setvar_12
%% 6 arguments
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin,CardMax) 6 new_setvar_1
new_setvar(SVar, Space, GlbMin, GlbMax, LubMin, LubMax, CardMin, CardMax) :-
assert_var(SVar),
assert_is_Space_or_Clause(Space,Space_),
assert_integer(GlbMin),
assert_integer(GlbMax),
assert_integer(LubMin),
assert_integer(LubMax),
assert_integer(CardMin),
assert_integer(CardMax),
gecode_new_setvar(Idx, Space_, GlbMin, GlbMax, LubMib, LubMax, CardMin, CardMax),
SVar='SetVar'(Idx).
%% 5 arguments
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin) 5 new_setvar_2
%% (Glb,LubMin,LubMax,CardMin,CardMax) 5 new_setvar_4
%% (GlbMin,GlbMax,Lub,CardMin,CardMax) 5 new_setvar_7
new_setvar(SVar, Space, X1, X2, X3, X4, X5) :-
assert_var(SVar),
assert_is_Space_or_Clause(Space,Space_),
(integer(X1)
->
assert_integer(X2),
assert_integer(X4),
assert_integer(X5),
(is_IntSet(X3,X3_)
-> gecode_new_setvar_7(Idx,Space_,X1,X2,X3_,X4,X5)
; gecode_new_setvar_2(Idx,Space_,X1,X2,X3,X4,X5))
;
assert_is_IntSet(X1,X1_),
assert_integer(X2),
assert_integer(X3),
assert_integer(X4),
assert_integer(X5),
gecode_new_setvar_4(Idx,Space_,X1_,X2,X3,X4,X5)),
SVar='SetVar'(Idx).
%% 4 arguments
%% (GlbMin,GlbMax,LubMin,LubMax) 4 new_setvar_3
%% (Glb,LubMin,LubMax,CardMin) 4 new_setvar_5
%% (GlbMin,GlbMax,Lub,CardMin) 4 new_setvar_8
%% (Glb,Lub,CardMin,CardMax) 4 new_setvar_10
new_setvar(SVar,Space,X1,X2,X3,X4) :-
assert_var(SVar),
assert_is_Space_or_Clause(Space,Space_),
assert_integer(X4),
(is_IntSet(X1,X1_)
-> (is_IntSet(X2,X2_)
->
assert_integer(X3),
gecode_new_setvar_10(Idx,Space_,X1_,X2_,X3,X4)
;
assert_integer(X2),
assert_integer(X3),
gecode_new_setvar_5(Idx,Space_,X1_,X2,X3,X4))
;
assert_integer(X1),
assert_integer(X2),
(is_IntSet(X3,X3_)
->
gecode_new_setvar_8(Idx,Space_,X1,X2,X3_,X4)
;
assert_integer(X3),
gecode_new_setvar_3(Idx,Space_,X1,X2,X3,X4))),
SVar='SetVar'(Idx).
%% 3 arguments
%% (Glb,LubMin,LubMax) 3 new_setvar_6
%% (GlbMin,GlbMax,Lub) 3 new_setvar_9
%% (Glb,Lub,CardMin) 3 new_setvar_11
new_setvar(SVar,Space,X1,X2,X3) :-
assert_var(SVar),
assert_is_Space_or_Clause(Space,Space_),
(is_IntSet(X1,X1_)
-> (is_IntSet(X2,X2_)
->
assert_integer(X3),
gecode_new_setvar_11(Idx,Space_,X1_,X2_,X3)
;
assert_integer(X2),
assert_integer(X3),
gecode_new_setvar_6(Idx,Space_,X1_,X2,X3))
;
assert_integer(X1),
assert_integer(X2),
assert_is_IntSet(X3,X3_),
gecode_new_setvar_9(Idx,Space_,X1,X2,X3_)),
SVar='SetVar'(Idx).
%% 2 arguments
%% (Glb,Lub) 2 new_setvar_12
new_setvar(SVar,Space,X1,X2) :-
assert_var(SVar),
assert_is_Space_or_Clause(Space,Space_),
assert_is_IntSet(X1,X1_),
assert_is_IntSet(X2,X2_),
gecode_new_setvar_12(Idx,Space_,X1_,X2_),
SVar='SetVar'(Idx).
minimize(Space,IVar) :-
assert_is_Space(Space,Space_),
assert_is_IntVar(IVar,IVar_),
gecode_space_minimize(Space_,IVar_).
maximize(Space,IVar) :-
assert_is_Space(Space,Space_),
assert_is_IntVar(IVar,IVar_),
gecode_space_maximize(Space_,IVar_).
minimize(Space,IVar1,IVar2) :-
assert_is_Space(Space,Space_),
assert_is_IntVar(IVar1,IVar1_),
assert_is_IntVar(IVar2,IVar2_),
gecode_space_minimize_ratio(Space_,IVar1_,IVar2_).
maximize(Space,IVar1,IVar2) :-
assert_is_Space(Space,Space_),
assert_is_IntVar(IVar1,IVar1_),
assert_is_IntVar(IVar2,IVar2_),
gecode_space_maximize_ratio(Space_,IVar1_,IVar2_).
search(Space, Solution) :-
assert_is_Space(Space,Space_),
assert_var(Solution),
gecode_new_engine(Space_,Engine_),
gecode_engine_search(Engine_,Solution_),
Solution='Space'(Solution_).
%% INSPECTING VARIABLES
get_for_vars([],Space,[],F).
get_for_vars([V|Vs],Space,[V2|V2s],F) :-
call_with_args(F,V,Space,V2),
get_for_vars(Vs,Space,V2s,F).
get_assigned(Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_assigned(Space_,Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_assigned(Space_,Var_)
; is_SetVar(Var,Var_)
-> gecode_setvar_assigned(Space_,Var_)
; throw(gecode_error(expected(variable))).
get_min(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_min(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_min(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_min).
get_max(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_max(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_max(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_max).
get_med(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_med(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_med(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_med).
get_val(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_val(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_val(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_val).
get_size(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_size(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_size(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_size).
get_width(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_width(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_width(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_width).
get_regret_min(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_regret_min(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_regret_min(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_regret_min).
get_regret_max(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_IntVar(Var,Var_)
-> gecode_intvar_regret_max(X, Space_, Var_)
; is_BoolVar(Var,Var_)
-> gecode_boolvar_regret_max(X, Space_, Var_)
; get_for_vars(X, Space, Var, gecode:get_regret_max).
get_glbSize(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_glbSize(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_glbSize).
get_lubSize(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_lubSize(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_lubSize).
get_unknownSize(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_unknownSize(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_unknownSize).
get_cardMin(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_cardMin(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_cardMin).
get_cardMax(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_cardMax(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_cardMax).
get_lubMin(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_lubMin(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_lubMin).
get_lubMax(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_lubMax(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_lubMax).
get_glbMin(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_glbMin(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_glbMin).
get_glbMax(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_glbMax(X,Space_,Var_)
; get_for_vars(X, Space, Var, gecode:get_glbMax).
get_glb_ranges(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_glb_ranges(X,Space_,Var_)
; get_for_vars(X,Space,Var,gecode:get_glb_ranges).
get_lub_ranges(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_lub_ranges(X,Space_,Var_)
; get_for_vars(X,Space,Var,gecode:get_lub_ranges).
get_unknown_ranges(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_unknown_ranges(X,Space_,Var_)
; get_for_vars(X,Space,Var,gecode:get_unknown_ranges).
get_glb_values(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_glb_values(X,Space_,Var_)
; get_for_vars(X,Space,Var,gecode:get_glb_values).
get_lub_values(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_lub_values(X,Space_,Var_)
; get_for_vars(X,Space,Var,gecode:get_lub_values).
get_unknown_values(X, Space, Var) :-
assert_is_Space(Space,Space_),
is_SetVar(Var,Var_)
-> gecode_setvar_unknown_values(X,Space_,Var_)
; get_for_vars(X,Space,Var,gecode:get_unknown_values).
new_disjunctor(X, Space) :-
assert_is_Space(Space,Space_),
gecode_new_disjunctor(D,Space_),
X='Disjunctor'(D).
is_Disjunctor_('Disjunctor'(D),D).
is_Disjunctor(X,Y) :- nonvar(X), is_Disjunctor_(X,Y).
is_Disjunctor(X) :- is_Disjunctor(X,_).
assert_is_Disjunctor(X,Y) :-
is_Disjunctor(X,Y) -> true ; throw(gecode_error(expected(disjunctor))).
new_clause(X, Disj) :-
assert_is_Disjunctor(Disj,Disj_),
gecode_new_clause(C, Disj_),
X='Clause'(C).
is_Clause_('Clause'(C),C).
is_Clause(X,Y) :- nonvar(X), is_Clause_(X,Y).
is_Clause(X) :- is_Clause(X,_).
assert_is_Clause(X,Y) :-
is_Clause(X,Y) -> true ; throw(gecode_error(expected(clause))).
is_Space_or_Clause(X,Y) :-
(is_Space(X,Y);is_Clause(X,Y)), !.
assert_is_Space_or_Clause(X,Y) :-
is_Space_or_Clause(X,Y) -> true
; throw(gecode_error(expected(space,clause))).
new_forward(Clause, X, Y) :-
assert_is_Clause(Clause, Clause_),
(is_IntVar(X,X_)
-> (is_IntVar(Y,Y_)
-> gecode_clause_intvar_forward(Clause_,X_,Y_)
; throw(gecode_error(forward)))
; (is_BoolVar(X,X_)
-> (is_BoolVar(Y,Y_)
-> gecode_clause_boolvar_forward(Clause_,X_,Y_)
; throw(gecode_error(forward)))
; (is_SetVar(X,X_)
-> (is_SetVar(Y,Y_)
-> gecode_clause_setvar_forward(Clause_,X_,Y_)
; throw(gecode_error(forward)))
; (X=[]
-> Y=[]
;(X=[H1|T1],Y=[H2|T2])
-> (new_forward(Clause,H1,H2),
new_forward(Clause,T1,T2))
; throw(gecode_error(forward)))))).
new_intvars_(L,Space,N,I,J) :- length(L,N), new_intvars(L,Space,I,J).
new_intvars_(L,Space,N,IntSet) :- length(L,N), new_intvars(L,Space,IntSet).
new_boolvars_(L,Space,N) :- length(L,N), new_boolvars(L,Space).
new_setvars_(L,Space,N,X1,X2,X3,X4,X5,X6) :- length(L,N), new_setvars(L,Space,X1,X2,X3,X4,X5,X6).
new_setvars_(L,Space,N,X1,X2,X3,X4,X5) :- length(L,N), new_setvars(L,Space,X1,X2,X3,X4,X5).
new_setvars_(L,Space,N,X1,X2,X3,X4) :- length(L,N), new_setvars(L,Space,X1,X2,X3,X4).
new_setvars_(L,Space,N,X1,X2,X3) :- length(L,N), new_setvars(L,Space,X1,X2,X3).
new_setvars_(L,Space,N,X1,X2) :- length(L,N), new_setvars(L,Space,X1,X2).
%% more concise interface:
(X := Y) :- var(Y), !, throw(gecode_error((X := Y))).
(X := intset(I,J)) :- !, new_intset(X,I,J).
(X := intset(L)) :- !, new_intset(X,L).
(X := space) :- !, new_space(X).
(X := intvar(Space,I,J)) :- !, new_intvar(X,Space,I,J).
(X := intvar(Space,IntSet)) :- !, new_intvar(X,Space,IntSet).
(X := boolvar(Space)) :- !, new_boolvar(X,Space).
(X := setvar(Space,X1,X2,X3,X4,X5,X6)) :- !, new_setvar(X,Space,X1,X2,X3,X4,X5,X6).
(X := setvar(Space,X1,X2,X3,X4,X5)) :- !, new_setvar(X,Space,X1,X2,X3,X4,X5).
(X := setvar(Space,X1,X2,X3,X4)) :- !, new_setvar(X,Space,X1,X2,X3,X4).
(X := setvar(Space,X1,X2,X3)) :- !, new_setvar(X,Space,X1,X2,X3).
(X := setvar(Space,X1,X2)) :- !, new_setvar(X,Space,X1,X2).
(X := intvars(Space,N,I,J)) :- !, new_intvars_(X,Space,N,I,J).
(X := intvars(Space,N,IntSet)) :- !, new_intvars_(X,Space,N,IntSet).
(X := boolvars(Space,N)) :- !, new_boolvars_(X,Space,N).
(X := setvars(Space,N,X1,X2,X3,X4,X5,X6)) :- !, new_setvars_(X,Space,N,X1,X2,X3,X4,X5,X6).
(X := setvars(Space,N,X1,X2,X3,X4,X5)) :- !, new_setvars_(X,Space,N,X1,X2,X3,X4,X5).
(X := setvars(Space,N,X1,X2,X3,X4)) :- !, new_setvars_(X,Space,N,X1,X2,X3,X4).
(X := setvars(Space,N,X1,X2,X3)) :- !, new_setvars_(X,Space,N,X1,X2,X3).
(X := setvars(Space,N,X1,X2)) :- !, new_setvars_(X,Space,N,X1,X2).
(X := min(Space,Var)) :- !, get_min(X,Space,Var).
(X := max(Space,Var)) :- !, get_max(X,Space,Var).
(X := med(Space,Var)) :- !, get_med(X,Space,Var).
(X := val(Space,Var)) :- !, get_val(X,Space,Var).
(X := size(Space,Var)) :- !, get_size(X,Space,Var).
(X := width(Space,Var)) :- !, get_width(X,Space,Var).
(X := regret_min(Space,Var)) :- !, get_regret_min(X,Space,Var).
(X := regret_max(Space,Var)) :- !, get_regret_max(X,Space,Var).
(X := glbSize(Space,Var)) :- !, get_glbSize(X,Space,Var).
(X := lubSize(Space,Var)) :- !, get_lubSize(X,Space,Var).
(X := unknownSize(Space,Var)) :- !, get_unknownSize(X,Space,Var).
(X := cardMin(Space,Var)) :- !, get_cardMin(X,Space,Var).
(X := cardMax(Space,Var)) :- !, get_cardMax(X,Space,Var).
(X := lubMin(Space,Var)) :- !, get_lubMin(X,Space,Var).
(X := lubMax(Space,Var)) :- !, get_lubMax(X,Space,Var).
(X := glbMin(Space,Var)) :- !, get_glbMin(X,Space,Var).
(X := glbMax(Space,Var)) :- !, get_glbMax(X,Space,Var).
(X := glb_ranges(Space,Var)) :- !, get_glb_ranges(X,Space,Var).
(X := lub_ranges(Space,Var)) :- !, get_lub_ranges(X,Space,Var).
(X := unknown_ranges(Space,Var)) :- !, get_unknown_ranges(X,Space,Var).
(X := glb_values(Space,Var)) :- !, get_glb_values(X,Space,Var).
(X := lub_values(Space,Var)) :- !, get_lub_values(X,Space,Var).
(X := unknown_values(Space,Var)) :- !, get_unknown_values(X,Space,Var).
(X := disjunctor(Space)) :- !, new_disjunctor(X,Space).
(X := clause(Disj)) :- !, new_clause(X,Disj).
(X := search(Y)) :- !, search(Y,X).
% these should be autogenerated:
(C += forward(X,Y)) :- !, new_forward(C,X,Y).
(Space += abs(X1,X2)) :- !, abs(Space,X1,X2).
(Space += abs(X1,X2,X3)) :- !, abs(Space,X1,X2,X3).
(Space += assign(X1,X2)) :- !, assign(Space,X1,X2).
(Space += atmostOne(X1,X2)) :- !, atmostOne(Space,X1,X2).
(Space += binpacking(X1,X2,X3)) :- !, binpacking(Space,X1,X2,X3).
(Space += binpacking(X1,X2,X3,X4)) :- !, binpacking(Space,X1,X2,X3,X4).
(Space += branch(X1,X2)) :- !, branch(Space,X1,X2).
(Space += branch(X1,X2,X3)) :- !, branch(Space,X1,X2,X3).
(Space += cardinality(X1,X2)) :- !, cardinality(Space,X1,X2).
(Space += cardinality(X1,X2,X3)) :- !, cardinality(Space,X1,X2,X3).
(Space += channel(X1,X2)) :- !, channel(Space,X1,X2).
(Space += channel(X1,X2,X3)) :- !, channel(Space,X1,X2,X3).
(Space += channel(X1,X2,X3,X4)) :- !, channel(Space,X1,X2,X3,X4).
(Space += channel(X1,X2,X3,X4,X5)) :- !, channel(Space,X1,X2,X3,X4,X5).
(Space += channelSorted(X1,X2)) :- !, channelSorted(Space,X1,X2).
(Space += circuit(X1)) :- !, circuit(Space,X1).
(Space += circuit(X1,X2)) :- !, circuit(Space,X1,X2).
(Space += circuit(X1,X2,X3)) :- !, circuit(Space,X1,X2,X3).
(Space += circuit(X1,X2,X3,X4)) :- !, circuit(Space,X1,X2,X3,X4).
(Space += circuit(X1,X2,X3,X4,X5)) :- !, circuit(Space,X1,X2,X3,X4,X5).
(Space += circuit(X1,X2,X3,X4,X5,X6)) :- !, circuit(Space,X1,X2,X3,X4,X5,X6).
(Space += clause(X1,X2,X3,X4)) :- !, clause(Space,X1,X2,X3,X4).
(Space += clause(X1,X2,X3,X4,X5)) :- !, clause(Space,X1,X2,X3,X4,X5).
(Space += convex(X1)) :- !, convex(Space,X1).
(Space += convex(X1,X2)) :- !, convex(Space,X1,X2).
(Space += count(X1,X2)) :- !, count(Space,X1,X2).
(Space += count(X1,X2,X3)) :- !, count(Space,X1,X2,X3).
(Space += count(X1,X2,X3,X4)) :- !, count(Space,X1,X2,X3,X4).
(Space += count(X1,X2,X3,X4,X5)) :- !, count(Space,X1,X2,X3,X4,X5).
(Space += cumulative(X1,X2,X3,X4)) :- !, cumulative(Space,X1,X2,X3,X4).
(Space += cumulative(X1,X2,X3,X4,X5)) :- !, cumulative(Space,X1,X2,X3,X4,X5).
(Space += cumulative(X1,X2,X3,X4,X5,X6)) :- !, cumulative(Space,X1,X2,X3,X4,X5,X6).
(Space += cumulative(X1,X2,X3,X4,X5,X6,X7)) :- !, cumulative(Space,X1,X2,X3,X4,X5,X6,X7).
(Space += cumulatives(X1,X2,X3,X4,X5,X6,X7)) :- !, cumulatives(Space,X1,X2,X3,X4,X5,X6,X7).
(Space += cumulatives(X1,X2,X3,X4,X5,X6,X7,X8)) :- !, cumulatives(Space,X1,X2,X3,X4,X5,X6,X7,X8).
(Space += distinct(X1)) :- !, distinct(Space,X1).
(Space += distinct(X1,X2)) :- !, distinct(Space,X1,X2).
(Space += distinct(X1,X2,X3)) :- !, distinct(Space,X1,X2,X3).
(Space += div(X1,X2,X3)) :- !, div(Space,X1,X2,X3).
(Space += div(X1,X2,X3,X4)) :- !, div(Space,X1,X2,X3,X4).
(Space += divmod(X1,X2,X3,X4)) :- !, divmod(Space,X1,X2,X3,X4).
(Space += divmod(X1,X2,X3,X4,X5)) :- !, divmod(Space,X1,X2,X3,X4,X5).
(Space += dom(X1,X2)) :- !, dom(Space,X1,X2).
(Space += dom(X1,X2,X3)) :- !, dom(Space,X1,X2,X3).
(Space += dom(X1,X2,X3,X4)) :- !, dom(Space,X1,X2,X3,X4).
(Space += dom(X1,X2,X3,X4,X5)) :- !, dom(Space,X1,X2,X3,X4,X5).
(Space += element(X1,X2,X3)) :- !, element(Space,X1,X2,X3).
(Space += element(X1,X2,X3,X4)) :- !, element(Space,X1,X2,X3,X4).
(Space += element(X1,X2,X3,X4,X5)) :- !, element(Space,X1,X2,X3,X4,X5).
(Space += element(X1,X2,X3,X4,X5,X6)) :- !, element(Space,X1,X2,X3,X4,X5,X6).
(Space += element(X1,X2,X3,X4,X5,X6,X7)) :- !, element(Space,X1,X2,X3,X4,X5,X6,X7).
(Space += linear(X1,X2,X3)) :- !, linear(Space,X1,X2,X3).
(Space += linear(X1,X2,X3,X4)) :- !, linear(Space,X1,X2,X3,X4).
(Space += linear(X1,X2,X3,X4,X5)) :- !, linear(Space,X1,X2,X3,X4,X5).
(Space += linear(X1,X2,X3,X4,X5,X6)) :- !, linear(Space,X1,X2,X3,X4,X5,X6).
(Space += max(X1,X2)) :- !, max(Space,X1,X2).
(Space += max(X1,X2,X3)) :- !, max(Space,X1,X2,X3).
(Space += max(X1,X2,X3,X4)) :- !, max(Space,X1,X2,X3,X4).
(Space += min(X1,X2)) :- !, min(Space,X1,X2).
(Space += min(X1,X2,X3)) :- !, min(Space,X1,X2,X3).
(Space += min(X1,X2,X3,X4)) :- !, min(Space,X1,X2,X3,X4).
(Space += mod(X1,X2,X3)) :- !, mod(Space,X1,X2,X3).
(Space += mod(X1,X2,X3,X4)) :- !, mod(Space,X1,X2,X3,X4).
(Space += mult(X1,X2,X3)) :- !, mult(Space,X1,X2,X3).
(Space += mult(X1,X2,X3,X4)) :- !, mult(Space,X1,X2,X3,X4).
(Space += nooverlap(X1,X2,X3,X4)) :- !, nooverlap(Space,X1,X2,X3,X4).
(Space += nooverlap(X1,X2,X3,X4,X5)) :- !, nooverlap(Space,X1,X2,X3,X4,X5).
(Space += nooverlap(X1,X2,X3,X4,X5,X6)) :- !, nooverlap(Space,X1,X2,X3,X4,X5,X6).
(Space += nooverlap(X1,X2,X3,X4,X5,X6,X7)) :- !, nooverlap(Space,X1,X2,X3,X4,X5,X6,X7).
(Space += nooverlap(X1,X2,X3,X4,X5,X6,X7,X8)) :- !, nooverlap(Space,X1,X2,X3,X4,X5,X6,X7,X8).
(Space += notMax(X1,X2)) :- !, notMax(Space,X1,X2).
(Space += notMin(X1,X2)) :- !, notMin(Space,X1,X2).
(Space += path(X1,X2,X3)) :- !, path(Space,X1,X2,X3).
(Space += path(X1,X2,X3,X4)) :- !, path(Space,X1,X2,X3,X4).
(Space += path(X1,X2,X3,X4,X5)) :- !, path(Space,X1,X2,X3,X4,X5).
(Space += path(X1,X2,X3,X4,X5,X6)) :- !, path(Space,X1,X2,X3,X4,X5,X6).
(Space += path(X1,X2,X3,X4,X5,X6,X7)) :- !, path(Space,X1,X2,X3,X4,X5,X6,X7).
(Space += path(X1,X2,X3,X4,X5,X6,X7,X8)) :- !, path(Space,X1,X2,X3,X4,X5,X6,X7,X8).
(Space += precede(X1,X2)) :- !, precede(Space,X1,X2).
(Space += precede(X1,X2,X3)) :- !, precede(Space,X1,X2,X3).
(Space += precede(X1,X2,X3,X4)) :- !, precede(Space,X1,X2,X3,X4).
(Space += rel(X1,X2)) :- !, rel(Space,X1,X2).
(Space += rel(X1,X2,X3)) :- !, rel(Space,X1,X2,X3).
(Space += rel(X1,X2,X3,X4)) :- !, rel(Space,X1,X2,X3,X4).
(Space += rel(X1,X2,X3,X4,X5)) :- !, rel(Space,X1,X2,X3,X4,X5).
(Space += sequence(X1)) :- !, sequence(Space,X1).
(Space += sequence(X1,X2)) :- !, sequence(Space,X1,X2).
(Space += sequence(X1,X2,X3,X4,X5)) :- !, sequence(Space,X1,X2,X3,X4,X5).
(Space += sequence(X1,X2,X3,X4,X5,X6)) :- !, sequence(Space,X1,X2,X3,X4,X5,X6).
(Space += sorted(X1,X2)) :- !, sorted(Space,X1,X2).
(Space += sorted(X1,X2,X3)) :- !, sorted(Space,X1,X2,X3).
(Space += sorted(X1,X2,X3,X4)) :- !, sorted(Space,X1,X2,X3,X4).
(Space += sqr(X0,X1,X2,X3)) :- !, sqr(Space,X0,X1,X2,X3).
(Space += sqr(X1,X2)) :- !, sqr(Space,X1,X2).
(Space += sqrt(X1,X2)) :- !, sqrt(Space,X1,X2).
(Space += sqrt(X1,X2,X3)) :- !, sqrt(Space,X1,X2,X3).
(Space += unary(X1,X2)) :- !, unary(Space,X1,X2).
(Space += unary(X1,X2,X3)) :- !, unary(Space,X1,X2,X3).
(Space += unary(X1,X2,X3,X4)) :- !, unary(Space,X1,X2,X3,X4).
(Space += unary(X1,X2,X3,X4,X5)) :- !, unary(Space,X1,X2,X3,X4,X5).
(Space += unshare(X1)) :- !, unshare(Space,X1).
(Space += unshare(X1,X2)) :- !, unshare(Space,X1,X2).
(Space += weights(X1,X2,X3,X4)) :- !; weights(Space,X1,X2,X3,X4).
(Space += minimize(X)) :- !, minimize(Space,X).
(Space += maximize(X)) :- !, maximize(Space,X).
(Space += minimize(X,Y)) :- !, minimize(Space,X,Y).
(Space += maximize(X,Y)) :- !, maximize(Space,X,Y).

View File

@ -0,0 +1,41 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- use_module(gecode).
% S E N D
% + M O R E
% ---------
% M O N E Y
send_more_money(Solution) :-
Space := space,
Letters := intvars(Space,8,0,9),
[S,E,N,D,M,O,R,Y] = Letters,
Space += rel(M,'IRT_NQ',0),
Space += rel(S,'IRT_NQ',0),
Space += distinct(Letters),
C = [1000, 100, 10, 1,
1000, 100, 10, 1,
-10000, -1000, -100, -10, -1],
X = [S,E,N,D,
M,O,R,E,
M,O,N,E,Y],
Space += linear(C, X, 'IRT_EQ', 0),
Space += branch(Letters, 'INT_VAR_SIZE_MIN', 'INT_VAL_MIN'),
SolSpace := search(Space),
Solution := val(SolSpace,Letters).

View File

@ -0,0 +1,45 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- use_module(gecode).
% S E N D
% + M O S T
% ---------
% M O N E Y
send_most_money(Solution,Amount) :-
Space := space,
Letters := intvars(Space,8,0,9),
[S,E,N,D,M,O,T,Y] = Letters,
Space += rel(M,'IRT_NQ',0),
Space += rel(S,'IRT_NQ',0),
Space += distinct(Letters),
C = [1000, 100, 10, 1,
1000, 100, 10, 1,
-10000, -1000, -100, -10, -1],
X = [S,E,N,D,
M,O,S,T,
M,O,N,E,Y],
Space += linear(C, X, 'IRT_EQ', 0),
Money := intvar(Space,0,99999),
Space += linear([10000,1000,100,10,1],[M,O,N,E,Y],'IRT_EQ',Money),
Space += maximize(Money),
Space += branch(Letters,'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
SolSpace := search(Space),
Solution := val(SolSpace,Letters),
Amount := val(SolSpace,Money).