-
Notifications
You must be signed in to change notification settings - Fork 22
/
amoeba_test.lua
79 lines (72 loc) · 1.36 KB
/
amoeba_test.lua
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
78
79
local amoeba = require "amoeba"
local S = amoeba.new()
print(S)
local xl, xm, xr =
S:var "xl", S:var "xm", S:var "xr"
print(xl)
print(xm)
print(xr)
print(S:constraint()
:add(xl):add(10)
:relation "le" -- or "<="
:add(xr))
S:addconstraint((xm*2) :eq (xl + xr))
S:addconstraint(
S:constraint()
:add(xl):add(10)
:relation "le" -- or "<="
:add(xr)) -- (xl + 10) :le (xr)
S:addconstraint(
S:constraint()(xr) "<=" (100)) -- (xr) :le (100)
S:addconstraint((xl) :ge (0))
print(S)
print(xl)
print(xm)
print(xr)
print('suggest xm to 0')
S:suggest(xm, 0)
print(S)
print(xl)
print(xm)
print(xr)
print('suggest xm to 70')
S:suggest(xm, 70)
print(S)
print(xl)
print(xm)
print(xr)
print('delete edit xm')
S:deledit(xm)
print(S)
print(xl)
print(xm)
print(xr)
--speed test
local now = require'time'.clock
local S = amoeba.new()
local vars = {}
for i=1,20 do
vars[i] = S:var('x'..i)
end
for i=1,20 do
local c = S:constraint():add(vars[i]):relation(i < 20 and '>=' or '<='):add(1)
if i > 1 then
c:add(vars[i-1])
end
S:addconstraint(c)
print(c)
end
local n = 100000
print(('\nstarting benchmark (%d iterations)'):format(n))
local start = now()
S:suggest(vars[20], 0)
for i = 1, n do
S:suggest(vars[1], i)
end
print(vars[1])
print(vars[2])
print(vars[19])
print(vars[20])
local stop = now()
--print(S)
print(('solved in %fms'):format((stop-start)*1000/n))