def Gen_Simu_data2(start_n, end_n, T, Simu_para_dict, bidding_mode=0, info_mode=0, simu_df=None, rng_seed=123): ''' start_n : start number of bidders end_n : end number of bidders T number of auctions T_end bidding path length info mode whether it is uninformed case or informed case 0: uninformed case 1: informed case bidding_mode whether it is the inoformed case or uninformed for replication 0: informed case 1: uninformed case ''' # moving the number simu_data = [] for n in range(start_n, end_n + 1): SIMU = Simu(rng_seed, Simu_para_dict, bidding_mode) if info_mode == 0: SIMU.setup_para(simu_df[n - start_n]) simu_data.append(SIMU.Data_premium(n, T, info_mode)) return simu_data
def Gen_Simu(N, T, T_end, Simu_para_dict, flag_num, info_mode=0, flag_mode=0, rng_seed=123): ''' N number of register bidders T number of auctions T_end bidding path length flag_num whether it is fixed N to genertate or starting from 2 to N 0: fix the N 1: start from 2 to N flag_mode whether it is fix reservation or fix the pub-evaulation or randomize everything 0: fix the pub 1: fix the reservation 2: randomize everything ''' # moving the number if flag_num == 0: SIMU = Simu(rng_seed, Simu_para_dict) simu_data = SIMU.Data_simu(N, T, T_end, info_mode, flag_mode) else: simu_data = [] for n in range(3, N + 1): SIMU = Simu(rng_seed, Simu_para_dict) simu_data.append(SIMU.Data_simu(n, T, T_end, flag_mode)) return simu_data
if __name__ == '__main__': # select the running mode: flag_mode=input("select mode : 0 for simulation results, 1: for running estimation") N=5 rng_seed=123 T=800 T_end=60 if flag_mode == "0" : SIMU=Simu(N,T,rng_seed,Simu_para_dict) simu_data=SIMU.Data_simu(T_end) pk.dump(simu_data, open( "simu_data.pkl", "wb")) else: simu_data = pk.load( open( "simu_data.pkl", "rb")) rng_seed=789 SS=25 JJ=6000 info_flag=0
total_energy_cost_dust = [] print "" print " ____ _____ _____ _____ __ __ __ __ " print " ( ) (_ _) / ____\ (_ _) \ \ / / ) ) ( ( " print " / /\ \ | | ________ ( (___ | | () \/ () ( ( ) ) " print " ( (__) ) | | (________) \___ \ | | / _ _ \ ) ) ( ( " print " ) ( | | ) ) | | / / \/ \ \ ( ( ) ) " print " / /\ \ _| |__ ___/ / _| |__ /_/ \_\ ) \__/ ( " print "/__( )__\ /_____( /____/ /_____( (/ \) \______/ " print "" for iteration in range(0, numberOfIterations): update_progress(float(iteration) / numberOfIterations) myRobot = FullSenseAgent("Mem_002") mySimu = Simu(myEnvironment.copy(), myRobot, [1, 1], False) mySimu.run(100000, 0.00) total_energy_cost_dust.append(mySimu.give_total_energy_cost()) #mySimu.print_statistics() myRobot = BasicAgent("Reflexive_001") mySimu = Simu(myEnvironment.copy(), myRobot, [1, 1], False) mySimu.run(100000, 0.000) total_energy_cost_basic.append(mySimu.give_total_energy_cost()) plt.plot(total_energy_cost_basic) plt.plot(total_energy_cost_dust) plt.legend(['BasicAgent', 'FullSenseAgent']) plt.xlabel('Simu Iteration') plt.ylabel('Energy Consumption') plt.title('AI-Agent: BasicAgent -vs- FullSenseAgent') plt.grid()
from simu import Simu from quadprog import solve_qp pkg = '/home/nmansard/src/sot_versions/groovy/ros/stacks/hrp2/' urdf = '/home/nmansard/src/pinocchio/pinocchio/models/hrp2014.urdf' robot = Hrp2Reduced(urdf,[pkg],loadModel=True) robot.display(robot.q0) robot.viewer.setCameraTransform(0,[1.9154722690582275, -0.2266872227191925, 0.1087859719991684, 0.5243823528289795, 0.518651008605957, 0.4620114266872406, 0.4925136864185333]) simu = Simu(robot,dt=1e-3,ndt=5) NQ,NV,NB,RF,LF,RK,LK = simu.NQ,simu.NV,simu.NB,simu.RF,simu.LF,simu.RK,simu.LK def loop(q,v,niter,ndt=None,dt=None,tsleep=.9,fdisplay=1): t0 = time.time() if dt is not None: simu.dt = dt if ndt is not None: simu.ndt = ndt robot.display(q) for i in range(niter): q,v = simu(q,v,control(q,v)) if not i % fdisplay: robot.display(q) time.sleep(tsleep*simu.dt) print 'Elapsed time = %.2f (simu time=%.2f)' % (time.time()-t0,simu.dt*niter) return q,v
# -*- coding: utf-8 -*- #modifier pour que la voiture soit verte que quand y a latence #modifier pour que la voiture reparte une fois qu'elle ralentie import turtle from simu import Simu # Chargement du jeu simulation = Simu() running = True # Initialisation de l'affichage simulation.voiture_a.affiche() simulation.voiture_b.affiche() simulation.voiture_c.affiche() simulation.voiture_d.affiche() #Parametres en fonction de la simmulation #Echelle : 1px equivaut a 0.5m et 1 en vitesse equivaut a 100km/h #distance entre deux voiture mini pour eviter accident distance_secu = 100 distance_visible = 50 + 300 turtle.Screen().onkey(simulation.reset, "r") turtle.Screen().onkey(simulation.voiture_b.arret, "a") turtle.Screen().onkey(simulation.simu_1, "1") turtle.Screen().onkey(simulation.simu_2, "2") #turtle.Screen().onkey(pong.voiture_a.arret,"a")
return sum_value / J if __name__ == '__main__': # select the running mode: flag_mode = input( "select mode : 0 for simulation results, 1: for running estimation") N = 5 rng_seed = 123 T = 300 T_end = 60 info_flag = 0 if flag_mode == "0": SIMU = Simu(rng_seed, Simu_para_dict) simu_data = SIMU.Data_simu(N, T, T_end, info_flag, flag_mode) pk.dump(simu_data, open("simu_data.pkl", "wb")) else: simu_data = pk.load(open("simu_data.pkl", "rb")) rng_seed = 789 SS = 25 JJ = 6000 info_flag = 0 print("fail") #est=Est(N,rng_seed,TT,SS,info_flag) d_struct = {
def start_simu(self): nbr_simu = self.number_simu.value() moy_res = {} path_simu = str(self.name_save.text())+"/" num_simu = 0 self.progressBar.show() self.repaint() self.progressBar.repaint() self.progressBar.setRange(0, nbr_simu) if os.path.isdir(path_simu): while os.path.isdir(path_simu + str(num_simu)) and num_simu < nbr_simu: if os.path.isfile(path_simu + str(num_simu) + "/res.data") and os.path.isfile(path_simu + str(num_simu) + "/results.json"): json_res = json.load(open(path_simu + str(num_simu) + "/results.json")) for key, val in json_res.iteritems(): if key.count("["): num = int(key[key.find("[")+1:key.find("]")]) key = "Agent" + str(num) if moy_res.keys().count(key): moy_res[key] += val else: moy_res.update({key: val}) else: shutil.rmtree(path_simu + str(num_simu)) num_simu += 1 else: os.mkdir(path_simu) nb_retry = 0 self.progressBar.show() self.progressBar.setValue(0) self.progressBar.repaint() while num_simu < nbr_simu: path = path_simu if nbr_simu != 1: path += str(num_simu)+"/" params = { "seed": randint(0, 1000), "repousse": 0, "mode_simu": 1 } simu = Simu( params=params, path_save=path, save=True, screenshot=self.screen_box.checkState(), display=False, nb_points=self.number_point.value(), interactive=False, delay_screenshot=self.delay_screenshots.value() ) try: res = simu.run() if len(moy_res.keys()) == 0: moy_res = res else: for key, val in res.iteritems(): if key.count("["): num = int(key[key.find("[")+1:key.find("]")]) key = "Agent" + str(num) if moy_res.keys().count(key): moy_res[key] += val else: moy_res.update({key: val}) except: print "\nUnexpected error:", sys.exc_info()[0] simu.stop() if nb_retry > 10: print "Number of retry exceeded" return {} else: nb_retry += 1 print "\nRetrying simulation" num_simu -= 1 num_simu += 1 self.progressBar.setValue(num_simu) self.progressBar.repaint() nbr_simu = num_simu self.progressBar.hide() if nbr_simu > 1: # compute average simulations datas_files = [] moy_data = open(path_simu + "res.data", "w") for i in range(nbr_simu): try: datas_files.append(open(path_simu+str(i)+"/res.data", "r")) except: print "ERROR no file 'res.data', simu " + str(i) + " ignored" # get name columns col_name = "" for data_file in datas_files: col_name = data_file.readline() moy_data.write(col_name) # average values for n_line in range(self.number_point.value()): res_line = [] for data_file in datas_files: if len(res_line) == 0: for n_fig, fig_datas in enumerate(data_file.readline().split('|')): res_line.append([]) for data in fig_datas.split(','): res_line[n_fig].append(float(data)) else: for n_fig, fig_datas in enumerate(data_file.readline().split('|')): for n_data, data in enumerate(fig_datas.split(',')): res_line[n_fig][n_data] += float(data) for n_fig, datas_fig in enumerate(res_line): for n_data, data in enumerate(datas_fig): moy_data.write("{:9.6f}".format(data/len(datas_files))) if n_data != len(datas_fig)-1: moy_data.write(", ") if n_fig != len(res_line)-1: moy_data.write("| ") moy_data.write("\n") moy_data.flush() print "-----------------\n" \ "|||||RESULTS|||||\n" \ "-----------------\n" for key in moy_res.keys(): moy_res[key] /= float(nbr_simu) json_res = json.dumps(moy_res, indent=4, sort_keys=False) print json_res results = open(path_simu+"results.json", 'w') results.write(json_res) Simu(path_save=path_simu, save=True).open_res(self.name_save.text() + "res.data")
if(k>1.0): ndt = int(ndt*(1+log(k))) print 'Increasing ndt to %d'%(ndt) #robot parameters Ky = conf.Ky Kz = conf.Kz By = ZETA*2*sqrt(Ky) #50e0 Bz = ZETA*2*sqrt(Kz) #500e0 K = np.asmatrix(np.diagflat([Ky,Kz,Ky,Kz])) Kspring = -np.diagflat([Ky,Kz,0.]) # Stiffness of the feet spring Bspring = -np.diagflat([By,Bz,0.]) # damping of the feet spring #Simulator simu = Simu(robot,dt=dt,ndt=ndt) simu.tauc = tauc simu.Krf, simu.Klf = Kspring, Kspring simu.Brf, simu.Blf = Bspring, Bspring simu.enable_friction_cones(mu_simu) simu.joint_torques_cut_frequency = JOINT_TORQUES_CUT_FREQUENCY #initial state #q0 = robot.q0.copy() #v0 = zero(robot.model.nv) g_vec = robot.model.gravity.linear[1:].A1 # gravity acc vector g = np.linalg.norm(g_vec) # gravity acceleration #se3.computeAllTerms(robot.model,robot.data,q0,v0) m = robot.data.mass[0] q0 = conf.q0 v0 = conf.v0
def Gen_Simu_data1(N, T, Simu_para_dict, info_flag=0, rng_seed=123): SIMU = Simu(rng_seed, Simu_para_dict) # simu_data=[SIMU.Data_simu(N,T,info_flag) for info_flag in range(0,2)] [simu_data, simu_mom] = SIMU.Data_premium(N, T, info_flag) return [simu_data, simu_mom]