-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vehicle.py
107 lines (98 loc) · 3.54 KB
/
Vehicle.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
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
__author__ = 'TriNguyenDang'
import matplotlib.pyplot as plt
import numpy as np
from ManagerPrefer import *
from Prefer import *
from Location import *
import random
from Ascending import *
#from Slot import *
class Vehicle:
ID = None
Destination = None
ParkingTime = None
ListPrefer = None
Matched = None
Cost = None
def __init__(self,Lists):
self.ID = Lists[0]
self.Destination = Lists[1]
self.ParkingTime = Lists[2]
self.ListPrefer = Lists[3]
self.Matched = Lists[4]
self.Cost = Lists[5]
#randomize data using Poison distribution
@staticmethod
def InitVehicle(Type):
if(Type == 'A'):
Destination = Location(XD,YD)
elif(Type == 'B'):
Destination = Location(XD,-YD)
elif(Type == 'C'):
Destination = Location(-XD,YD)
elif(Type == 'D'):
Destination = Location(-XD,-YD)
else:
Destination = Location.InitDestination()
TmpA = Location.InitLocation()
while(-LOW_BOUND<=TmpA[X])and(TmpA[X]<=LOW_BOUND)and(-SUP_BOUND<=TmpA[Y])and(TmpA[Y]<=SUP_BOUND):
TmpA = Location.InitLocation()
TmpT = random.uniform(CONST_SUP_TIME,CONST_INF_TIME)
TmpP = ManagerPrefer()
TmpM = Location(0,0)
TmpC = 0
return TmpA,Destination,TmpT,TmpP,TmpM,TmpC
def __str__(self):
return "ID: %s\t Des: %s\tTime: %s\t Pre: %s\t M:%s\t C:%s"%(self.ID,self.Destination,self.ParkingTime,self.ListPrefer,self.Matched,self.Cost)
def __repr__(self):
return "\n<ID: %s\t Des %s\t Time: %s\t Pre: %s\t M: %s\t C: %s>\n"%(self.ID,self.Destination,self.ParkingTime,self.ListPrefer,self.Matched,self.Cost)
def __getitem__(self, item):
if(item == ID):
return self.ID
elif(item == D):
return self.Destination
elif(item == PT):
return self.ParkingTime
elif(item == M):
return self.Matched
elif(item == C):
return self.Cost
elif(item == P):
return self.ListPrefer
def __setitem__(self, key, value):
if(key == ID):
self.ID = value
elif(key == D):
self.Destination = value
elif(key == PT):
self.ParkingTime = value
elif(key == P):
self.ListPrefer = value
elif(key == M):
self.Matched = value
elif(key == C):
self.Cost = value
def CalculatePrefer(self,Parking,Destination):
TmpP = ManagerPrefer()
for Slot in Parking['SlotList']:
TmpLocation = Slot[ID]
TmpCost = Slot[F]*self[PT] + CONST_COST_DRIVING*(self[ID] - Slot[ID])/10 + CONST_COST_WALKING*(Slot[ID] - Destination)/10
TmpP.add(Prefer(TmpLocation,TmpCost))
Ascending(TmpP.ListPrefer)
self[P] = TmpP
'''
def CalculatePrefer(self,ListSlot,Destination,Type):
tmp = ManagerPrefer()
for subSlot in ListSlot:
tmpLocation = subSlot[ID]
tmpCost = subSlot[F]*self[PT] + CONST_COST_DRIVING * (self[ID] - subSlot[ID])/10 + CONST_COST_WALKING*(Destination - subSlot[ID])/10
tmp.add(Prefer(tmpLocation,tmpCost))
if(Type == AS):
ManagerPrefer.QuickSort(tmp.ListPrefer)
elif(Type == DS):
ManagerPrefer.QuickSort2(tmp.ListPrefer)
self[P] = tmp
'''
def DrawMatched(self,Color,Marker):
plt.plot([self['ID']['X'],self['Matched']['X']],[self['ID']['Y'],self['Matched']['Y']],color = Color,marker = Marker)
pass