Beispiel #1
0
 def remember(self, densities, reward):
     state = self.local_state
     action = self.action
     self.assign_local_state(densities)
     new_state = self.local_state
     times = {'old': Globals().time - 1, 'new': Globals().time}
     memory = Memory(state=state, action=action, new_state=new_state, reward=reward, times=times)
     self.memories.append(memory)
Beispiel #2
0
        def createMemory():
            #Memory size input
            resultValue = self.view.insertMemSizeMessage()

            #Verify if value is not none
            if resultValue is 0 or resultValue is None:
                self.view.programFinishMessage()
                exit()
            #Verify if value is less than 0
            elif resultValue < 0:
                self.view.incorrectValueMessage()
                self.view.tryAgainMessage()
                createMemory()
            else:
                try:
                    Memory.createMemories(self, resultValue)
                    return True
                except Exception as error:
                    self.view.failedToCreateMemoryMessage()
                    print(error)
                    self.view.programFinishMessage()
                    exit()
Beispiel #3
0
        def createProcess():
            allMemoriesList = Memory.memory_List
            self.view.insertProcessChosen()

            #Returning 'name' and 'size'
            processInfo = self.view.createProcessMessage()

            #Check if dict is not null
            if processInfo != None:
                processName = processInfo['name']
                processSize = processInfo['size']

                counter = 0
                for each in allMemoriesList:
                    if processSize <= each.memory_MaxForProcess:
                        counter += 1

                if counter > 0:
                    newProcess = Process(processName, processSize)

                    for each in allMemoriesList:
                        if processSize > each.memory_MaxForProcess:
                            #print(each) Criar view depois
                            self.view.notAvailableMemoryMessage(
                                each.memoryName())
                        else:
                            if each.memory_Id == 0:
                                #FirstFit
                                content = Memory.firstFit(
                                    each, newProcess.process_Size,
                                    newProcess.process_PID)
                                newProcess.process_Memories[
                                    'First Fit'] = content['position']
                                self.view.showFitPosition(
                                    content['fit'], content['position'])
                            elif each.memory_Id == 1:
                                #BestFit
                                content = Memory.bestFit(
                                    each, newProcess.process_Size,
                                    newProcess.process_PID)
                                newProcess.process_Memories[
                                    'Best Fit'] = content['position']
                                self.view.showFitPosition(
                                    content['fit'], content['position'])
                            elif each.memory_Id == 2:
                                #WorstFit
                                content = Memory.worstFit(
                                    each, newProcess.process_Size,
                                    newProcess.process_PID)
                                newProcess.process_Memories[
                                    'Worst Fit'] = content['position']
                                self.view.showFitPosition(
                                    content['fit'], content['position'])
                            else:
                                #CircularFit
                                content = Memory.circularFit(
                                    each, newProcess.process_Size,
                                    newProcess.process_PID)
                                newProcess.process_Memories[
                                    'Circular Fit'] = content['position']
                                self.view.showFitPosition(
                                    content['fit'], content['position'])
                else:
                    self.view.processNotCreatedMessage()
                    self.view.clickToContinueMessage()
                    return
            else:
                self.view.clickToContinueMessage()
                return

            self.view.successfullyCreatedProcessMessage(
                newProcess.process_Name, newProcess.process_PID)
            self.view.clickToContinueMessage()