示例#1
0
def main():
    Test()
    uus = car("Olaa", 20)
    print("|----------------|")
    print(uus.get_col)
    print("|----------------|")
    print(uus.get_txt)
    print("|----------------|")
示例#2
0
 def run(self):
     d = Data()
     self.data = d.getData()
     m = map(self.data)
     self.edges = m.getEdges()
     c = car(self.data[0])
     f = fuzzy()
     Y = c.getPosition()
     while(Y[1] < 43):
         self.mapping(self.edges)
         self.draw_car(c.getPosition())
         c.sensor(self.edges)
         F, L, R = c.getDistance()
         self.front_value = tk.Label(windows, text= str(F)).grid(row=2,column=1, sticky=tk.W+tk.E)
         self.left_value = tk.Label(windows, text= str(L)).grid(row=3,column=1, sticky=tk.W+tk.E)
         self.right_value = tk.Label(windows, text= str(R)).grid(row=4,column=1, sticky=tk.W+tk.E)
         c.setWheel(f.system(F, L, R))
         c.update_car_direction()
         c.update_car_pos()
         self.result_figure.clear()
示例#3
0
def runner(Total_Spots,base,avg,avg_start,
           start_dev,base_dev=.002,inc_dev=.002):
    """(Total_Spots,base%,totalavg%,base std=.002,increment std=.002"""
    
    random.seed()
    
    #initalize variables
    no_init = 0
    allc = 0
    total = []
    spot_que = []
    wait_que = []
    timer = 0
    incz = 0
    values = []
    wait_time = []
    total_wait = []

    #average and sigma for taking a spot
    wait_mu = 20*60
    wait_sig = 4*60
    
    
    increment = random.gauss((2*(avg-base)),inc_dev)/5400
    base = random.gauss(base,base_dev)
    
    attempt_prob = base

    #print(base) #debug
    
    #Initialize parking lot to values assigned in function call and assign
    #to no_init for analysis
    no_init = int(random.gauss(avg_start,start_dev))
    for i in range(0, no_init):
        spot_que.append(car(random.gauss(wait_mu,wait_sig)))
                   
    while timer <= 10800:

        #assign a value to attempt_prob variable for this iteration
        #attempt_prob = random.gauss(0,1)

        
        if timer <= 5400:  #<= 5400: 
            #increase value mu by increment value until *12:30 PM
            attempt_prob = attempt_prob + increment

    
        else: #elif timer > (peak + peak_width):
            #bring value mu back down to levels started at
            attempt_prob = attempt_prob - increment
            
     
     
        if (attempt_prob > random.uniform(0,1)):
            allc = allc + 1

            #A car wants a spot so if there is room then put it in the lot
            if len(spot_que) < Total_Spots:
                #assign the car a random time before it leaves and add it to lot
                spot_que.append(car(random.gauss(wait_mu,wait_sig)))
                total.append(1)

                #If there is more room and more cars wanting spots
                #get the number and add them to lot
                i = Total_Spots - len(spot_que) 
                for k in range(0,i):

                    #only add them if they are waiting for a spot
                    if len(wait_que) > 0:
                        
                        #grab the amount of time they waited 
                        wait_time.append( wait_que[0].get_time())
                        #remove them from the wait_que
                        wait_que.pop(0)
                        
                        spot_que.append(car(random.gauss(wait_mu,wait_sig)))
                        total.append(1)
                        
            #If no spots available car is now driving around for a spot
            else:
                wait_que.append(wait())
                total_wait.append(1)
       
        #Go through cars currently parked in lot
        for j in spot_que:
            #if timer is above 0, decrement timer
            if j.get_time() > 0:
                j.det_time()

            #if timer == 0 remove car from spot    
            else:
                spot_que.remove(j)

                #Since a car left, if there are cars waiting for a spot
                #add them to the lot
                if len(wait_que) > 0:
                    wait_time.append( wait_que[0].get_time())
                    wait_que.pop(0)
                    spot_que.append(car(random.gauss(wait_mu,wait_sig)))
                    total.append(1)
                    
        #For all the cars now waiting for a spot, incremement their timers            
        for i in wait_que:
            i.inc_time()
        """  
        print("Time: {}".format(timer))
        print("Spots taken: {}".format(len(spot_que)))
        print("Cars waiting: {}".format(len(wait_que)))
        
        if timer == 10800:
            print("Total cars: {}".format(len(total)))
            print("Total waiting: {}".format(len(total_wait)))
            print("Total time spent waiting: {}".format(sum(wait_time)))
            if len(total_wait) > 0:
                print("Average wait time: {} seconds".format(sum(wait_time)/len(total_wait)))
                print("Max wait time: {} seconds.".format(max(wait_time)))
        """        
        timer = timer + 1

    if len(total_wait) > 0:    
        return([len(total),len(total_wait),(sum(wait_time)/len(total_wait)),
                max(wait_time),len(wait_que),allc,no_init])
    else:
        return([len(total),len(total_wait),0, 0,0,allc,no_init])
示例#4
0
 def run(self):
     data4D = open("data/RBFN_params.txt", 'w+')
     d = Data()  #new object of selected data
     self.data = d.getData()
     if (self.file_name == 'data/train4dAll.txt'):
         x, y = d.getTrainData4d()
     elif (self.file_name == 'data/train6dAll.txt'):
         x, y = d.getTrainData6d()
     else:
         x, y = d.getTrainData4d()
     #normalize training data
     x = d.normalize_input(x)
     y = d.normalize_Y(y)
     #get input parameters
     cross_rate = float(self.e4.get())
     mutation_rate = float(self.e3.get())
     pop_size = int(self.e2.get())
     iterations = int(self.e1.get())
     if (self.file_name != 'data/RBFN_params.txt'):
         #training weight --start--
         rbf = RBF(3, 50, 1)  #new object of RBFN
         x_dim, w, centers, beta = rbf.get_parameter()
         ga = genetic(len(x), cross_rate, mutation_rate, pop_size, x_dim, x,
                      y, w, centers, beta)  #new object of ga
         temp = 100
         for i in range(0, iterations):
             fitness = ga.F()
             best_idx = np.argmin(fitness)
             if (fitness[best_idx] < temp):
                 temp = fitness[best_idx]
                 best_DNA = ga.get_best_DNA(best_idx)
                 ga.update(best_DNA)
         #training weight --end--
         ga.w, ga.centers, ga.beta = ga.get_data()
         rbf.set_parameter(ga.w, ga.centers, ga.beta)
         rbf.train(x, y)
         z1 = rbf.predict(x, rbf.get_weight())
         y = d.inverse_normalize_Y(y)
         z = d.inverse_normalize_Y(z1)
         dim, output_W, output_centers, output_beta = rbf.get_parameter()
         for i in range(0, len(output_W)):  #save trained parameters
             print(str(output_W[i][0]),
                   str(output_centers[i][0]),
                   str(output_centers[i][1]),
                   str(output_centers[i][2]),
                   str(output_beta[i][0]),
                   file=data4D)
         data4D.close()
     else:
         load_w, load_centers, load_beta = d.load_parameters()
         rbf = RBF(3, len(load_centers), 1)
         rbf.set_parameter(load_w, load_centers, load_beta)
     m = map(self.data)  #new object of map
     self.edges = m.getEdges()
     c = car(self.data[0])  #new object of car
     Y = c.getPosition()  #get the position of car
     self.mapping(self.edges)
     while (Y[1] < 43):
         self.draw_car(c.getPosition())  #draw car on the window
         c.sensor(self.edges)  #calculate the distane of front, left, right
         F, R, L = c.getDistance()
         input_x = []
         if (self.file_name == 'data/train4dAll.txt'):
             input_x.append([F, R, L])
         elif (self.file_name == 'data/train6dAll.txt'):
             pos = c.getPosition()
             input_x.append([pos[0], pos[1], F, R, L])
         else:
             input_x.append([F, R, L])
         input_x = np.array(input_x)
         input_x = d.normalize_input(input_x)
         wheel = rbf.predict(input_x,
                             rbf.get_weight())  #predict the degree of wheel
         wheel = d.inverse_normalize_Y(wheel)
         if wheel < -40:
             wheel = -40
         elif wheel > 40:
             wheel = 40
         c.setWheel(wheel)
         c.update_car_direction()
         c.update_car_pos()
示例#5
0
dimImprevisto = larghezzaSchermo / 20
SCRITTA_MACCHINA = "3CLSA"
SCRITTA_MEZZERIA = "CDS.18"
MAXSPEED = 12

altezzaStriscia = 500
larghezzaStriscia = 800

mezzeria = mezz(0, 1, speed, larghezzaStriscia, altezzaStriscia,
                SCRITTA_MEZZERIA)
ListaImpr = []
imprevisto = Imprevisti(speed, dimImprevisto, larghezzaSchermo, altezzaSchermo)
ListaImpr.append(imprevisto)
punteggio = Scritte('0', 'black', 18)

macchina = car(10, 10, speed * 2, 1, 50, SCRITTA_MACCHINA)
fineGioco = 0


def setup():
    size(larghezzaSchermo, altezzaSchermo)
    for impr in ListaImpr:
        impr.createNewImprevisto()
    punteggio.setPos(larghezzaSchermo / 2, 15)
    frameRate(30)


def draw():
    global fineGioco

    background(255)
示例#6
0
文件: __init__.py 项目: Anon-LeoH/MCM
 def __init__(self, _id, road, test_type):
     self._id = _id
     self.road = road
     self.journey = 0
     
     Probability = random.random()
     if Probability < 0.7:
         self.type = TYPE[0]
     elif Probability < 0.85:
         self.type = TYPE[1]
     elif Probability < 0.99:
         self.type = TYPE[2]
     else:
         self.type = TYPE[3]
     safeLineError = random.normalvariate(0, 4)
     if abs(safeLineError) > 8:
         safeLineError = safeLineError / abs(safeLineError) * 8
     self.safeLine = self.basicSafeLine = 20 + safeLineError + delta[self.type][2]
     reflectTimeError = random.normalvariate(0, 0.1)
     if abs(reflectTimeError) > 0.6:
         reflectTimeError = reflectTimeError / abs(reflectTimeError) * 0.6
     self.reflectTime = basicReflectTime + reflectTimeError + delta[self.type][1]
     viewRangeError = random.normalvariate(0, 10)
     if abs(viewRangeError) > 40:
         viewRangeError = viewRangeError / abs(viewRangeError) * 40
     self.viewRange = basicViewRange + viewRangeError + delta[self.type][0]
     tmpHoldV = random.normalvariate(road.Vmin + (road.Vmax - road.Vmin) / 3, 8)
     if tmpHoldV < road.Vmin:
         tmpHoldV = road.Vmin
     elif tmpHoldV > road.Vmax * 3 / 5:
         tmpHoldV = road.Vmax * 3 / 5
     self.holdV = tmpHoldV
     tmpMaxV = random.normalvariate(road.Vmin + (road.Vmax - road.Vmin) / 2, 20)
     if tmpMaxV < self.holdV:
         tmpMaxV = self.holdV
     elif tmpMaxV > road.Vmax:
         tmpMaxV = road.Vmax
     self.maxV = tmpMaxV
     
     self.car = car(self.holdV)
     self.pos = (road.piece[0], 0, -self.car.length, 0)
     chaseRangeError = random.normalvariate(0, 5)
     if abs(chaseRangeError) > 10:
         chaseRangeError = chaseRangeError / abs(chaseRangeError) * 10
     self.chaseRange = self.basicChaseRange = 50 + chaseRangeError
     if road.weather == "wet":
         self.viewRange -= 40
         self.chaseRange -= 10
         self.safeLine += 1
     if test_type == "RightHand":
         self.FSA = FSA.driveFSA(self)
     elif test_type == "NoRule":
         self.FSA = No_Rule_FSA.driveFSA(self)
     elif test_type == "SpeedFirst":
         self.FSA = Speed_First_FSA.driveFSA(self)
     elif test_type == "NS":
         self.FSA = NS.driveFSA(self)
     self.trance = 0.005 + delta[self.type][3]
     self.crashTime = 0
     self.crash = False
     self.option = "move"
示例#7
0
 def run(self):
     d = Data()
     self.data = d.getData()
     if(self.file_name == 'data/train4dAll.txt'):
         x, y = d.getTrainData4d()
     elif(self.file_name == 'data/train6dAll.txt'):
         x, y = d.getTrainData6d()
     else:
         x, y = d.getTrainData4d()
     print('---------')
     print('data:',self.data)
     x = d.normalize_input(x)
     y = d.normalize_Y(y)
     print('x:', x)
     print('y:', y)
     learn_rate1 = float(self.e4.get())
     learn_rate2 = float(self.e3.get())
     pop_size = int(self.e2.get())
     iterations = int(self.e1.get())
     if(self.file_name != 'data/RBFN_params.txt'):
         data4D = open("data/RBFN_params.txt",'w+')
         #training weight --start--
         rbf = RBF(3, 50, 1)
         x_dim, w, centers, beta = rbf.get_parameter()
         tStart = time.time()
         my_pso = pso(pop_size, iterations, learn_rate1, learn_rate2,x_dim, x, y, w, centers, beta)  
         my_pso.initialize()
         print('pso!!!!!!!!!!!!!')
         fitness = my_pso.training()
         tEnd = time.time()
         print('It cost', (tEnd - tStart), ' sec.')
         print('fitness: ', fitness)
         theta, w, centers, beta = my_pso.get_parameter()
         rbf.set_parameter(theta, w, centers, beta)
         rbf.train(x,y)
         z1 = rbf.predict(x, rbf.get_weight())
         print('predict_z', z1)
         y = d.inverse_normalize_Y(y)
         z = d.inverse_normalize_Y(z1)
         print('inverse_z', z)
         dim, output_W, output_centers, output_beta = rbf.get_parameter()
         print('output_W:',output_W)
         for i in range(0, len(output_W)):
             print(str(output_W[i][0]), str(output_centers[i][0]),str(output_centers[i][1]),str(output_centers[i][2]), str(output_beta[i][0]),file=data4D)
         data4D.close()
     else:
         load_w, load_centers, load_beta = d.load_parameters()
         rbf = RBF(3, len(load_centers), 1)
         rbf.set_parameter(0.5, load_w, load_centers, load_beta)
     print('rbf_W:', rbf.get_weight())
     m = map(self.data)
     self.edges = m.getEdges()
     c = car(self.data[0])
     Y = c.getPosition()
     self.mapping(self.edges)
     data4 = open("/Users/chengshu-yu/Documents/train4D.txt",'w+')
     data6 = open("/Users/chengshu-yu/Documents/train6D.txt",'w+')
     while(Y[1] < 43):
         self.draw_car(c.getPosition())
         print('car direction:', c.getDirection(), ', wheel degree: ', c.getWheel())
         c.sensor(self.edges)
         F, R, L = c.getDistance()
         input_x = []
         if(self.file_name == 'data/train4dAll.txt'):
             input_x.append([F, R, L])
         elif(self.file_name == 'data/train6dAll.txt'):
             pos = c.getPosition()
             input_x.append([pos[0], pos[1], F, R, L])
         else:
             input_x.append([F, R, L])
         input_x = np.array(input_x)
         input_x = d.normalize_input(input_x)
         print('input_x:', input_x)
         wheel = rbf.predict(input_x, rbf.get_weight())
         print('predict_wheel:', wheel)
         wheel = d.inverse_normalize_Y(wheel)
         print('inverse wheel:', wheel)
         if wheel < -40:
             wheel = -40
         elif wheel > 40:
             wheel = 40
         print('-----------front right left:', input_x, '-----------')
         print('-----------predict wheel:', wheel, '-----------')
         c.setWheel(wheel)
         c.update_car_direction()
         c.update_car_pos()
         print(str(F),' ',str(R),' ',str(L),' ',str(c.getDirection()),file=data4)
         print(str(c.getPosX()),'',str(c.getPosY()),' ',str(F),' ',str(R),' ',str(L),' ',str(c.getDirection()),file=data6)
     data4.close()
     data6.close()
示例#8
0
文件: MyCar.py 项目: lmomoh91/work
from Car import car
from my_electric_car import ElectricCar

my_bettle = car('volkswagen', 'beetle', 2019)
print(my_bettle.get_description_name())

my_tesla = ElectricCar('tesla', 'roadster', 2019)
print(my_tesla.get_description_name())
示例#9
0
from Car import car

my_car = car("Mercedes AMG", "$1000")
my_car.print_info()

示例#10
0
from Car import car

car = car(12, 20, 31)
car.move_forward()
示例#11
0
from Car import car

cc=car('audi', 'a4', str(2016))
print(cc.get_name())