Basic Solution

This commit is contained in:
MAO Dongyang 2023-01-14 19:12:41 +00:00
parent 3b0fd8392b
commit 66964953a8
2 changed files with 456 additions and 257 deletions

View File

@ -1 +1,186 @@
1
LoadCarrots 12
LoadGift Nelly9621
AccRight 1
Float 1
AccLeft 1
Float 1
AccLeft 1
Float 1
AccRight 1
Float 1
LoadCarrots 12
LoadGift Stefan1846
AccRight 1
Float 1
AccLeft 1
Float 1
AccDown 1
Float 1
AccUp 1
Float 1
AccUp 1
Float 1
AccDown 1
Float 1
AccLeft 1
Float 1
AccRight 1
Float 1
LoadCarrots 12
LoadGift Stepan6060
AccRight 1
Float 1
AccLeft 1
Float 1
AccUp 1
Float 1
AccDown 1
Float 1
AccDown 1
Float 1
AccUp 1
Float 1
AccLeft 1
Float 1
AccRight 1
Float 1
LoadCarrots 12
LoadGift Clement2007
AccLeft 1
Float 1
AccRight 1
Float 1
AccDown 1
Float 1
AccUp 1
Float 1
AccUp 1
Float 1
AccDown 1
Float 1
AccRight 1
Float 1
AccLeft 1
Float 1
LoadCarrots 12
LoadGift Matas6172
AccRight 2
Float 1
AccLeft 2
Float 1
AccUp 2
Float 1
AccDown 2
Float 1
AccDown 2
Float 1
AccUp 2
Float 1
AccLeft 2
Float 1
AccRight 2
Float 1
LoadCarrots 12
LoadGift Petar5664
AccRight 2
Float 1
AccLeft 2
Float 1
AccLeft 2
Float 1
AccRight 2
Float 1
LoadCarrots 12
LoadGift Matas2180
AccLeft 2
Float 1
AccRight 2
Float 1
AccDown 2
Float 1
AccUp 2
Float 1
AccUp 2
Float 1
AccDown 2
Float 1
AccRight 2
Float 1
AccLeft 2
Float 1
LoadCarrots 12
LoadGift Przemek1941
AccLeft 1
Float 1
AccRight 1
Float 1
AccUp 2
Float 1
AccDown 2
Float 1
AccDown 2
Float 1
AccUp 2
Float 1
AccRight 1
Float 1
AccLeft 1
Float 1
LoadCarrots 12
LoadGift Tatiyana4230
AccRight 2
Float 1
AccLeft 2
Float 1
AccDown 1
Float 1
AccUp 1
Float 1
AccUp 1
Float 1
AccDown 1
Float 1
AccLeft 2
Float 1
AccRight 2
Float 1
LoadCarrots 12
LoadGift Michal5548
AccUp 2
Float 1
AccDown 2
Float 1
AccDown 2
Float 1
AccUp 2
Float 1
LoadCarrots 12
LoadGift Przemek4289
AccRight 3
Float 1
AccLeft 3
Float 1
AccDown 2
Float 1
AccUp 2
Float 1
AccUp 2
Float 1
AccDown 2
Float 1
AccLeft 3
Float 1
AccRight 3
Float 1
LoadCarrots 12
LoadGift Max1879
AccUp 4
Float 1
AccDown 4
Float 1
AccDown 4
Float 1
AccUp 4
Float 1
LoadCarrots 12
LoadGift Przemek4984

View File

@ -2,6 +2,7 @@ from math import sqrt
import matplotlib.pyplot as plt
import os
def is_number(s):
try:
float(s)
@ -16,6 +17,7 @@ def is_number(s):
pass
return False
def convertToFloat(DataSet):
for i in range(len(DataSet)):
for j in range(len(DataSet[i])):
@ -23,10 +25,12 @@ def convertToFloat(DataSet):
DataSet[i][j] = float(DataSet[i][j])
return DataSet
def caculateDistance(a: list, b: tuple):
d = sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
return d
def readLine(m=0, n=2, offset=1):
global DataSet
lenth = int(DataSet[m][n])
@ -35,8 +39,10 @@ def readLine(m = 0, n = 2, offset = 1):
line.append(DataSet[i + offset])
return line
class Person:
priority: float
def __init__(self, infomationLine):
self.name, self.score, self.weightOfGift, self.x_position, self.y_position = infomationLine
@ -53,6 +59,7 @@ class Person:
class People:
info = []
def __init__(self):
global DataSet
line = readLine(m=0, n=3, offset=1 + int(DataSet[0][2]))
@ -75,6 +82,7 @@ class Santa:
speed = [0.0, 0.0]
weightOfCarrots: int = 0
weightOfGift: int = 0
def __init__(self):
global DataSet
self.timeLimit = int(DataSet[0][0])
@ -95,8 +103,8 @@ class Santa:
return self.speedLimitTable[i][1]
return 0
# DONE 此速度限制speedLimit为限制表不是当前限制我们下一步要定义nowspeedLimit
def isAllowedBySpeedLimit(self, s):
return s <= self.nowSpeedLimit()
@ -112,6 +120,7 @@ class Santa:
print("AccUp", int(s), file=output)
else:
pass
def AccDown(self, s):
if self.timeLimit > 0:
assert self.isAllowedBySpeedLimit(s)
@ -120,6 +129,7 @@ class Santa:
print("AccDown", int(s), file=output)
else:
pass
def AccRight(self, s):
if self.timeLimit > 0:
assert self.isAllowedBySpeedLimit(s)
@ -128,6 +138,7 @@ class Santa:
print("AccRight", int(s), file=output)
else:
pass
def AccLeft(self, s):
if self.timeLimit > 0:
assert self.isAllowedBySpeedLimit(s)
@ -139,12 +150,14 @@ class Santa:
def LoadCarrots(self, w):
self.weightOfCarrots += w
def LoadGift(self, w):
self.weightOfGift += w
def DiliveryGift(self, p: Person):
if self.timeLimit >= 0 and caculateDistance(self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit:
assert caculateDistance(self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit
assert caculateDistance(
self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit
self.weightOfGift -= p.weightOfGift
assert self.weightOfGift >= 0
p.getScore()
@ -168,13 +181,11 @@ class Santa:
print("Now weightOfGift is:", self.weightOfGift)
print("Now weightOfCarrots is:", self.weightOfCarrots)
def generateTableauDeDistribution(self, pp: People):
self.tableauDeDistribution = sorted(pp.info, key=lambda x: x.caculatePriority(), reverse=True)
self.tableauDeDistribution = sorted(
pp.info, key=lambda x: x.caculatePriority(), reverse=True)
return self.tableauDeDistribution
def kidoneWay(self, x: int, p: Person):
v = self.nowSpeedLimit()
if isinstance(x/v, int) and x > 0:
@ -193,7 +204,6 @@ class Santa:
self.AccUp(v)
self.Float(1)
elif isinstance(x/v, int) and x < 0:
t = abs(x)/v
self.AccDown(v)
@ -310,7 +320,6 @@ class Santa:
self.AccRight(v)
self.Float(1)
elif isinstance(p.x_position/v, int) and p.x_position < 0:
t = abs(p.x_position)/v
self.AccLeft(v)
@ -401,7 +410,6 @@ class Santa:
self.kidoneWay(p.y_position, p)
def line_prepender(f, line):
content = f.read()
f.seek(0, 0)
@ -413,6 +421,7 @@ Output_File_Directory = 'Output/'
files = os.listdir(File_Directory)
out_files = os.listdir(Output_File_Directory)
print('------------------Score--------------------------------')
for File_Name in files:
File_Path = File_Directory+File_Name
@ -425,17 +434,22 @@ for File_Name in files:
pp = People()
s.generateTableauDeDistribution(pp)
output = open(Output_File_Path, "w+")
output = open(Output_File_Path, "w")
try:
for i in s.generateTableauDeDistribution(pp):
s.oneWay(i)
except:
print("Error in this dataset", file=output)
# print("Error in this dataset", file=output)
pass
else:
pass
print(File_Name, Score)
print('-------------------how many line in output file---------------')
def line_prepender(filename, line):
with open(filename, 'r+') as f:
@ -443,6 +457,7 @@ def line_prepender(filename, line):
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
@ -452,4 +467,3 @@ for out_file in out_files:
pass
print(out_file, count + 1)
line_prepender(Output_File_Path, str(count+1))