-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyhash.py
More file actions
executable file
·113 lines (101 loc) · 3.75 KB
/
polyhash.py
File metadata and controls
executable file
·113 lines (101 loc) · 3.75 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import sys
import inspect
from scipy.spatial import distance
import math
from model import cadeau,groupe, heatMap, chemin, boucle, parcoursFinal,traineau,accelerationCalculator, rangeCalculator
import fileParser
challenge = input("nom du fichier d'entrée")
#chargement du challenge
(cadeaux, secondes, reachRange, accCalculator) = fileParser.parseChallenge(challenge)
r = rangeCalculator(reachRange)
heatmap = heatMap(r,cadeaux)
parcoursFinal = parcoursFinal()
maxValRegion = 0
while (secondes > 0 and maxValRegion != -math.inf):
# on détermine la valeur de chaque région
# on prend la région avec la plus grande valeur
maxValRegion = -math.inf
maxRegion = None
for row in heatmap.regions:
for region in row:
#TODO : raffiner l'algo de décision
if(region.getScore() == 0):
val = -math.inf
else:
val = region.getPoids() * -20 + region.getScore()*100 -(distance.euclidean([0,0],[(region.maxX + region.minX) / 2, (region.maxY + region.minY) / 2 ] )//15)** 2
if(val > maxValRegion):
maxValRegion = val
maxRegion = region
# pour cette région on prend le meilleur point
if(maxRegion != None):
bcl = boucle()
previousGroup = groupe(0,0)
maxValGroupe = 0
while(maxValGroupe != -math.inf):
maxValGroupe = -math.inf
maxGroup = groupe(0,0)
groups = maxRegion.getGroups()
for row in groups:
for group in row:
score = group.getScore()
if(score == 0 or (group.positionX == 0 and group.positionY == 0) or group.delivre == True):
val = -math.inf
else:
val = score*10 - group.getPoids()*2
if(val > maxValGroupe):
maxValGroupe = val
maxGroup = group
# a partir de ce meilleur point on essaie de mettre a jour le parcours, d'abbord
cheminRetour = chemin(maxGroup,previousGroup,r,accCalculator,bcl.getPoids())
cheminAller = chemin(groupe(0,0),maxGroup,r,accCalculator,bcl.getPoids() + cheminRetour.carotteConsommes + maxGroup.getPoids())
#print(str(bcl))
if(secondes - (bcl.getTempsConsomme() + cheminRetour.tempsConsomme + cheminAller.tempsConsomme) >= 0 and maxValGroupe != -math.inf):
previousGroup = maxGroup
if(len(bcl.chemins) != 0):
pop = bcl.chemins.pop(0)
bcl.chemins.insert(0,cheminRetour)
bcl.chemins.insert(0,cheminAller)
for cadeau in maxGroup.cadeaux:
if(not cadeau.enTransport):
cadeau.enTransport = True
else:
maxGroup.delivre = True
for cadeau in maxGroup.cadeaux:
cadeau.delivre = True
print("---",secondes,bcl.getPoids(),bcl.getScore(),len(bcl.chemins))
if(secondes - bcl.getTempsConsomme() >= 0):
parcoursFinal.boucles.append(bcl)
secondes = secondes - bcl.getTempsConsomme()
lastGroup = groupe(0,0)
for c in bcl.chemins:
#print("(",c.begining.positionX,c.begining.positionY,")->(",c.end.positionX,c.end.positionY,")")
if(c.begining.positionX != lastGroup.positionX or c.begining.positionY != lastGroup.positionY):
raise RuntimeWarning("chemin non cohérent")
lastGroup = c.end
c.move()
for cadeau in c.end.cadeaux:
if(not cadeau.delivre):
bcl.loadingActions.append(["LoadGift",cadeau.nom])
#print(str(cadeau),end="")
cadeau.delivre = True
carrotCount = bcl.getCarotteConsommes()
if(carrotCount > 0):
bcl.loadingActions.append(["LoadCarrots",carrotCount])
else:
for c in bcl.chemins:
c.move()
for cadeau in c.end.cadeaux:
cadeau.delivre = True
print("----------------")
print(secondes)
with open("test.out.txt", 'w') as a_fichier:
contenu = a_fichier.write(str(parcoursFinal))
import os
import sys
import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
import scorer
print(scorer.score(challenge,"test.out.txt"))