Exemplo n.º 1
0
 def __init__(self, date, run, x, y, z, xrem, yrem, loc):
     perffile = '%s/%s-perf-test-run%s.txt' % (loc, date, run)
     rd = ReadData(perffile)
     self.axesn = [x, y, z]
     self.axesr = [xrem, yrem]  # remove outer bands from axes
     self.axesv = [[], [], []]
     self.data = rd.genData()
Exemplo n.º 2
0
 def __init__(self):
     self.AM = Model().solve()  # return the values of the model, list
     self.one = ReadData("TTRP_01.txt")
     self.truck_num = 5
     self.trailer_num = 3
     # different TTRP_xx.txt need different argument
     # self.all_locations = [['a', ['30.0', '40.0']]] + self.one.get_locations() # 01.txt
     self.all_locations = [['a', ['30.0', '40.0']]
                           ] + self.one.get_locations()  # 02.txt
Exemplo n.º 3
0
class Server(object):
	"""docstring for Server"""
	def __init__(self, **kwargs):
		super(Server, self).__init__()

		self._init_attr()

	#----------------------------------------------------------------------
	# 类属性设置
	#----------------------------------------------------------------------
	def _init_attr(self):
		logger.debug('_init_attr')
		self.rd = ReadData()

	def startup(self):
		logger.debug('startup')

	def _do_command(self):
		logger.debug('do command')
		command = raw_input('>>#')
		if command == 'q':
			sys.exit(0)

	def workerDaily(self):
		logger.debug('workerDaily')
		while True:
			#logger.debug('working')
			print time.ctime()
			#self.rd.getSina();
			self.rd.writeDailyShare(self.rd.daily)
			print time.ctime()
			time.sleep(60)

	def workerShares(self):
		logger.debug('workerShares')
		while True:
			#logger.debug('working')
			print time.ctime()
			#self.rd.getSina();
			self.rd.writeDailyShare(self.rd.shares)
			print time.ctime()
			time.sleep(0.5)

	#----------------------------------------------------------------------
	# 主消息分发函数
	#----------------------------------------------------------------------
	def process(self):
		logger.debug('process')
		thr = threading.Thread(target=self.workerShares)
		thr.start()
		t_woker = threading.Thread(target=self.workerDaily)
		t_woker.start()

		if(conf.single.outofTrade()):
			sys.exit()
			logger.debug('stop')
Exemplo n.º 4
0
def print_keys(loc, date, run):
    perffile = '%s/%s-perf-test-run%s.txt' % (loc, date, run)
    data = ReadData(perffile).genData()
    for k in data[0].keys():
        print(k)
Exemplo n.º 5
0
    def __init__(self, filename, filename_r):
        self.filename = filename
        self.flight = ReadData(self.filename)
        self.flight_data = self.flight.read_data();
        self.app = QtGui.QApplication([])
        self.win = QtGui.QMainWindow()
        self.area = DockArea()
        self.win.setCentralWidget(self.area)
        self.win.showMaximized()
        self.win.setWindowTitle('MPU Simulation')
        self.win.setGeometry(10, 25, 1920, 1024)

        #Reference Data
        self.filename_r = filename_r
        self.reference = ReadData(self.filename_r)
        self.reference_data = self.reference.read_data();


        # Create docks, place them into the window one at a time.
        self.d_a = Dock("Animation", size=(500, 400))
        self.d_n = Dock("North (Xn)", size=(500, 200))
        self.d_e = Dock("East (Yn)", size=(500, 200))
        self.d_h = Dock("Height (h)", size=(500, 200))
        self.d_v = Dock("Velocity V", size=(500, 200))
        self.d_u_ = Dock("Velocity u", size=(500, 200))
        self.d_v_ = Dock("Velocity v", size=(500, 200))
        self.d_w_ = Dock("Velocity w", size=(500, 200))
        self.d_p = Dock("Velocity p", size=(500, 200))
        self.d_q = Dock("Velocity q", size=(500, 200))
        self.d_r = Dock("Velocity r", size=(500, 200))
        self.d_phi = Dock("Roll", size=(500, 200))
        self.d_theta = Dock("Pitch", size=(500,200))
        self.d_psi = Dock("Yaw", size=(500,200))
        self.d_w = Dock("Motors Rotation", size=(500, 200))
        self.d_t = Dock("Motors Angle", size=(500,200))
        self.d_deltae = Dock("Elevons", size=(500,200))
        self.area.addDock(self.d_a, 'left')
        self.area.addDock(self.d_n, 'right')
        self.area.addDock(self.d_e, 'below', self.d_n)
        self.area.addDock(self.d_h, 'below', self.d_e)
        self.area.addDock(self.d_v, 'below', self.d_h)
        self.area.addDock(self.d_u_, 'below', self.d_v)
        self.area.addDock(self.d_v_, 'below', self.d_u_)
        self.area.addDock(self.d_w_, 'below', self.d_v_)
        self.area.addDock(self.d_phi, 'bottom', self.d_n)
        self.area.addDock(self.d_theta, 'below', self.d_phi)
        self.area.addDock(self.d_psi, 'below', self.d_theta)
        self.area.addDock(self.d_p, 'below', self.d_psi)
        self.area.addDock(self.d_q, 'below', self.d_p)
        self.area.addDock(self.d_r, 'below', self.d_q)
        self.area.addDock(self.d_w, 'bottom', self.d_phi)
        self.area.addDock(self.d_t, 'below', self.d_w)
        self.area.addDock(self.d_deltae, 'below', self.d_t)

        #Animation Window
        self.d_a.hideTitleBar()
        self.w = gl.GLViewWidget()
        self.zgrid = gl.GLGridItem()
        self.w.addItem(self.zgrid)
        self.w.setWindowTitle('Animation')
        self.w.setCameraPosition(distance=20, azimuth=90, elevation=60)
        self.x0 = self.flight_data[self.flight.i_north][0]
        self.y0 = -self.flight_data[self.flight.i_east][0]
        self.h0 = self.flight_data[self.flight.i_height][0]

        #Fuselage Model
        self.model_fus = Model("./obj_files/MPUFuselage.obj")
        self.md_fus = gl.MeshData(vertexes=self.model_fus.returnMesh())
        self.fuselage = gl.GLMeshItem(meshdata=self.md_fus, color=(1, 1, 1, 1),
            smooth=False, shader='shaded', glOptions='opaque')
        self.d_a.addWidget(self.w)

        #Waypoint Model
        self.model_wayp = Model("./obj_files/wayp.obj")
        self.md_wayp = gl.MeshData(vertexes=self.model_wayp.returnMesh())
        self.waypoint = gl.GLMeshItem(meshdata=self.md_wayp, color=(1, 1, 1, 1),
            smooth=False, shader='shaded', glOptions='opaque')
        self.d_a.addWidget(self.w)

        #Plots Setup
        #North Displacement
        self.w_n = pg.PlotWidget(title="North Displacement")
        self.w_n.setDownsampling(mode='peak')
        self.w_n.setClipToView(True)
        self.curve_x = self.w_n.plot()
        self.curve_x_r = self.w_n.plot()
        self.w_n.setLabel('bottom', 'Time', 's')
        self.w_n.setLabel('left', 'Xn', 'm')
        self.d_n.addWidget(self.w_n)

        #East Displacement
        self.w_e = pg.PlotWidget(title="East Displacement")
        self.w_e.setDownsampling(mode='peak')
        self.w_e.setClipToView(True)
        self.curve_y = self.w_e.plot()
        self.w_e.setLabel('bottom', 'Time', 's')
        self.w_e.setLabel('left', 'Yn', 'm')
        self.d_e.addWidget(self.w_e)

        #Height
        self.w_h = pg.PlotWidget(title="Height Displacement")
        self.w_h.setDownsampling(mode='peak')
        self.w_h.setClipToView(True)
        self.curve_h = self.w_h.plot()
        self.w_h.setLabel('bottom', 'Time', 's')
        self.w_h.setLabel('left', 'h', 'm')
        self.d_h.addWidget(self.w_h)

        #Velocity V
        self.w_v = pg.PlotWidget(title="Total Velocity")
        self.w_v.setDownsampling(mode='peak')
        self.w_v.setClipToView(True)
        self.curve_V = self.w_v.plot()
        self.w_v.setLabel('bottom', 'Time', 's')
        self.w_v.setLabel('left', 'V', 'm/s')
        self.d_v.addWidget(self.w_v)

        #Velocity u
        self.w_u_ = pg.PlotWidget(title="Velocity u")
        self.w_u_.setDownsampling(mode='peak')
        self.w_u_.setClipToView(True)
        self.curve_u_ = self.w_u_.plot()
        self.w_u_.setLabel('bottom', 'Time', 's')
        self.w_u_.setLabel('left', 'u', 'm/s')
        self.d_u_.addWidget(self.w_u_)

        #Velocity v
        self.w_v_ = pg.PlotWidget(title="Velocity v")
        self.w_v_.setDownsampling(mode='peak')
        self.w_v_.setClipToView(True)
        self.curve_v_ = self.w_v_.plot()
        self.w_v_.setLabel('bottom', 'Time', 's')
        self.w_v_.setLabel('left', 'v', 'm/s')
        self.d_v_.addWidget(self.w_v_)

        #Velocity w
        self.w_w_ = pg.PlotWidget(title="Velocity w")
        self.w_w_.setDownsampling(mode='peak')
        self.w_w_.setClipToView(True)
        self.curve_w_ = self.w_w_.plot()
        self.w_w_.setLabel('bottom', 'Time', 's')
        self.w_w_.setLabel('left', 'w', 'm/s')
        self.d_w_.addWidget(self.w_w_)

        #Velocity p
        self.w_p = pg.PlotWidget(title="Rotational Velocity p")
        self.w_p.setDownsampling(mode='peak')
        self.w_p.setClipToView(True)
        self.curve_p = self.w_p.plot()
        self.w_p.setLabel('bottom', 'Time', 's')
        self.w_p.setLabel('left', 'p', 'rad/s')
        self.d_p.addWidget(self.w_p)

        #Velocity q
        self.w_q = pg.PlotWidget(title="Rotational Velocity q")
        self.w_q.setDownsampling(mode='peak')
        self.w_q.setClipToView(True)
        self.curve_q = self.w_q.plot()
        self.w_q.setLabel('bottom', 'Time', 's')
        self.w_q.setLabel('left', 'q', 'rad/s')
        self.d_q.addWidget(self.w_q)

        #Velocity q
        self.w_r = pg.PlotWidget(title="Rotational Velocity r")
        self.w_r.setDownsampling(mode='peak')
        self.w_r.setClipToView(True)
        self.curve_r = self.w_r.plot()
        self.w_r.setLabel('bottom', 'Time', 's')
        self.w_r.setLabel('left', 'r', 'rad/s')
        self.d_r.addWidget(self.w_r)

        #Roll
        self.w_phi = pg.PlotWidget(title="Roll Angle")
        self.w_phi.setDownsampling(mode='peak')
        self.w_phi.setClipToView(True)
        self.curve_phi = self.w_phi.plot()
        self.w_phi.setLabel('bottom', 'Time', 's')
        self.w_phi.setLabel('left', 'Roll Anlge', 'rad')
        self.d_phi.addWidget(self.w_phi)

        #Pitch
        self.w_theta = pg.PlotWidget(title="Pitch Angle")
        self.w_theta.setDownsampling(mode='peak')
        self.w_theta.setClipToView(True)
        self.curve_theta = self.w_theta.plot()
        self.w_theta.setLabel('bottom', 'Time', 's')
        self.w_theta.setLabel('left', 'Pitch Angle', 'rad')
        self.d_theta.addWidget(self.w_theta)

        #Yaw
        self.w_psi = pg.PlotWidget(title="Yaw Angle")
        self.w_psi.setDownsampling(mode='peak')
        self.w_psi.setClipToView(True)
        self.curve_psi = self.w_psi.plot()
        self.w_psi.setLabel('bottom', 'Time', 's')
        self.w_psi.setLabel('left', 'Yaw Angle', 'rad')
        self.d_psi.addWidget(self.w_psi)

        #Motors Rotation
        self.w_w = pg.PlotWidget(title="Motors Rotational Velocity")
        self.w_w.setDownsampling(mode='peak')
        self.w_w.setClipToView(True)
        self.curve_wl = self.w_w.plot(pen = (255,0,0))
        self.curve_wr = self.w_w.plot(pen = (0,255,0))
        self.curve_wb = self.w_w.plot(pen = (0,0,255))
        self.w_w.setLabel('bottom', 'Time', 's')
        self.w_w.setLabel('left', 'Rotational Velocity', 'rpm')
        self.w_w.addLegend()
        self.l_w = self.w_w.plotItem.legend
        self.l_w.addItem(self.curve_wl, "Left Motor")
        self.l_w.addItem(self.curve_wr, "Right Motor")
        self.l_w.addItem(self.curve_wb, "Rear Motor")
        self.d_w.addWidget(self.w_w)

        #Motors Angle
        self.w_t = pg.PlotWidget(title="Motors Angle")
        self.w_t.setDownsampling(mode='peak')
        self.w_t.setClipToView(True)
        self.curve_tl = self.w_t.plot(pen = (255,0,0))
        self.curve_tr = self.w_t.plot(pen = (0,255,0))
        self.w_t.setLabel('bottom', 'Time', 's')
        self.w_t.setLabel('left', 'Motors Angle', 'deg')
        self.d_t.addWidget(self.w_t)
        self.w_t.addLegend()
        self.l_t = self.w_t.plotItem.legend
        self.l_t.addItem(self.curve_tl, "Left Motor")
        self.l_t.addItem(self.curve_tr, "Right Motor")
        self.d_t.addWidget(self.w_t)

        #Elevons Angle
        self.w_deltae = pg.PlotWidget(title="Elevons Angle")
        self.w_deltae.setDownsampling(mode='peak')
        self.w_deltae.setClipToView(True)
        self.curve_deltael = self.w_deltae.plot(pen = (255,0,0))
        self.curve_deltaer = self.w_deltae.plot(pen = (0,255,0))
        self.w_deltae.setLabel('bottom', 'Time', 's')
        self.w_deltae.setLabel('left', 'Elevons Angle', 'deg')
        self.d_deltae.addWidget(self.w_deltae)
        self.w_deltae.addLegend()
        self.l_deltae = self.w_deltae.plotItem.legend
        self.l_deltae.addItem(self.curve_deltael, "Left Elevon")
        self.l_deltae.addItem(self.curve_deltaer, "Right Elevon")
        self.d_deltae.addWidget(self.w_deltae)

        #Data Animation
        self.pts = np.vstack([self.flight_data[self.flight.i_north],
            -self.flight_data[self.flight.i_east],
            self.flight_data[self.flight.i_height]]).transpose()
        self.plt = gl.GLLinePlotItem(pos=self.pts, color=pg.glColor(('b')),
            width=1, antialias=True)
        self.w.addItem(self.plt)

        #Reference
        self.pts_r = np.stack([self.reference_data[self.reference.i_north_r],
            -self.reference_data[self.reference.i_east_r],
            self.reference_data[self.reference.i_height_r]]).transpose()
        self.plt_r = gl.GLLinePlotItem(pos=self.pts_r, color=pg.glColor(('r')),
            width=1, antialias=True)
        # print(self.pts_r[0])
        self.w.addItem(self.plt_r)

        #Add Geometry
        self.w.addItem(self.fuselage)
        self.w.addItem(self.waypoint)
        self.ti_in = 0
Exemplo n.º 6
0
class Animation(object):

    def __init__(self, filename, filename_r):
        self.filename = filename
        self.flight = ReadData(self.filename)
        self.flight_data = self.flight.read_data();
        self.app = QtGui.QApplication([])
        self.win = QtGui.QMainWindow()
        self.area = DockArea()
        self.win.setCentralWidget(self.area)
        self.win.showMaximized()
        self.win.setWindowTitle('MPU Simulation')
        self.win.setGeometry(10, 25, 1920, 1024)

        #Reference Data
        self.filename_r = filename_r
        self.reference = ReadData(self.filename_r)
        self.reference_data = self.reference.read_data();


        # Create docks, place them into the window one at a time.
        self.d_a = Dock("Animation", size=(500, 400))
        self.d_n = Dock("North (Xn)", size=(500, 200))
        self.d_e = Dock("East (Yn)", size=(500, 200))
        self.d_h = Dock("Height (h)", size=(500, 200))
        self.d_v = Dock("Velocity V", size=(500, 200))
        self.d_u_ = Dock("Velocity u", size=(500, 200))
        self.d_v_ = Dock("Velocity v", size=(500, 200))
        self.d_w_ = Dock("Velocity w", size=(500, 200))
        self.d_p = Dock("Velocity p", size=(500, 200))
        self.d_q = Dock("Velocity q", size=(500, 200))
        self.d_r = Dock("Velocity r", size=(500, 200))
        self.d_phi = Dock("Roll", size=(500, 200))
        self.d_theta = Dock("Pitch", size=(500,200))
        self.d_psi = Dock("Yaw", size=(500,200))
        self.d_w = Dock("Motors Rotation", size=(500, 200))
        self.d_t = Dock("Motors Angle", size=(500,200))
        self.d_deltae = Dock("Elevons", size=(500,200))
        self.area.addDock(self.d_a, 'left')
        self.area.addDock(self.d_n, 'right')
        self.area.addDock(self.d_e, 'below', self.d_n)
        self.area.addDock(self.d_h, 'below', self.d_e)
        self.area.addDock(self.d_v, 'below', self.d_h)
        self.area.addDock(self.d_u_, 'below', self.d_v)
        self.area.addDock(self.d_v_, 'below', self.d_u_)
        self.area.addDock(self.d_w_, 'below', self.d_v_)
        self.area.addDock(self.d_phi, 'bottom', self.d_n)
        self.area.addDock(self.d_theta, 'below', self.d_phi)
        self.area.addDock(self.d_psi, 'below', self.d_theta)
        self.area.addDock(self.d_p, 'below', self.d_psi)
        self.area.addDock(self.d_q, 'below', self.d_p)
        self.area.addDock(self.d_r, 'below', self.d_q)
        self.area.addDock(self.d_w, 'bottom', self.d_phi)
        self.area.addDock(self.d_t, 'below', self.d_w)
        self.area.addDock(self.d_deltae, 'below', self.d_t)

        #Animation Window
        self.d_a.hideTitleBar()
        self.w = gl.GLViewWidget()
        self.zgrid = gl.GLGridItem()
        self.w.addItem(self.zgrid)
        self.w.setWindowTitle('Animation')
        self.w.setCameraPosition(distance=20, azimuth=90, elevation=60)
        self.x0 = self.flight_data[self.flight.i_north][0]
        self.y0 = -self.flight_data[self.flight.i_east][0]
        self.h0 = self.flight_data[self.flight.i_height][0]

        #Fuselage Model
        self.model_fus = Model("./obj_files/MPUFuselage.obj")
        self.md_fus = gl.MeshData(vertexes=self.model_fus.returnMesh())
        self.fuselage = gl.GLMeshItem(meshdata=self.md_fus, color=(1, 1, 1, 1),
            smooth=False, shader='shaded', glOptions='opaque')
        self.d_a.addWidget(self.w)

        #Waypoint Model
        self.model_wayp = Model("./obj_files/wayp.obj")
        self.md_wayp = gl.MeshData(vertexes=self.model_wayp.returnMesh())
        self.waypoint = gl.GLMeshItem(meshdata=self.md_wayp, color=(1, 1, 1, 1),
            smooth=False, shader='shaded', glOptions='opaque')
        self.d_a.addWidget(self.w)

        #Plots Setup
        #North Displacement
        self.w_n = pg.PlotWidget(title="North Displacement")
        self.w_n.setDownsampling(mode='peak')
        self.w_n.setClipToView(True)
        self.curve_x = self.w_n.plot()
        self.curve_x_r = self.w_n.plot()
        self.w_n.setLabel('bottom', 'Time', 's')
        self.w_n.setLabel('left', 'Xn', 'm')
        self.d_n.addWidget(self.w_n)

        #East Displacement
        self.w_e = pg.PlotWidget(title="East Displacement")
        self.w_e.setDownsampling(mode='peak')
        self.w_e.setClipToView(True)
        self.curve_y = self.w_e.plot()
        self.w_e.setLabel('bottom', 'Time', 's')
        self.w_e.setLabel('left', 'Yn', 'm')
        self.d_e.addWidget(self.w_e)

        #Height
        self.w_h = pg.PlotWidget(title="Height Displacement")
        self.w_h.setDownsampling(mode='peak')
        self.w_h.setClipToView(True)
        self.curve_h = self.w_h.plot()
        self.w_h.setLabel('bottom', 'Time', 's')
        self.w_h.setLabel('left', 'h', 'm')
        self.d_h.addWidget(self.w_h)

        #Velocity V
        self.w_v = pg.PlotWidget(title="Total Velocity")
        self.w_v.setDownsampling(mode='peak')
        self.w_v.setClipToView(True)
        self.curve_V = self.w_v.plot()
        self.w_v.setLabel('bottom', 'Time', 's')
        self.w_v.setLabel('left', 'V', 'm/s')
        self.d_v.addWidget(self.w_v)

        #Velocity u
        self.w_u_ = pg.PlotWidget(title="Velocity u")
        self.w_u_.setDownsampling(mode='peak')
        self.w_u_.setClipToView(True)
        self.curve_u_ = self.w_u_.plot()
        self.w_u_.setLabel('bottom', 'Time', 's')
        self.w_u_.setLabel('left', 'u', 'm/s')
        self.d_u_.addWidget(self.w_u_)

        #Velocity v
        self.w_v_ = pg.PlotWidget(title="Velocity v")
        self.w_v_.setDownsampling(mode='peak')
        self.w_v_.setClipToView(True)
        self.curve_v_ = self.w_v_.plot()
        self.w_v_.setLabel('bottom', 'Time', 's')
        self.w_v_.setLabel('left', 'v', 'm/s')
        self.d_v_.addWidget(self.w_v_)

        #Velocity w
        self.w_w_ = pg.PlotWidget(title="Velocity w")
        self.w_w_.setDownsampling(mode='peak')
        self.w_w_.setClipToView(True)
        self.curve_w_ = self.w_w_.plot()
        self.w_w_.setLabel('bottom', 'Time', 's')
        self.w_w_.setLabel('left', 'w', 'm/s')
        self.d_w_.addWidget(self.w_w_)

        #Velocity p
        self.w_p = pg.PlotWidget(title="Rotational Velocity p")
        self.w_p.setDownsampling(mode='peak')
        self.w_p.setClipToView(True)
        self.curve_p = self.w_p.plot()
        self.w_p.setLabel('bottom', 'Time', 's')
        self.w_p.setLabel('left', 'p', 'rad/s')
        self.d_p.addWidget(self.w_p)

        #Velocity q
        self.w_q = pg.PlotWidget(title="Rotational Velocity q")
        self.w_q.setDownsampling(mode='peak')
        self.w_q.setClipToView(True)
        self.curve_q = self.w_q.plot()
        self.w_q.setLabel('bottom', 'Time', 's')
        self.w_q.setLabel('left', 'q', 'rad/s')
        self.d_q.addWidget(self.w_q)

        #Velocity q
        self.w_r = pg.PlotWidget(title="Rotational Velocity r")
        self.w_r.setDownsampling(mode='peak')
        self.w_r.setClipToView(True)
        self.curve_r = self.w_r.plot()
        self.w_r.setLabel('bottom', 'Time', 's')
        self.w_r.setLabel('left', 'r', 'rad/s')
        self.d_r.addWidget(self.w_r)

        #Roll
        self.w_phi = pg.PlotWidget(title="Roll Angle")
        self.w_phi.setDownsampling(mode='peak')
        self.w_phi.setClipToView(True)
        self.curve_phi = self.w_phi.plot()
        self.w_phi.setLabel('bottom', 'Time', 's')
        self.w_phi.setLabel('left', 'Roll Anlge', 'rad')
        self.d_phi.addWidget(self.w_phi)

        #Pitch
        self.w_theta = pg.PlotWidget(title="Pitch Angle")
        self.w_theta.setDownsampling(mode='peak')
        self.w_theta.setClipToView(True)
        self.curve_theta = self.w_theta.plot()
        self.w_theta.setLabel('bottom', 'Time', 's')
        self.w_theta.setLabel('left', 'Pitch Angle', 'rad')
        self.d_theta.addWidget(self.w_theta)

        #Yaw
        self.w_psi = pg.PlotWidget(title="Yaw Angle")
        self.w_psi.setDownsampling(mode='peak')
        self.w_psi.setClipToView(True)
        self.curve_psi = self.w_psi.plot()
        self.w_psi.setLabel('bottom', 'Time', 's')
        self.w_psi.setLabel('left', 'Yaw Angle', 'rad')
        self.d_psi.addWidget(self.w_psi)

        #Motors Rotation
        self.w_w = pg.PlotWidget(title="Motors Rotational Velocity")
        self.w_w.setDownsampling(mode='peak')
        self.w_w.setClipToView(True)
        self.curve_wl = self.w_w.plot(pen = (255,0,0))
        self.curve_wr = self.w_w.plot(pen = (0,255,0))
        self.curve_wb = self.w_w.plot(pen = (0,0,255))
        self.w_w.setLabel('bottom', 'Time', 's')
        self.w_w.setLabel('left', 'Rotational Velocity', 'rpm')
        self.w_w.addLegend()
        self.l_w = self.w_w.plotItem.legend
        self.l_w.addItem(self.curve_wl, "Left Motor")
        self.l_w.addItem(self.curve_wr, "Right Motor")
        self.l_w.addItem(self.curve_wb, "Rear Motor")
        self.d_w.addWidget(self.w_w)

        #Motors Angle
        self.w_t = pg.PlotWidget(title="Motors Angle")
        self.w_t.setDownsampling(mode='peak')
        self.w_t.setClipToView(True)
        self.curve_tl = self.w_t.plot(pen = (255,0,0))
        self.curve_tr = self.w_t.plot(pen = (0,255,0))
        self.w_t.setLabel('bottom', 'Time', 's')
        self.w_t.setLabel('left', 'Motors Angle', 'deg')
        self.d_t.addWidget(self.w_t)
        self.w_t.addLegend()
        self.l_t = self.w_t.plotItem.legend
        self.l_t.addItem(self.curve_tl, "Left Motor")
        self.l_t.addItem(self.curve_tr, "Right Motor")
        self.d_t.addWidget(self.w_t)

        #Elevons Angle
        self.w_deltae = pg.PlotWidget(title="Elevons Angle")
        self.w_deltae.setDownsampling(mode='peak')
        self.w_deltae.setClipToView(True)
        self.curve_deltael = self.w_deltae.plot(pen = (255,0,0))
        self.curve_deltaer = self.w_deltae.plot(pen = (0,255,0))
        self.w_deltae.setLabel('bottom', 'Time', 's')
        self.w_deltae.setLabel('left', 'Elevons Angle', 'deg')
        self.d_deltae.addWidget(self.w_deltae)
        self.w_deltae.addLegend()
        self.l_deltae = self.w_deltae.plotItem.legend
        self.l_deltae.addItem(self.curve_deltael, "Left Elevon")
        self.l_deltae.addItem(self.curve_deltaer, "Right Elevon")
        self.d_deltae.addWidget(self.w_deltae)

        #Data Animation
        self.pts = np.vstack([self.flight_data[self.flight.i_north],
            -self.flight_data[self.flight.i_east],
            self.flight_data[self.flight.i_height]]).transpose()
        self.plt = gl.GLLinePlotItem(pos=self.pts, color=pg.glColor(('b')),
            width=1, antialias=True)
        self.w.addItem(self.plt)

        #Reference
        self.pts_r = np.stack([self.reference_data[self.reference.i_north_r],
            -self.reference_data[self.reference.i_east_r],
            self.reference_data[self.reference.i_height_r]]).transpose()
        self.plt_r = gl.GLLinePlotItem(pos=self.pts_r, color=pg.glColor(('r')),
            width=1, antialias=True)
        # print(self.pts_r[0])
        self.w.addItem(self.plt_r)

        #Add Geometry
        self.w.addItem(self.fuselage)
        self.w.addItem(self.waypoint)
        self.ti_in = 0

    def update(self):
        self.data_initiation()
        if (self.ti_in < self.t_len):
            self.geometry_update()
            self.waypoints_update()
            self.curves_update()
            self.ti_in = self.ti_in + 1;
        else:
            self.fuselage.translate(0, 0, 0, local=False)

    def data_initiation(self):
        self.t = self.flight_data[self.flight.i_time];
        self.t_len = len(self.t)
        self.time_ = self.flight_data[self.flight.i_time]
        self.north = self.flight_data[self.flight.i_north]
        self.east = self.flight_data[self.flight.i_east]
        self.height = self.flight_data[self.flight.i_height]
        self.velocity = self.flight_data[self.flight.i_velocity]
        self.u_ = self.flight_data[self.flight.i_u]
        self.v_ = self.flight_data[self.flight.i_v]
        self.w_ = self.flight_data[self.flight.i_w]
        self.p = self.flight_data[self.flight.i_p]
        self.q = self.flight_data[self.flight.i_q]
        self.r = self.flight_data[self.flight.i_r]
        self.phi = self.flight_data[self.flight.i_phi]
        self.theta = self.flight_data[self.flight.i_theta]
        self.psi = self.flight_data[self.flight.i_psi]
        self.wl = self.flight_data[self.flight.i_wl]
        self.wr = self.flight_data[self.flight.i_wr]
        self.wb = self.flight_data[self.flight.i_wb]
        self.tl = self.flight_data[self.flight.i_tl]
        self.tr = self.flight_data[self.flight.i_tr]
        self.deltael = self.flight_data[self.flight.i_deltael]
        self.deltaer = self.flight_data[self.flight.i_deltaer]
        self.w_i = self.flight_data[self.flight.i_w_i]
        self.north_r = self.reference_data[self.reference.i_north_r]
        self.east_r = self.reference_data[self.reference.i_east_r]
        self.height_r = self.reference_data[self.reference.i_height_r]

    def geometry_update(self):
        # Fuselage
        self.fuselage.resetTransform()
        self.fuselage.rotate(np.degrees(self.psi[self.ti_in]), 0 ,0, -1, local=False)
        self.fuselage.rotate(np.degrees(self.theta[self.ti_in]), 0, -1, 0, local=True)
        self.fuselage.rotate(np.degrees(self.phi[self.ti_in]), 1, 0, 0, local=True)
        self.fuselage.translate(self.north[self.ti_in], -self.east[self.ti_in],
        self.height[self.ti_in], local=False)
        self.camera_update()

    
    def camera_update(self):
        scale_xe = 0.01
        scale_ye = 0.01
        scale_ze = 0.01
        # self.w.pan(scale_xe*self.north[self.ti_in] + 2,
        #     -scale_ye*self.east[self.ti_in] + 2,
        #     scale_ze*self.height[self.ti_in] + 2, relative=False)
        print(self.w.opts['azimuth'])

    def waypoints_update(self):
        self.waypoint.resetTransform()
        self.w_i_n = int(self.w_i[self.ti_in])
        self.waypoint.translate(self.north_r[self.w_i_n],
         -self.east_r[self.w_i_n], self.height_r[self.w_i_n], local=False)

    def curves_update(self):
        self.curve_x.setData(self.time_[:self.ti_in], self.north[:self.ti_in])
        self.curve_y.setData(self.time_[:self.ti_in], self.east[:self.ti_in])
        self.curve_h.setData(self.time_[:self.ti_in], self.height[:self.ti_in])
        self.curve_V.setData(self.time_[:self.ti_in], self.velocity[:self.ti_in])
        self.curve_u_.setData(self.time_[:self.ti_in], self.u_[:self.ti_in])
        self.curve_v_.setData(self.time_[:self.ti_in], self.v_[:self.ti_in])
        self.curve_w_.setData(self.time_[:self.ti_in], self.w_[:self.ti_in])
        self.curve_p.setData(self.time_[:self.ti_in], self.p[:self.ti_in])
        self.curve_q.setData(self.time_[:self.ti_in], self.q[:self.ti_in])
        self.curve_r.setData(self.time_[:self.ti_in], self.r[:self.ti_in])
        self.curve_phi.setData(self.time_[:self.ti_in], self.phi[:self.ti_in])
        self.curve_theta.setData(self.time_[:self.ti_in], self.theta[:self.ti_in])
        self.curve_psi.setData(self.time_[:self.ti_in], self.psi[:self.ti_in])
        self.curve_wl.setData(self.time_[:self.ti_in], self.wl[:self.ti_in])
        self.curve_wr.setData(self.time_[:self.ti_in], self.wr[:self.ti_in])
        self.curve_wb.setData(self.time_[:self.ti_in], self.wb[:self.ti_in])
        self.curve_tl.setData(self.time_[:self.ti_in], self.tl[:self.ti_in])
        self.curve_tr.setData(self.time_[:self.ti_in], self.tr[:self.ti_in])
        self.curve_deltael.setData(self.time_[:self.ti_in], self.deltael[:self.ti_in])
        self.curve_deltaer.setData(self.time_[:self.ti_in], self.deltaer[:self.ti_in])

    def start(self):
        if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
            QtGui.QApplication.instance().exec_()

    def animation(self):
        timer = QtCore.QTimer()
        timer.timeout.connect(self.update)
        timer.start(30)
        self.start()
Exemplo n.º 7
0
class Construction:
    def __init__(self):
        self.AM = Model().solve()  # return the values of the model, list
        self.one = ReadData("TTRP_01.txt")
        self.truck_num = 5
        self.trailer_num = 3
        # different TTRP_xx.txt need different argument
        # self.all_locations = [['a', ['30.0', '40.0']]] + self.one.get_locations() # 01.txt
        self.all_locations = [['a', ['30.0', '40.0']]
                              ] + self.one.get_locations()  # 02.txt

    # compute the distance of two nodes
    def compute_dist(self, i, j):
        for node in self.all_locations:
            if i == node[0]:
                cord_i = node[1]
            if j == node[0]:
                cord_j = node[1]
        dist_ij = hypot(
            float(cord_i[0]) - float(cord_j[0]),
            float(cord_i[1]) - float(cord_j[1]))
        return dist_ij

    # get the five tours
    def get_tours(self):
        seqs = []
        for i in range(self.truck_num):
            seq = range(i, self.one.customer_num * self.truck_num,
                        self.truck_num)
            seqs.append(seq)
        tours = []
        for seq in seqs:
            tour = []
            for index in seq:
                if self.AM[index] > 0.5:
                    tour.append((ceil((index + 1) / self.truck_num)) -
                                1)  # for a standard index
            tour.append('a')  # add the index of depot, awful code
            tours.append(tour)
        return tours

    # find the closest neighbor to a given node in the tour
    def closest_neighbor(self, current_tour, node):
        dists = {}
        for cus in current_tour:
            if cus == node:
                continue
            dist = self.compute_dist(node, cus)
            dists.update({cus: dist})
        return sorted(dists.items(), key=itemgetter(1))[0][0]

    # add node k between node i and node j
    def add(self, i, j, k):
        return self.compute_dist(i, k) + self.compute_dist(
            k, j) - self.compute_dist(i, j)

    def add_closest_to_tour(self, current_tour, tour):
        best_cost, new_tour = float('inf'), None
        for k in current_tour:
            if k in tour:
                continue
            for index in range(len(tour) - 1):
                cost = self.add(tour[index], tour[index + 1], k)
                if cost < best_cost:
                    best_cost = cost
                    new_tour = tour[:index + 1] + [k] + tour[index + 1:]
        return new_tour

    def cheapest_insertion(self, current_tour):
        # print("cheapest current tour", current_tour)
        # print(len(current_tour))
        # f**k = len(current_tour)
        # current_tour = self.get_tours()[0]
        # for tour in self.get_tours():
        # only 2 point, do nothing
        if len(current_tour) == 2:
            return current_tour
        # a route only one point, it means:
        # tr\pv\main_tours only have 'a'; sub-tours only have root
        elif len(current_tour) == 1:
            return []
        starter = random.choice(current_tour)
        # print(starter)
        tour, tours = [starter], []
        neighbor = self.closest_neighbor(current_tour, starter)
        tour.append(neighbor)  # the first [i, j] list
        # print(tour)
        while len(tour) != len(current_tour):
            tour = self.add_closest_to_tour(current_tour, tour)
            tours.append(tour)
            # print(tour)
        return tour

    def check_route(self, tour):
        # type_list = []
        # for tour in self.get_tours():
        types = []
        for cus in tour:
            if cus == 'a':
                types.append(2)
            else:
                types.append(self.one.get_types()[cus])
            # type_list.append(types)
        return types

    def tour_length(self, tour):
        tour_length = 0.0
        if len(tour) == 0:
            return tour_length
        elif len(tour) == 1:
            return tour_length
        elif len(tour) == 2:
            return self.compute_dist(tour[0], tour[1])
        else:
            for i in range(len(tour) - 1):
                tour_length += self.compute_dist(tour[i], tour[i + 1])
            tour_length += self.compute_dist(tour[0],
                                             tour[-1])  # because it's a circle
            return tour_length

    def pure_truck(self):
        pure_truck = []
        for route in self.get_tours()[self.trailer_num:]:
            tour = self.cheapest_insertion(route)
            # pure_truck.append([tour, self.tour_length(tour)])
            pure_truck.append(tour)
        return pure_truck

    def pure_vehicle(self):
        pure_vehicle = []
        for tour in self.get_tours()[:self.trailer_num]:
            if 1 not in self.check_route(tour):
                pure_vehicle.append(tour)
        return pure_vehicle

    def main_sub(self):
        mains_subs = []
        for tour in self.get_tours()[:self.trailer_num]:
            if 1 in self.check_route(tour):
                init_main, init_sub = [], []
                for cus in tour:
                    if cus == 'a':
                        init_main.append(cus)
                    elif self.one.get_types()[cus] == 0:
                        init_main.append(cus)
                    else:
                        init_sub.append(cus)
                mains_subs.append([init_main, init_sub])
        return mains_subs

    def sub_num(self, s):
        sub_demands = 0.0
        for cus in s:
            sub_demands += self.one.get_demands()[
                cus]  # s 中的索引和 get_demands 中的一样吗❓
        return ceil(sub_demands / self.one.truck_cap)

    # def complete_tour(self, ms):
    def complete_tour(self, ms):
        main_tour = self.cheapest_insertion(ms[0])
        # 储存所有的子路径
        # 如果只有一个子路径,查询为 subs[0]
        subs = []
        temp_s = ms[1]
        for i in range(self.sub_num(ms[1])):
            sub_demands = 0.0
            s = []
            for cus in temp_s:
                sub_demands += self.one.get_demands()[cus]
                if sub_demands < self.one.truck_cap:
                    s.append(cus)
            subs.append(s)
            # 这里是移除上面循环中符合条件的客户
            temp_s = [x for x in temp_s if x not in s]

        sub_tour = []
        for sub in subs:
            # 连接点不能是仓库,所以是 [:-1]
            connector = self.closest_neighbor(ms[0][:-1], sub[0])
            sub.append(connector)
            sub_tour.append(self.cheapest_insertion(sub))
        # complete_tours = [main_tour, sub_tour, self.tour_length(main_tour) + self.tour_length(sub_tour)]
        complete_tours = [main_tour, sub_tour]
        return complete_tours

    def all_complete_tour(self):
        complete_tours = []
        for ms in self.main_sub():
            complete_tours.append(self.complete_tour(ms))
        return complete_tours

    def total_length(self):
        length = 0.0
        for route in self.pure_truck():
            length += self.tour_length(route)
        for route in self.pure_vehicle():
            length += self.tour_length(route)
        cv = self.all_complete_tour()
        main_tours, sub_tours = [], []
        for seqs in cv:
            main_tours.append(seqs[0])
            sub_tours.append(seqs[1])  # this will be a list of list of list
        split_sub_tours = []
        for tour in sub_tours:
            split_sub_tours += tour
        for route in main_tours:
            length += self.tour_length(route)
        for route in split_sub_tours:
            length += self.tour_length(route)
        return length

    def all_route(self):
        return self.pure_truck(), self.pure_vehicle(), self.all_complete_tour()
Exemplo n.º 8
0
	def _init_attr(self):
		logger.debug('_init_attr')
		self.rd = ReadData()
Exemplo n.º 9
0
 def scrape(self):
     names = ReadData().get_all_names()
     self.parse_pages(names)
     return self._firms
Exemplo n.º 10
0
 def __init__(self):
     self.one = ReadData("TTRP_01.txt")
     self.truck_num = 5
     self.trailer_num = 3
Exemplo n.º 11
0
class Assignment:
    def __init__(self):
        self.one = ReadData("TTRP_01.txt")
        self.truck_num = 5
        self.trailer_num = 3

    def costs_all(self):
        dists_di = []
        # n = 0
        for i in self.one.get_locations():
            # (1)仓库到客户 i 的距离,存储为索引和距离的列表
            dist_di = hypot(
                float(self.one.depot_loc[0]) - float(i[1][0]),
                float(self.one.depot_loc[1]) - float(i[1][1]))
            dists_di.append([i[0], float(dist_di)])
            # n += 1 # 保证索引从 0 开始
        # print(dists_di)
        # return dists_di

    # def seed_sets(self):
    # 按照与仓库的距离选 first 种子点,选10次,拿到索引
        rank_dist = sorted(dists_di, key=lambda dist_di: dist_di[1])
        seeds1_ind = []
        dist_ds = []  # (2)存储仓库到种子点的距离值
        for i in range(10):
            seeds1_ind.append(rank_dist[i][0])
            dist_ds.append(rank_dist[i][1])
        # print(seeds1_ind)
        # print(dist_ds)

        # 选种子点集合,这部分可能在计算上有错误...
        # 选择种子点,组成 seed set,根据 1st 种子点的不同,有不同的 seed set
        seed_sets = []
        cus_sets = []
        for seed1 in seeds1_ind:
            seed_set = [seed1]
            # seed_set = [45, 10]
            # print("初始种子点:", seed_set)
            dists = []
            cus = self.one.get_locations()
            for i in seed_set:
                for j in cus:
                    if j[0] == i:
                        cus.remove(j)
            # print("初始的 cus 长度:", len(cus))
            while len(seed_set) < self.truck_num:
                dists_sum = []
                for i in cus:
                    dist_ipsum = 0.0
                    # ind_i = one.get_locations().index(i)
                    dist_i = dists_di[i[0]][1]
                    # print(dist_i)
                    for pseed in seed_set:
                        dist_ip = hypot(
                            float(i[1][0]) -
                            float(self.one.get_locations()[pseed][1][0]),
                            float(i[1][1]) -
                            float(self.one.get_locations()[pseed][1][1]))
                        dist_ipsum += dist_ip
                        # print(dist_ip)
                        # print("ipsum:", dist_ipsum)
                    dist_isum = dist_i + dist_ipsum
                    dists_sum.append([i[0], dist_isum])
                # print(len(dists_sum))
                rank_sum = sorted(dists_sum, key=lambda dist_sum: dist_sum[1])
                # print(rank_sum)
                seed_set.append(rank_sum[0][0])
                for i in cus:
                    if i[0] == rank_sum[0][0]:
                        cus.remove(i)
                # print("这里是cus:", len(cus))
            # print(seed_set)
            seed_sets.append(seed_set)
            # print("last cus", len(cus))
            cus_sets.append(cus)
        # print(len(cus_sets)) # 10组
        # print(cus_sets) # 10组 每组是除了种子点的其余点
        # print(seed_sets) # 10组 每组5个值(跟卡车数或者说路线数相同)
        # return seed_sets

    # def costs_all(self):
    # 求解指派花费 d_ij 这里的 j 是卡车数,也其实是路径数
    # cost_ij = dists_id + dist_is + dist_sd
        costs_ij = []
        # i 到种子点(五个索引的集合)
        costs_all = []
        for t in range(10):
            costs = []
            # for i in cus_sets[t]:
            #     dist_id = hypot(float(i[1][0]) - float(one.depot_loc[0]),
            #                     float(i[1][1]) - float(one.depot_loc[1]))
            for i in dists_di:
                dist_id = i[1]
                cost = []
                for seed in seed_sets[t]:
                    # dist_is = hypot(float(i[1][0]) - float(one.get_locations()[seed][1][0]),
                    #                 float(i[1][1]) - float(one.get_locations()[seed][1][1])) # 客户到各个路线的种子点的距离
                    dist_is = hypot(
                        float(self.one.get_locations()[i[0]][1][0]) -
                        float(self.one.get_locations()[seed][1][0]),
                        float(self.one.get_locations()[i[0]][1][1]) -
                        float(self.one.get_locations()[seed][1][1]))
                    dist_sd = hypot(
                        float(self.one.get_locations()[seed][1][0]) -
                        float(self.one.depot_loc[0]),
                        float(self.one.get_locations()[seed][1][1]) -
                        float(self.one.depot_loc[1]))
                    cost_ij = dist_id + dist_is + dist_sd  # 这里对每个路线下的客户 i 计算了一次 d_ij
                    cost.append(cost_ij)
                # print(cost)
                # print()
                costs.extend(cost)
            costs_all.append(costs)
            # print("应该是十组之一", len(costs)) # 长度为(剔除了路线点)客户数
        # print(len(costs_all)) # 10组
        # 哪一组是最好的呢?
        return costs_all