fix for setvars. also slightly better errors in generated code.
This commit is contained in:
parent
48cb3d6543
commit
8b16734e1c
File diff suppressed because it is too large
Load Diff
@ -296,8 +296,9 @@ class Cluster(object):
|
||||
# discriminating tree based on argument types
|
||||
class DTree(object):
|
||||
|
||||
def __init__(self, i, preds):
|
||||
def __init__(self, i, preds, cluster):
|
||||
self.index = i
|
||||
self.cluster = cluster
|
||||
if len(preds) == 1 and len(preds[0].argtypes) == i:
|
||||
self.is_leaf = True
|
||||
self.pred = preds[0]
|
||||
@ -313,7 +314,7 @@ class DTree(object):
|
||||
d = []
|
||||
dispatch[t.type] = d
|
||||
d.append(p)
|
||||
self.subtrees = tuple((t2,DTree(i+1,p2))
|
||||
self.subtrees = tuple((t2,DTree(i+1,p2,cluster))
|
||||
for t2,p2 in dispatch.iteritems())
|
||||
|
||||
def _generate_body(self, user_vars, lib_vars):
|
||||
@ -325,7 +326,9 @@ class DTree(object):
|
||||
|
||||
def _generate_dispatch(self, i, user_vars, lib_vars):
|
||||
if i == len(self.subtrees):
|
||||
return PrologLiteral("throw(gecode_argument_error)")
|
||||
return PrologLiteral("throw(gecode_argument_error(%s/%d,arg=%d,%s))" \
|
||||
% (self.cluster.name, self.cluster.arity,
|
||||
self.index+1, user_vars[self.index]))
|
||||
typ, dtree = self.subtrees[i]
|
||||
idx = self.index
|
||||
X = user_vars[idx]
|
||||
@ -371,7 +374,7 @@ class YAPConstraintGeneratorBase(PredGenerator):
|
||||
def _dtreefy(self):
|
||||
dtrees = {}
|
||||
for key, cluster in self.clusters.iteritems():
|
||||
dtree = DTree(0, cluster.preds)
|
||||
dtree = DTree(0, cluster.preds, cluster)
|
||||
dtrees[key] = dtree
|
||||
self.dtrees = dtrees
|
||||
|
||||
|
@ -284,7 +284,7 @@ new_setvar(SVar, Space, X1, X2, X3, X4, X5) :-
|
||||
assert_integer(X4),
|
||||
assert_integer(X5),
|
||||
gecode_new_setvar_4(Idx,Space_,X1_,X2,X3,X4,X5)),
|
||||
SVar='SetVar'(Idx).
|
||||
SVar='SetVar'(Idx,-1).
|
||||
|
||||
%% 4 arguments
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax) 4 new_setvar_3
|
||||
@ -313,7 +313,7 @@ new_setvar(SVar,Space,X1,X2,X3,X4) :-
|
||||
;
|
||||
assert_integer(X3),
|
||||
gecode_new_setvar_3(Idx,Space_,X1,X2,X3,X4))),
|
||||
SVar='SetVar'(Idx).
|
||||
SVar='SetVar'(Idx,-1).
|
||||
|
||||
%% 3 arguments
|
||||
%% (Glb,LubMin,LubMax) 3 new_setvar_6
|
||||
@ -336,7 +336,7 @@ new_setvar(SVar,Space,X1,X2,X3) :-
|
||||
assert_integer(X2),
|
||||
assert_is_IntSet(X3,X3_),
|
||||
gecode_new_setvar_9(Idx,Space_,X1,X2,X3_)),
|
||||
SVar='SetVar'(Idx).
|
||||
SVar='SetVar'(Idx,-1).
|
||||
|
||||
%% 2 arguments
|
||||
%% (Glb,Lub) 2 new_setvar_12
|
||||
@ -346,7 +346,7 @@ new_setvar(SVar,Space,X1,X2) :-
|
||||
assert_is_IntSet(X1,X1_),
|
||||
assert_is_IntSet(X2,X2_),
|
||||
gecode_new_setvar_12(Idx,Space_,X1_,X2_),
|
||||
SVar='SetVar'(Idx).
|
||||
SVar='SetVar'(Idx,-1).
|
||||
|
||||
minimize(Space,IVar) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
|
Reference in New Issue
Block a user