Automatically generate results
This commit is contained in:
parent
8eb2e55057
commit
3b0fd8392b
37
Output/a_an_example.out.txt
Normal file
37
Output/a_an_example.out.txt
Normal file
@ -0,0 +1,37 @@
|
||||
36
|
||||
LoadCarrots 12
|
||||
LoadGift Liam
|
||||
AccRight 6
|
||||
Float 1
|
||||
AccLeft 4
|
||||
Float 1
|
||||
AccLeft 2
|
||||
Float 1
|
||||
AccUp 4
|
||||
Float 1
|
||||
AccDown 4
|
||||
Float 1
|
||||
DeliverGift Liam
|
||||
AccDown 4
|
||||
Float 1
|
||||
AccUp 4
|
||||
Float 1
|
||||
AccLeft 6
|
||||
Float 1
|
||||
AccRight 4
|
||||
Float 1
|
||||
AccRight 2
|
||||
Float 1
|
||||
LoadCarrots 12
|
||||
LoadGift Emma
|
||||
AccLeft 6
|
||||
Float 1
|
||||
AccRight 2
|
||||
Float 1
|
||||
AccRight 4
|
||||
Float 1
|
||||
AccUp 1
|
||||
Float 1
|
||||
AccDown 1
|
||||
Float 1
|
||||
DeliverGift Emma
|
1030
Output/b_better_hurry.out.txt
Normal file
1030
Output/b_better_hurry.out.txt
Normal file
File diff suppressed because it is too large
Load Diff
8183
Output/c_carousel.out.txt
Normal file
8183
Output/c_carousel.out.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
Output/d_decorated_houses.out.txt
Normal file
1
Output/d_decorated_houses.out.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
2868
Output/e_excellent_weather.out.txt
Normal file
2868
Output/e_excellent_weather.out.txt
Normal file
File diff suppressed because it is too large
Load Diff
1379
Output/f_festive_flyover.out.txt
Normal file
1379
Output/f_festive_flyover.out.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""HashCode2022_BUG.ipynb
|
||||
|
||||
Automatically generated by Colaboratory.
|
||||
|
||||
Original file is located at
|
||||
https://colab.research.google.com/drive/1PiwWB2bonQgoAGp6woFuJhFi2qq0_aj7
|
||||
"""
|
||||
|
||||
from google.colab import drive
|
||||
drive.mount('/content/drive')
|
||||
|
||||
from math import sqrt
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import os
|
||||
import math
|
||||
|
||||
File_Directory = 'drive/MyDrive/polyhash/DataSet/'
|
||||
File_Name = 'f_festive_flyover.in.txt'
|
||||
File_Path = File_Directory+File_Name
|
||||
|
||||
DataSet = [line.strip().split() for line in open(File_Path, "r")]
|
||||
|
||||
Score:int = 0
|
||||
|
||||
def is_number(s):
|
||||
try:
|
||||
@ -45,12 +23,6 @@ def convertToFloat(DataSet):
|
||||
DataSet[i][j] = float(DataSet[i][j])
|
||||
return DataSet
|
||||
|
||||
|
||||
|
||||
# convert data-set to float
|
||||
DataSet = convertToFloat(DataSet)
|
||||
|
||||
|
||||
def caculateDistance(a: list, b: tuple):
|
||||
d = sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
|
||||
return d
|
||||
@ -115,7 +87,6 @@ class Santa:
|
||||
def getWeight(self):
|
||||
return self.weightOfCarrots + self.weightOfGift
|
||||
|
||||
#[[2000.0, 20.0], [3000.0, 15.0], [5000.0, 10.0], [6000.0, 9.0], [7000.0, 8.0]]
|
||||
def nowSpeedLimit(self):
|
||||
w = self.getWeight()
|
||||
assert w >= 0
|
||||
@ -138,7 +109,7 @@ class Santa:
|
||||
assert self.isAllowedBySpeedLimit(s)
|
||||
self.speed[1] += s
|
||||
self.consumeCarrot()
|
||||
print("AccUp",int(s))
|
||||
print("AccUp",int(s), file=output)
|
||||
else:
|
||||
pass
|
||||
def AccDown(self, s):
|
||||
@ -146,7 +117,7 @@ class Santa:
|
||||
assert self.isAllowedBySpeedLimit(s)
|
||||
self.speed[1] -= s
|
||||
self.consumeCarrot()
|
||||
print("AccDown",int(s))
|
||||
print("AccDown",int(s), file=output)
|
||||
else:
|
||||
pass
|
||||
def AccRight(self, s):
|
||||
@ -154,7 +125,7 @@ class Santa:
|
||||
assert self.isAllowedBySpeedLimit(s)
|
||||
self.speed[0] += s
|
||||
self.consumeCarrot()
|
||||
print("AccRight",int(s))
|
||||
print("AccRight",int(s), file=output)
|
||||
else:
|
||||
pass
|
||||
def AccLeft(self, s):
|
||||
@ -162,7 +133,7 @@ class Santa:
|
||||
assert self.isAllowedBySpeedLimit(s)
|
||||
self.speed[0] -= s
|
||||
self.consumeCarrot()
|
||||
print("AccLeft",int(s))
|
||||
print("AccLeft",int(s), file=output)
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -177,7 +148,7 @@ class Santa:
|
||||
self.weightOfGift -= p.weightOfGift
|
||||
assert self.weightOfGift >= 0
|
||||
p.getScore()
|
||||
print("DeliverGift",p.name)
|
||||
print("DeliverGift",p.name, file=output)
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -186,7 +157,7 @@ class Santa:
|
||||
self.position[0] += self.speed[0] * t
|
||||
self.position[1] += self.speed[1] * t
|
||||
self.timeLimit -= t
|
||||
print("Float",int(t))
|
||||
print("Float",int(t), file=output)
|
||||
else:
|
||||
self.timeLimit -= self.timeLimit
|
||||
|
||||
@ -320,9 +291,9 @@ class Santa:
|
||||
def oneWay(self, p:Person):
|
||||
if self.timeLimit >0:
|
||||
self.LoadCarrots(12)
|
||||
print("LoadCarrots 12")
|
||||
print("LoadCarrots 12", file=output)
|
||||
self.LoadGift(p.weightOfGift)
|
||||
print("LoadGift",p.name)
|
||||
print("LoadGift",p.name, file=output)
|
||||
v = self.nowSpeedLimit()
|
||||
if isinstance(p.x_position/v,int) and p.x_position > 0 :
|
||||
t = p.x_position/v
|
||||
@ -429,22 +400,56 @@ class Santa:
|
||||
elif p.x_position == 0 :
|
||||
self.kidoneWay(p.y_position,p)
|
||||
|
||||
s = Santa()
|
||||
|
||||
s.speedLimitTable
|
||||
|
||||
pp = People()
|
||||
def line_prepender(f, line):
|
||||
content = f.read()
|
||||
f.seek(0, 0)
|
||||
f.write(line.rstrip('\r\n') + '\n' + content)
|
||||
|
||||
pp.info[0]
|
||||
|
||||
pp.visualization()
|
||||
File_Directory = 'DataSet/'
|
||||
Output_File_Directory = 'Output/'
|
||||
files = os.listdir(File_Directory)
|
||||
out_files = os.listdir(Output_File_Directory)
|
||||
|
||||
s.generateTableauDeDistribution(pp)
|
||||
for File_Name in files:
|
||||
|
||||
File_Path = File_Directory+File_Name
|
||||
Output_File_Path = Output_File_Directory+File_Name.replace("in", "out")
|
||||
DataSet = [line.strip().split() for line in open(File_Path, "r")]
|
||||
DataSet = convertToFloat(DataSet)
|
||||
|
||||
for i in s.generateTableauDeDistribution(pp):
|
||||
s.oneWay(i)
|
||||
Score:int = 0
|
||||
s = Santa()
|
||||
pp = People()
|
||||
s.generateTableauDeDistribution(pp)
|
||||
|
||||
s.getSituation()
|
||||
|
||||
Score
|
||||
output = open(Output_File_Path, "w+")
|
||||
|
||||
try:
|
||||
for i in s.generateTableauDeDistribution(pp):
|
||||
s.oneWay(i)
|
||||
except:
|
||||
print("Error in this dataset", file=output)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
def line_prepender(filename, line):
|
||||
with open(filename, 'r+') as f:
|
||||
content = f.read()
|
||||
f.seek(0, 0)
|
||||
f.write(line.rstrip('\r\n') + '\n' + content)
|
||||
|
||||
# count Action
|
||||
for out_file in out_files:
|
||||
Output_File_Path = Output_File_Directory + out_file
|
||||
count = 0
|
||||
with open(Output_File_Path, 'r') as fp:
|
||||
for count, line in enumerate(fp):
|
||||
pass
|
||||
print(out_file, count + 1)
|
||||
line_prepender(Output_File_Path, str(count+1))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user