forked from ML2R-center/autumn2021-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmpl05.py
executable file
·58 lines (34 loc) · 1.15 KB
/
xmpl05.py
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
#
# script demonstrates brute force search of possible packings
#
# NOTE: ths script will write 234 PNG images to disk
#
import sys
sys.path.append('./Base')
from bp2DBase import *
from bp2DData import *
from bp2DPlot import *
from bp2DState import *
from bp2DAction import *
def initialize_state(rcts, BOX):
rcts = Rectangle2D.place_rectangles_at_point(rcts, Point2D(-1, -1))
rcts_clsd = []
rcts_open = rcts
pnts_open = [Point2D(0,0)]
return State(rcts_clsd, rcts_open, pnts_open, BOX)
stateCounter = 0
def brute_force_search_all_feasible(S):
global stateCounter
stateCounter += 1
actions = [Action(p,r) for p in S.pnts_open for r in S.rcts_open]
for A in actions:
if A.is_feasible(S):
S_new = A.apply_to(S)
fName = 'figXmpl05-trial-%d.png' % stateCounter
S_new.plot(fname=fName)
brute_force_search_all_feasible(S_new)
if __name__ == '__main__':
BOX = Rectangle2D(10, 10, Point2D(0, 0))
rcts = example2()
S = initialize_state(rcts, BOX)
brute_force_search_all_feasible(S)