def test_transitions(): """ Ensure that actions result in expected state transition behavior. """ # [[manually set state, manually turn off stochasticity ie deterministic, # and observe transitions, reward, etc.]] default_map_dir = os.path.join( __rlpy_location__, "Domains", "SystemAdministratorMaps") domain = SystemAdministrator(networkmapname=os.path.join( default_map_dir, "5Machines.txt")) dummyS = domain.s0() up = domain.RUNNING # shorthand down = domain.BROKEN # shorthand state = np.array([up for dummy in xrange(0, domain.state_space_dims)]) domain.state = state.copy() a = 5 # =n on this 5-machine map, ie no action ns = state.copy() # Test that no penalty is applied for a non-reboot action r, ns, t, pA = domain.step(a) numWorking = len(np.where(ns == up)[0]) if domain.IS_RING and domain.state[0] == self.RUNNING: r = r-1 # remove the correctin for rings / symmetry assert r == numWorking # Test that penalty is applied for reboot r, ns, t, pA = domain.step(0) # restart computer 0 numWorking = len(np.where(ns == up)[0]) if domain.IS_RING and domain.state[0] == self.RUNNING: r = r-1 # remove the correctin for rings / symmetry assert r == numWorking + domain.REBOOT_REWARD while np.all(ns == up): r, ns, t, pA = domain.step(a) # now at least 1 machine has failed domain.P_SELF_REPAIR = 0.0 domain.P_REBOOT_REPAIR = 0.0 # Test that machine remains down when no reboot taken fMachine = np.where(ns == down)[0][0] r, ns, t, pA = domain.step(fMachine) assert ns[fMachine] == down # Test that machine becomes up when reboot taken domain.P_REBOOT_REPAIR = 1.0 r, ns, t, pA = domain.step(fMachine) assert ns[fMachine] == up
def makeComponents(self): map_type = str(self.lstMap.currentItem().text()) domain = SystemAdministrator(networkmapname=os.path.join( SystemAdministrator.default_map_dir, map_type+'.txt')) domain.P_SELF_REPAIR = self.spSelfRepairProb.value() domain.P_REBOOT_REPAIR = self.spRobotRepairProb.value() domain.REBOOT_REWARD = self.spRobotReward.value() representation = RepresentationFactory.get(config=self.representationConfig, name=str(self.lstRepresentation.currentItem().text()), domain=domain) policy = PolicyFactory.get(config=self.policyConfig, name=str(self.lstPolicy.currentItem().text()), representation=representation) agent = AgentFactory.get(config=self.agentConfig, name=str(self.lstAgent.currentItem().text()), representation=representation, policy=policy) return domain, agent
def makeComponents(self): map_type = str(self.lstMap.currentItem().text()) domain = SystemAdministrator(networkmapname=os.path.join( SystemAdministrator.default_map_dir, map_type + '.txt')) domain.P_SELF_REPAIR = self.spSelfRepairProb.value() domain.P_REBOOT_REPAIR = self.spRobotRepairProb.value() domain.REBOOT_REWARD = self.spRobotReward.value() representation = RepresentationFactory.get( config=self.representationConfig, name=str(self.lstRepresentation.currentItem().text()), domain=domain) policy = PolicyFactory.get(config=self.policyConfig, name=str( self.lstPolicy.currentItem().text()), representation=representation) agent = AgentFactory.get(config=self.agentConfig, name=str(self.lstAgent.currentItem().text()), representation=representation, policy=policy) return domain, agent