Exemple #1
0
def menu():        
    clock()
    lcd.clear()
    i=0
    ok=0
    while (i<5):
        if ok==0: 
            lcd.clear()
            lcd.message(v[i])
            sleep(1)
            ok=1
        if GPIO.event_detected(20):
            if i==0:
#60
                shell = spur.LocalShell()
                result = shell.run(["python","/home/pi/bt/temp.py"])
                temp=result.output
                stemp(int(temp))
                lcd.clear()
                temp="Temperatura\n este :"+str(temp)
                lcd.message(temp)
                ok=0
                while not GPIO.event_detected(16):
                    pass
            if i==1:
                shell = spur.LocalShell()
                result = shell.run(["python","/home/pi/bt/pres.py"])
                pres=result.output
                lcd.clear()
                spres(int(pres))
                pres="Presiunea\n este: " +str(pres)
                lcd.message(pres)
                ok=0
                while not GPIO.event_detected(16):
                    pass
            if i==2:
                shell = spur.LocalShell() 
                result = shell.run(["python","/home/pi/bt/hum.py"])
                um=result.output
                sum(int(um))
                lcd.clear()
                lcd.message("Umiditatea"+'\n'+"este :"+um)
                ok=0
                while not GPIO.event_detected(16):
                    pass
            if i==3:
                x=["Piatra","Foarfeca","Hartie"]
 		computer = x[randint(0,2)]
		j=0
		player = False
		ok1=0
 		while True:
                 if ok1==0: 
                     lcd.clear()
                     t = ["Alegeti piatra?\n  Nu        Da","Alegeti Foarfeca?\n  Nu        Da","Alegeti Hartie?\n  Nu        Da"]
                     lcd.message(t[j])
                     sleep(1)
                     ok1=1       
		 if GPIO.event_detected(20):
                     if j==0:
                        player = "Piatra"
                        lcd.clear()
                        lcd.message("Ati ales:\n Piatra")
                        sleep(2)
                        ok1=0
                        break
                     if j==1:
                        player = "Foarfeca"
                        lcd.clear()
                        lcd.message("Ati ales:\n Foarfeca")
                        sleep(2)
                        ok1=0
                        break
                     if j==2:
                        player = "Hartie"
                        lcd.clear()
                        lcd.message("Ati ales:\n Hartie")
                        sleep(2)
                        ok1=0
                        break   
                 else:
                     if GPIO.event_detected(16):
                        if j<2:
                            j+=1
                        else:
                            j=0
                        ok1=0
                print (player,computer)        
                if player == computer:
                    lcd.clear()
                    lcd.message("Egal")
                elif player == x[0]:
                    if computer == x[2]:
                       lcd.clear()
                       lcd.message("Ai pierdut,\nOponent:Hartie") 
                    else:
                       lcd.clear()
                       lcd.message("Ai castigat,\nOponent:Foarfeca")
                elif player == x[1]:
                    if computer == x[0]:
                       lcd.clear()
                       lcd.message("Ai pierdut,\nOponent:Piatra") 
                    else:
                       lcd.clear()
                       lcd.message("Ai castigat,\nOponent:Hartie")
                elif player == x[2]:
                    if computer == x[1]:
                       lcd.clear()
                       lcd.message("Ai pierdut,\nOponent:Foarfeca") 
                    else:
                       lcd.clear()
                       lcd.message("Ai castigat,\nOponent:Piatra")
                ok=0
                while not GPIO.event_detected(16):
                    pass
            
            if i==4:
                rr()
                lcd.clear()
                sleep(2)
                rrp()
        else:
            if GPIO.event_detected(16):
                i+=1
                ok=0
Exemple #2
0
	if go_through_with_program:

		# Get file input 
		list_of_processes = get_instructions(sys.argv[1])

		# Convert file input to a series of Process objects
		process_list = [Process(p[0],p[1],p[2],p[3],p[4]) for p in list_of_processes]
		process_list1 = [Process(p[0],p[1],p[2],p[3],p[4]) for p in list_of_processes]
		process_list2 = [Process(p[0],p[1],p[2],p[3],p[4]) for p in list_of_processes]

		# Call each algorithm and report the stats
		fcfs = fcfs(process_list)
		print("")
		srt = srt(process_list1)
		print("")
		rr = rr(process_list2)
		filename = sys.argv[2]
		with open(filename,'w') as f:
			f.write("Algorithm FCFS\n")
			f.write("-- average CPU burst time: {:.2f}".format(fcfs[0])+ " ms\n")
			f.write("-- average wait time: {:.2f}".format(fcfs[1])+ " ms\n")
			f.write("-- average turnaround time: {:.2f}".format(fcfs[2])+ " ms\n")
			f.write("-- total number of context switches: {}".format(int(fcfs[3])) + "\n")
			f.write("-- total number of preemptions: {}".format(int(fcfs[4])) + "\n")
			f.write("Algorithm SRT\n")
			f.write("-- average CPU burst time: {:.2f}".format(srt[0])+ " ms\n")
			f.write("-- average wait time: {:.2f}".format(srt[1])+ " ms\n")
			f.write("-- average turnaround time: {:.2f}".format(srt[2])+ " ms\n")
			f.write("-- total number of context switches: {}".format(int(srt[3])) + "\n")
			f.write("-- total number of preemptions: {}".format(int(srt[4])) + "\n")
			f.write("Algorithm RR\n")
Exemple #3
0
from metric import printErrorMetrics

from rf import rf
from rr import rr
from nn import nn
from lr import lr


if __name__ == '__main__':
    extract_dir = sys.argv[1]
    fnum = int(sys.argv[2])

    """ datasets and labels's size is fnum """
    datasets, labels = GetAllData(extract_dir, fnum, 'bfs', total_vertex_num=4900578, L=500000)
    # datasets, labels = GetAllData(extract_dir, fnum, 'bfs', total_vertex_num=65608366, L=10000000)

    """ ridge regression """
    sr, sl = rr(datasets, labels, fnum)

    """ neural network """
    sr, sl = nn(datasets, labels, fnum)
    
    """ liner regression """
    sr, sl = lr(datasets, labels, fnum)

    """ random forest """
    sr, sl = rf(datasets, labels, fnum)

    """ draw picture """
    sample_draw(sr,sl)
Exemple #4
0
#coding:utf-8


import serial
import time
from vor import vor
from hinter import hinter
from rr import rr
from rl import rl
from fin import fin

vor()
hinter()
rr()
rl()

print 'key w = forward, s = back, a = left turn, d = right turn, q = finish...'

while(True):
    if __name__ == '__main__':
        input_data = raw_input('>>> ')

        if input_data == 'w':
            vor()
            print 'forward'
        elif input_data == 's':
            hinter()
            print 'back'
        elif input_data == 'a':
            rl()
            print 'left turn'
Exemple #5
0
 def rr(self):
     self.window = QtWidgets.QMainWindow()
     self.ui = rr()
     self.ui.setupUi(self.window)
     self.window.show()
def main():

	# Error handling for the arguments
	if len(sys.argv) != 8 and len(sys.argv) != 9:
		sys.exit("ERROR: Incorrect number of arguments!")

	try:
		# Seed for the random number generator to determine the interarrival times of CPU bursts.
		number_generator_seed = int(sys.argv[1])

		# Lambda value that determines average value generated for interarrival times
		# 	(with exponential distribution).
		lambda_value = float(sys.argv[2])

		# Upper-bound for valid pseudo-random values (will skip values greater than upper bound).
		upper_bound = int(sys.argv[3])

		# Number of processes to simulate.
		# Process IDs are assigned in alphabetical order A through Z, therefore atmost there will
		#	be 26 processes to simulate.
		number_simulations = int(sys.argv[4])

		# Time (in milliseconds) it takes to perform a context switch.
		context_switch_time = int(sys.argv[5])

		# For SJF and SRT, we cannot know the actual CPU burst times beforehand, so we will make
		# 	an estimate determined via exponential averaging (using "ceiling" function).
		alpha_value = float(sys.argv[6])

		# For the RR algoorithm, we need to define the time slice value (in milliseconds).
		time_slice = int(sys.argv[7])
	except ValueError:
		sys.exit("ERROR: Improper arguments were given!")

	# For the RR algorithm, we define whether processes or added to the beginning or end of
	#	the ready queue when they arrive or complete I/O.
	# Value should be set to BEGINNING or END, with END being the default behavior.
	if len(sys.argv) > 8:
		if sys.argv[8] == "BEGINNING" or sys.argv[8] == "END":
			queue_addition = sys.argv[8]
		else:
			sys.exit("ERROR: Enter correct rr_add!")
	else:
		queue_addition = "END"

	# List that contains all of the stimulations
	processes = []

	# List that contains the amount of bursts for each of the processes
	bursts = []

	# List of lists that contains the burst times each burst in each process
	burst_times = [] 

	# List of lists that contains the I/O times for each burst in each process
	io_times = []

	# Initiating the generator with srand48
	generator = Rand48(number_generator_seed)
	generator.srand48()

	i = 0
	while i < number_simulations:
		# Adding the arrival times for each process
		random_number = generator.drand48()
		arrival_time = math.floor(-math.log(random_number) / lambda_value)

		# Skip arrival times that exceed upper bound
		if arrival_time > upper_bound:
			continue
		else:
			# Store the arrival time if it does not exceed upper bound
			processes.append(arrival_time)

			# Adding the number of bursts needed for each process
			random_number = generator.drand48()

			# Skip bursts that exceed upper bound
			while  math.floor(random_number * 100) + 1 > upper_bound:
				random_number = generator.drand48()

			bursts.append(math.floor(random_number * 100) + 1)

			temp_burst = []
			temp_io = []

			# For each burst of a process, generate a burst time  and an I/O time
			for j in range(0, bursts[len(bursts)-1]):
				# Last burst does not have an I/O, so just generate a burst time
				if j == bursts[len(bursts)-1] - 1:
					burst_and_io_generator(lambda_value, upper_bound, temp_burst, generator)
					continue
				else:
					# Generating burst time values
					burst_and_io_generator(lambda_value, upper_bound, temp_burst, generator)

					# Generating I/O values
					burst_and_io_generator(lambda_value, upper_bound, temp_io, generator)

			burst_times.append(temp_burst)
			io_times.append(temp_io)

		i += 1

	# FCFS Algorithm
	fcfs(processes, bursts, burst_times, io_times, context_switch_time)
	print()

	# SJF Algorithm
	sjf(processes, bursts, burst_times, io_times, context_switch_time, lambda_value, alpha_value)
	print()

	# SRT Algorithm 
	srt(processes, bursts, burst_times, io_times, context_switch_time, lambda_value, alpha_value)
	print()

	# RR Algorithm
	rr(processes, bursts, burst_times, io_times, context_switch_time, time_slice, queue_addition)