-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbatch.py
57 lines (44 loc) · 1.64 KB
/
batch.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
from importers.importer import Importer
from logic.world import World
from logic.serializer import Serializer
import time
def calculateFleet(fleet, inheritedFleet):
for i in range(len(fleet['names'])):
fleet['count'][i] += inheritedFleet[i]
return fleet
SIMPLE_MODE = True
BATCHES_SIZE = 6
importer = Importer('test', '-2013-02-01', 'DC', SIMPLE_MODE, BATCHES_SIZE)
data = importer.process()
serializer = Serializer()
batchesToRetry = []
start = time.time()
for i in range(len(data['cities'])):
print 'BATCH #' + str(i + 1) + ' out of ' + str(len(data['cities']))
if i > 0:
if result != -1:
fleet = calculateFleet(data['fleets'][i], serializer.trucksLeft(world))
fleet = data['fleets'][i]
else:
fleet = data['fleets'][i]
serializer.listFleet(data['fleets'][i])
serializer.listCities(data['cities'][i], data['demands'][i])
world = World(data['cities'][i], data['demands'][i], data['distances'][i], fleet)
result = world.compute(SIMPLE_MODE)
if result == -1:
batchesToRetry.append(i)
else:
serializer.add(world)
for i in batchesToRetry:
print 'RETRY BATCH #' + str(i + 1) + ' out of ' + str(len(batchesToRetry))
fleet = calculateFleet(data['fleets'][i], serializer.trucksLeft(world))
serializer.listFleet(data['fleets'][i])
serializer.listCities(data['cities'][i], data['demands'][i])
world = World(data['cities'][i], data['demands'][i], data['distances'][i], fleet)
result = world.compute(SIMPLE_MODE)
if result == -1:
'PRINT UNABLE TO SOLVE IT :(('
else:
serializer.add(world)
serializer.explain()
print 'FINISHED after {0:.02f}s (BATCH SIZE: {1})'.format(time.time() - start, BATCHES_SIZE)