-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIntegerPoints.txt
77 lines (73 loc) · 1.76 KB
/
IntegerPoints.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
IntegerPoints := proc (SN::{list, set}, Var::list)
local SN1, sn, n, Sol, k, i, s, S, R;
SN1 := convert(evalf(SN), fraction);
for sn in SN1 do
if type(sn, `<`) then
SN1 := subs(sn = (`<=`(op(sn))), SN1):
end if:
end do;
if PolyhedralSets:-IsBounded(PolyhedralSets:-PolyhedralSet(SN1)) = false then
error "The region should be bounded"
end if;
n := nops(Var);
# print(SN,Var);
Sol := SolveTools[Inequality][LinearMultivariateSystem](SN, Var);
if Sol = {} then
return {}
else
k := 0;
for s in Sol do
if nops(indets(s[1])) = 1 then
S[0] := [[]];
for i to n do
S[i] := [seq(seq([op(j1), op(j2)], j2 = [isolve(eval(s[i], j1))]), j1 = S[i-1])]:
end do;
k := k+1;
R[k] := op(S[n]):
end if:
end do;
convert(R, set);
map(proc (t) options operator, arrow; `~`[rhs](t) end proc, %) :
end if:
end proc;
IntegerPoints1 := proc (SN::{list, set}, Var::list)
local SN1, sn, n, i, p, q, xl, xr, Xl, Xr, X, T, k, t, S;
uses combinat:
SN1 := SN:
for sn in SN1 do
if type(sn, `<`) then
SN1 := subs(sn = (`<=`(op(sn))), SN1):
fi;
od;
n := nops(Var);
for i to n do
p := simplex[minimize](Var[i], SN1); q := simplex[maximize](Var[i], SN1):
if p = {} or q = {} then
return {}:
else
if p = NULL or q = NULL then
error "The region should be bounded":
else
xl[i] := eval(Var[i], p):
xr[i] := eval(Var[i], q):
fi:
fi:
od:
Xl := ceil~(convert(xl, list)); Xr := floor~(convert(xr, list)):
X := [seq([$ Xl[i] .. Xr[i]], i = 1 .. n)]:
T := cartprod(X):
k := 0:
while not T[finished] do
t := T[nextvalue]():
if convert(eval(SN, Var=~t), `and`) then
k := k+1:
S[k] := t:
fi:
od:
S := convert(S, set):
if type(S, set(list)) then
S:
else
{}:
fi:
end proc: