-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (60 loc) · 2.24 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
import numpy
import scipy
import matplotlib.pyplot as plt
class Optimize():
def __init__(self):
self.size_grid = []
self.pieces = []
self.forbidden = []
self.penalty = []
self.loss = []
input_data = (open('Problems/Problem1.txt', "r").read()).split('\n')
self.size_grid = map(int, input_data[1].split(' '))
for i in range(3, input_data.index('FORBIDDEN')):
self.pieces.append(input_data[i].split(' '))
for i in range(input_data.index('FORBIDDEN') + 1, input_data.index('PENALTY')):
self.forbidden.append(input_data[i].split(','))
for i in range(input_data.index('PENALTY') + 1, len(input_data)-1):
self.penalty.append(input_data[i].split(','))
for i in range(len(self.penalty)):
self.loss.append(self.penalty[i][0].split(' ')[0])
self.loss.append(self.penalty[i][0].split(' ')[1])
def validate(self):
print(self.size_grid)
print(self.pieces)
print(self.forbidden)
print(self.loss)
def grid(self):
grid = numpy.zeros([self.size_grid[0], self.size_grid[1]])
print(grid)
def rank(self):
rank = []
obj = []
for i in range(len(self.pieces)):
rank.append(self.loss.count(self.pieces[i][0]))
obj.append(self.pieces[i][0])
zipped_pairs = zip(rank, obj)# fig = plt.figure()
z = [x for _, x in sorted(zipped_pairs)]
return z
def box(self):
grid = numpy.zeros([self.size_grid[0], self.size_grid[1]])
return grid
def plot(self):
plt.xlim(0 ,self.size_grid[0])
plt.ylim(0 ,self.size_grid[1])
plt.xticks([i for i in range(self.size_grid[0])])
plt.yticks([j for j in range(self.size_grid[1])])
plt.grid(color = 'b', linewidth = 1.5)
plt.title("The visulaization of pieces arrangment")
plt.show()
def shape(self):
piece = self.rank()
print(piece)
shape = []
for i in range(len(piece)):
for j in range(len(self.pieces)):
if piece[i]==self.pieces[j][0]:
shape.append(self.pieces[i][1])
return shape
if __name__ == "__main__":
Optimize().plot()