class ConstList: def __init__(self): self.const = None self.constList = None #Parsing to determine the amount of constants to compare to the id in the constat list def parse(self): TokList.nextToken() self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() if TokList.currentToken() == 'COMMA': self.constList = ConstList() self.constList.parse() #Simple print def print(self): print(',', end='') self.const.print() if self.constList is not None: self.constList.print() #Recursive executor that runs through all constant values in the constant list to compare to id def exec(self, caseId): if self.const.exec() == caseId.getValue(): return True if self.constList is not None: return self.constList.exec(caseId) return False
def parse(self): TokList.nextToken() self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() if TokList.currentToken() == 'COMMA': self.constList = ConstList() self.constList.parse()
def parse(self): self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() if TokList.currentToken() == 'COMMA': self.constList = ConstList() self.constList.parse() TokList.match('COLON', 'case line') self.expr = Expr() self.expr.parse() self.caseLineFollow = CaseLineFollow() self.caseLineFollow.parse()
def play(self, agent): gameString = '' lastMove = '' game = self.getGame() while not game.over(): addString, lastMove = self.turn(lastMove, agent) gameString += addString #print (Const.stateStr(game.getState())) if Const.stateStr(game.getState()) == 'x won': winner = 'x' elif Const.stateStr(game.getState()) == 'o won': winner = 'o' else: winner = 'd' return gameString, winner
def parse(self): if TokList.checkTok('CONST'): self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.checkTok('ID'): self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.match('LEFTPARAN', 'factor'): self.expr = Expr.Expr() self.expr.parse() TokList.match('RIGHTPARAN', 'factor')
def unmove(self,row,col): Const.rowOk(row) Const.colOk(col) if self._board[row][col] == Const.MARK_X: self._unplayed = self._unplayed + 1 self._board[row][col] = Const.MARK_NONE self._state = Const.STATE_TURN_X elif self._board[row][col] == Const.MARK_O: self._unplayed = self._unplayed + 1 self._board[row][col] = Const.MARK_NONE self._state = Const.STATE_TURN_O else: raise ValueError("unmove (" + str(row) + "," + str(col) + ") invalid in current state")
def __init__(self, program, selection, monitor, state, arch, abi='default'): self.currentProgram = program self.currentSelection = selection self.monitor = monitor self.state = state if self.currentProgram.getExecutableFormat() != ElfLoader.ELF_NAME: popup('Not an ELF file, cannot continue') return global CONSTANTS, ARGUMENTS, FUNCTIONS CONSTANTS = Const(arch, abi) ARGUMENTS = self.loadData('arguments', arch, abi) FUNCTIONS = self.loadData('functions', arch, abi) symEval = SymbolicPropogator(self.currentProgram) symEval.setParamRefCheck(True) symEval.setDebug(True) for func in self.currentProgram.getListing().getFunctions(True): if self.monitor.isCancelled(): return self.doCancel() if func.getName() not in FUNCTIONS: continue calls = self.getCalls(func) if calls is None: continue for call in calls: if self.currentSelection is not None: if call < self.currentSelection.getMinAddress(): continue if call > self.currentSelection.getMaxAddress(): continue if self.monitor.isCancelled(): return self.doCancel() for arg in FUNCTIONS[func.getName()]: value = self.getParameterValue(func, call, arg[0]) if value is None: continue const = self.getConstant(arg[1], value) if const is None: continue self.updateEquates(call, const, value)
def Cylindrical(r, r_Sun): ''' :param r: must be array float :param r_Sun: must be array float :return: ''' const = Const() norm_r_Sun = np.sqrt(r_Sun.dot(r_Sun)) e_Sun = r_Sun / norm_r_Sun #% Sun direction unit vector s = r.dot(e_Sun) #% Projection of s/c position norm_RSESUN = np.sqrt((r - s * e_Sun).dot(r - s * e_Sun)) if s > 0 or norm_RSESUN > const['R_Earth']: nu = 1 else: nu = 0 return nu
def play(self): game = self.getGame() while not game.over(): self.turn() self.printB(game) print("\n\n") print (Const.stateStr(game.getState()))
def __init__(self, boxsizeX, boxsizeY, boxsizeZ, particle_count = 1024 * 16, phy_val = 1.67): ''' Constructor It's important that sizes of box are multiple with r0 = h * 0.5 Because it should be integer number of boundary particles TODO: more detailed comment... ''' const = Const() Const.r0_squared = const.scale_r0(phy_val)*const.scale_r0(phy_val) self.p_count = particle_count Const.xmax = boxsizeX#( boxsizeX % Const.r0 == 0 ) and boxsizeX or ( int( boxsizeX / Const.r0 ) + 1 ) * Const.r0 # if boxsizeX divides on r0 without rest than XMAX = boxsizeX Const.ymax = boxsizeY#( boxsizeY % Const.r0 == 0 ) and boxsizeY or ( int( boxsizeY / Const.r0 ) + 1 ) * Const.r0 # same Const.zmax = boxsizeZ#( boxsizeZ % Const.r0 == 0 ) and boxsizeZ or ( int( boxsizeZ / Const.r0 ) + 1 ) * Const.r0 # same self.particles = [] self.elasticConnections = [] self.membranes = [] self.part_memb_index = []
def __str__(self): ans = "\n" for row in range(Const.ROWS): s=""; for col in range(Const.COLS): s=s+Const.markStr(self._board[row][col]) ans = ans + s + "\n" return ans
def iauFave03(t): const=Const() # % Mean longitude of Venus (IERS Conventions 2003) a = ((3.176146697 + 1021.3285546211 * t)%const['D2PI']) return a
def addConstant(self, constant_or_name, init_value): new_constant = None if init_value == None: new_constant = constant_or_name else: new_constant = Const(constant_or_name, init_value) self.constants.append(new_constant) self.map_constants[new_constant.name] = len(self.constants) - 1 return new_constant
def iauFae03(t): const=Const() # % Mean longitude of Earth (IERS Conventions 2003). a = ((1.753470314 + 628.3075849991 * t) % const['D2PI']) return a
def get_ground_station_postion_ICRF(t, lat, lon, alt, MJD_UTC_Start): ''' :param t:相对仿真起始点的时间/s :param r_ITRS: 地固坐标系 m :return: 地心惯性坐标系 m ''' x, y, z = pm.geodetic2ecef(lat, lon, alt) #默认为WGS84椭球体 r_ITRS = np.array([x, y, z]) const = Const() MJD_UTC = MJD_UTC_Start + t / 86400 # JD = MJD_UTC + 2400000.5 x_pole, y_pole, UT1_UTC, LOD, dpsi, deps, dx_pole, dy_pole, TAI_UTC = IERS( Global_parameters.eopdata, MJD_UTC, 'l') UT1_TAI, UTC_GPS, UT1_GPS, TT_UTC, GPS_UTC = timediff(UT1_UTC, TAI_UTC) JD = MJD_UTC + 2400000.5 year, month, day, hour, minute, sec = invjday(JD) DJMJD0, DATE = iauCal2jd(year, month, day) TIME = (60 * (60 * hour + minute) + sec) / 86400 UTC = DATE + TIME TT = UTC + TT_UTC / 86400 #Terrestrial Time (TT) Terrestrial Time (TT) # used to be known as Terrestrial Dynamical Time (TDT) TUT = TIME + UT1_UTC / 86400 UT1 = DATE + TUT #Polar motion matrix (TIRS->ITRS, IERS 2003) Pi = iauPom00(x_pole, y_pole, iauSp00(DJMJD0, TT)) #Form bias-precession-nutation matrix NPB = iauPnm06a(DJMJD0, TT) #% Form Earth rotation matrix gast = iauGst06(DJMJD0, UT1, DJMJD0, TT, NPB) Theta = iauRz(gast, np.eye(3)) #ICRS to ITRS transformation E = np.dot(np.dot(Pi, Theta), NPB) #ITRS to ICRS transformation E_1 = np.linalg.inv(E) r_ICRF = np.dot(E_1, r_ITRS) return r_ICRF
def IERS(eop, Mjd_UTC, interp): const = Const() if (interp == 'l'): # % linear interpolation mjd = (floor(Mjd_UTC)) i = np.nonzero(mjd == eop[3, :]) i = i[-1] i = i[-1] preeop = eop[:, i] nexteop = eop[:, i + 1] mfme = 1440 * (Mjd_UTC - floor(Mjd_UTC)) fixf = mfme / 1440 #% Setting of IERS Earth rotation parameters #% (UT1-UTC [s], TAI-UTC [s], x ["], y ["]) x_pole = preeop[4] + (nexteop[4] - preeop[4]) * fixf y_pole = preeop[5] + (nexteop[5] - preeop[5]) * fixf UT1_UTC = preeop[6] + (nexteop[6] - preeop[6]) * fixf LOD = preeop[7] + (nexteop[7] - preeop[7]) * fixf dpsi = preeop[8] + (nexteop[8] - preeop[8]) * fixf deps = preeop[9] + (nexteop[9] - preeop[9]) * fixf dx_pole = preeop[10] + (nexteop[10] - preeop[10]) * fixf dy_pole = preeop[11] + (nexteop[11] - preeop[11]) * fixf TAI_UTC = preeop[12] x_pole = x_pole / const['Arcs'] # % Pole coordinate [rad] y_pole = y_pole / const['Arcs'] #% Pole coordinate [rad] dpsi = dpsi / const['Arcs'] deps = deps / const['Arcs'] dx_pole = dx_pole / const['Arcs'] #% Pole coordinate [rad] dy_pole = dy_pole / const['Arcs'] #% Pole coordinate [rad] else: mjd = (floor(Mjd_UTC)) i = np.nonzero(mjd == eop[3, :]) i = i[-1] i = i[-1] eop = eop[:, i] #% Setting of IERS Earth rotation parameters #% (UT1-UTC [s], TAI-UTC [s], x ["], y ["]) x_pole = eop[4] / const['Arcs'] #% Pole coordinate [rad] y_pole = eop[5] / const['Arcs'] #% Pole coordinate [rad] UT1_UTC = eop[6] #% UT1-UTC time difference [s] LOD = eop[7] #% Length of day [s] dpsi = eop[8] / const['Arcs'] deps = eop[9] / const['Arcs'] dx_pole = eop[10] / const['Arcs'] #% Pole coordinate [rad] dy_pole = eop[11] / const['Arcs'] #% Pole coordinate [rad] TAI_UTC = eop[12] #% TAI-UTC time difference [s] return x_pole, y_pole, UT1_UTC, LOD, dpsi, deps, dx_pole, dy_pole, TAI_UTC
def iauFaom03(t): const = Const() # % Mean longitude of the Moon's ascending node (IERS Conventions 2003). a = ((450160.398036 + t * (-6962890.5431 + t * (7.4722 + t * (0.007702 + t * (-0.00005939))))) % const['TURNAS']) * const['DAS2R'] return a
def iauSp00(date1, date2): const = Const() # % Interval between fundamental epoch J2000.0 and current date (JC). t = ((date1 - const['DJ00']) + date2) / const['DJC'] # % Approximate s'. sp = -47e-6 * t * const['DAS2R'] return sp
class CaseLine: def __init__(self): self.const = None self.constList = None self.expr = None self.caseLineFollow = None #Parsing for CaseLine based on the homework def parse(self): self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() if TokList.currentToken() == 'COMMA': self.constList = ConstList() self.constList.parse() TokList.match('COLON', 'case line') self.expr = Expr() self.expr.parse() self.caseLineFollow = CaseLineFollow() self.caseLineFollow.parse() #Simple printing def print(self): self.const.print() if self.constList is not None: self.constList.print() print(':', end='') self.expr.print() self.caseLineFollow.print() #Exectuion that returns a boolean based on idValue and constants given def exec(self, caseId): if self.const.exec() == caseId.getValue(): caseId.setValue(self.expr.exec()) return True if self.constList is not None: if self.constList.exec(caseId): caseId.setValue(self.expr.exec()) return True if self.caseLineFollow.exec(caseId): return True return False
def iauAnp(a): const = Const() w = a % const['D2PI'] if (w < 0): w = w + const['D2PI'] return w
def iauFalp03(t): const = Const() # % Mean anomaly of the Sun (IERS Conventions 2003). a = ((1287104.793048 + t * (129596581.0481 + t * (-0.5532 + t * (0.000136 + t * (-0.00001149))))) % const['TURNAS']) * const['DAS2R'] return a
def iauFal03(t): const=Const() # % Mean anomaly of the Moon (IERS Conventions 2003). a = ( (485868.249036 + t * ( 1717915923.2178 + t * ( 31.8792 + t * ( 0.051635 + t * ( - 0.00024470 ) ) ) ))% const['TURNAS'] ) * const['DAS2R'] return a
def __init__(self, row, col, mark): Const.rowOk(row) Const.colOk(col) if mark != None: Const.markOk(mark) self._row = row self._col = col self._mark = mark
class Factor: def __init__(self): self.const = None self.id = None self.expr = None #Simple parsing that checks for constant, Id, or paranthesis def parse(self): if TokList.checkTok('CONST'): self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.checkTok('ID'): self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.match('LEFTPARAN', 'factor'): self.expr = Expr.Expr() self.expr.parse() TokList.match('RIGHTPARAN', 'factor') #Simple print statement def print(self): if self.const is not None: self.const.print() elif self.id is not None: self.id.print() elif self.expr is not None: print('(', end='') self.expr.print() print(')', end='') #Simple execution statement that returns a value based on parsing def exec(self): if self.const is not None: return self.const.exec() elif self.id is not None: return self.id.exec() elif self.expr is not None: return self.expr.exec()
def __init__(self, boxsizeX, boxsizeY, boxsizeZ, particle_count=1024 * 16, phy_val=1.67): ''' Constructor It's important that sizes of box are multiple with r0 = h * 0.5 Because it should be integer number of boundary particles TODO: more detailed comment... ''' const = Const() Const.r0_squared = const.scale_r0(phy_val) * const.scale_r0(phy_val) self.p_count = particle_count Const.xmax = boxsizeX #( boxsizeX % Const.r0 == 0 ) and boxsizeX or ( int( boxsizeX / Const.r0 ) + 1 ) * Const.r0 # if boxsizeX divides on r0 without rest than XMAX = boxsizeX Const.ymax = boxsizeY #( boxsizeY % Const.r0 == 0 ) and boxsizeY or ( int( boxsizeY / Const.r0 ) + 1 ) * Const.r0 # same Const.zmax = boxsizeZ #( boxsizeZ % Const.r0 == 0 ) and boxsizeZ or ( int( boxsizeZ / Const.r0 ) + 1 ) * Const.r0 # same self.particles = [] self.elasticConnections = [] self.membranes = [] self.part_memb_index = []
def turn(self): game=self.getGame() state=game.getState() if state == Const.STATE_TURN_O: move = self.getAgentO().move(game) print(move) move.play(game) elif state == Const.STATE_TURN_X: move = self.getAgentX().move(game) print(move) move.play(game) else: raise ValueError("invalid game state (" + Const.stateStr(game.getState()) + ")")
def iauFaf03(t): const = Const() # % Mean longitude of the Moon minus that of the ascending node # % (IERS Conventions 2003). a = ((335779.526232 + t * (1739527262.8478 + t * (-12.7512 + t * (-0.001037 + t * (0.00000417))))) % const['TURNAS']) * const['DAS2R'] return a
def Relativity(r, v): const = Const() # % Relative position vector of satellite w.r.t. point mass r_Sat = np.sqrt(r.dot(r)) v_Sat = np.sqrt(v.dot(v)) # % Acceleration a = const['GM_Earth']/((const['c_light']**2)*(r_Sat**3))\ *((4*const['GM_Earth']/r_Sat-v_Sat**2)*r+4*r.dot(v)*v) return a
def iauObl06(date1, date2): const=Const() # % Interval between fundamental date J2000.0 and given date (JC). t = ((date1 - const['DJ00']) + date2) / const['DJC'] # % Mean obliquity. eps0 = (84381.406 + (-46.836769 + ( -0.0001831 + ( 0.00200340 + ( -0.000000576 + ( -0.0000000434) * t) * t) * t) * t) * t) * const['DAS2R'] return eps0
def moveOk(self,row,col,mark): Const.rowOk(row) Const.colOk(col) Const.markOk(mark) if (self._state == Const.STATE_TURN_O) and (mark == Const.MARK_O) and \ self._board[row][col] == Const.MARK_NONE: return if (self._state == Const.STATE_TURN_X) and (mark == Const.MARK_X) and \ self._board[row][col] == Const.MARK_NONE: return raise ValueError("move (" + str(Move(mark,row,col)) + ") invalid in current state")
def Geodetic(r): const = Const() R_equ = const['R_Earth'] f = const['f_Earth'] eps = 2.22044604925031e-16 epsRequ = eps * R_equ # % Convergence criterion e2 = f * (2 - f) # % Square of eccentricity X = r[0] #% Cartesian coordinates Y = r[1] Z = r[2] rho2 = X * X + Y * Y #% Square of distance from z-axis # % Check validity of input data norm_r = sqrt(r[0]**2 + r[1]**2 + r[2]**2) if norm_r == 0: print(' invalid input in Geodetic constructor\n') lon = 0 lat = 0 h = -const['R_Earth'] return lon, lat, h # % Iteration dZ = e2 * Z while 1: ZdZ = Z + dZ Nh = sqrt(rho2 + ZdZ * ZdZ) SinPhi = ZdZ / Nh #% Sine of geodetic latitude N = R_equ / sqrt(1 - e2 * SinPhi * SinPhi) dZ_new = N * e2 * SinPhi if abs(dZ - dZ_new) < epsRequ: break dZ = dZ_new # % Longitude, latitude, altitude lon = atan2(Y, X) lat = atan2(ZdZ, sqrt(rho2)) h = Nh - N return lon, lat, h