def reverse(self): if self.queue.isEmpty(): return reversedStack = Stack() for i in range(self.queue.size): reversedStack.push(self.queue.pop().data) self.queue = reversedStack self.isReversed = not self.isReversed
def push(self, newData): if self.isCapacityFull(): # add new stack newStack = Stack() newStack.push(newData) self.set.append(newStack) self.singleStackCapacity += 1 print("New stack is created") print("New capacity is " + str(self.singleStackCapacity)) else: lastStackIndex = len(self.set) - 1 self.set[lastStackIndex].push(newData)
def reverse(self, newData=None): reversedStack = Stack() if not newData: for i in range(self.size): reversedStack.pushNode(self.pop()) else: isAddedNewNode = False for i in range(self.size): # big to small newNode = Node(newData) if newData < self.peek().data and not isAddedNewNode: #insert first reversedStack.pushNode(newNode) isAddedNewNode = True reversedStack.pushNode(self.pop()) if not isAddedNewNode: reversedStack.pushNode(newNode) return reversedStack
class MyQueue: def __init__(self): self.queue = Stack() self.isReversed = False def reverse(self): if self.queue.isEmpty(): return reversedStack = Stack() for i in range(self.queue.size): reversedStack.push(self.queue.pop().data) self.queue = reversedStack self.isReversed = not self.isReversed def dequeue(self): if not self.isReversed: # need to reverse to pop the first element self.reverse() if self.queue.isEmpty(): print("Error! the queue is empty") return node = self.queue.pop() return node def enqueue(self, newData): if self.isReversed: # need to reverse to push to the last element self.reverse() self.queue.push(newData) def print(self): self.queue.print()
import torch from DQN_Net import DQN_Net import gym from Utils.Stack import Stack from Utils.Stack import StackRam from Utils.Preprocessor import PreprocessorGray from Utils.Preprocessor import PreprocessorRam env = gym.make("SpaceInvaders-v0") ramenv = gym.make("SpaceInvaders-ram-v0") ppg = PreprocessorGray(84, 84) ppr = PreprocessorRam() stackg = Stack(4, ppg) stackr = StackRam(4, ppr) pixduel_net = DQN_Net(channels=1, frame_stack=4, observation_space=(84, 84), action_space=4, lr=0.00025, loss="huber", reduction="elementwise_mean", dueling=True, optim="sgd") pix_net = DQN_Net(channels=1, frame_stack=4, observation_space=(84, 84), action_space=4, lr=0.00025, loss="huber",
def __init__(self): self.queue = Stack() self.isReversed = False
def __init__(self): self.set = [] self.set.append(Stack()) self.singleStackCapacity = 1