def test_GenerosityPole(self): curstate1 = State({"f1": 100}, {"i1": 0}) desState1 = State({'f1': 1000}, {'i1': 1000}) test_polelow = GenerosityPole(-1, 1) test_polemiddle = GenerosityPole(0, 1) test_polehigh = GenerosityPole(1, 1) move1 = Move({"f1": 100, "f2": 0}, {"i1": 1}, [], 1, None) # most expensive move2 = Move({"f1": 75, "f2": 0}, {"i1": 1}, [], 1, None) move3 = Move({"f1": 45, "f2": 0}, {"i1": 1}, [], 1, None) move4 = Move({"f1": 0, "f2": 0}, {"i1": 1}, [], 1, None) test_MST1 = MST(curstate1, desState1, [move1, move2, move3, move4], 2) test_MST2 = MST(curstate1, desState1, [move1, move2, move3, move4], 2) test_MST3 = MST(curstate1, desState1, [move1, move2, move3, move4], 2) actorlow = Actor([test_polelow], curstate1, None, None, .05, None, None, [], []) actormiddle = Actor([test_polemiddle], curstate1, None, None, .05, None, None, [], []) actorhigh = Actor([test_polehigh], curstate1, None, None, .05, None, None, [], []) low_mst = test_polelow.actOnMST(test_MST1, actorlow) mid_mst = test_polemiddle.actOnMST(test_MST2, actormiddle) high_mst = test_polehigh.actOnMST(test_MST3, actorhigh) self.assertTrue(len(low_mst.getMoves()) == 1) self.assertTrue(len(high_mst.getMoves()) == 4) self.assertTrue(len(mid_mst.getMoves()) == 2) self.assertTrue(True) if __name__ == '__main__': unittest.main()
def test_EmotionalPole(self): curstate1 = State({"f1": 100}, {"i1": 0}) desState1 = State({'f1': 1000}, {'i1': 1000}) test_polelow = EmotionalPole(-.81, 1) test_polemiddle = EmotionalPole(.5, 1) test_polehigh = EmotionalPole(1, 1) move1 = Move({"f1": 0}, {"i1": 0}, [], .5, 'Engage in diplomatic cooperation') # .6-.8 move2 = Move({"f1": 0}, {"i1": 0}, [], .5, 'Appeal') # 4-6 move3 = Move({"f1": 0}, {"i1": 0}, [], .5, 'Build economic infrastructure') # .5-.7 move4 = Move({"f1": 0}, {"i1": 0}, [], .5, 'Assault') # -.2 move5 = Move({"f1": 0}, {"i1": 0}, [], .5, 'Coerce') # -.8 test_MST1 = MST(curstate1, desState1, [move1, move2, move3, move4, move5], 2) test_MST2 = MST(curstate1, desState1, [move1, move2, move3, move4, move5], 2) test_MST3 = MST(curstate1, desState1, [move1, move2, move3, move4, move5], 2) actorlow = Actor([test_polelow], curstate1, None, None, .05, None, None, [], []) actormiddle = Actor([test_polemiddle], curstate1, None, None, .05, None, None, [], []) actorhigh = Actor([test_polehigh], curstate1, None, None, .05, None, None, [], []) low_mst = test_polelow.actOnMST(test_MST1, actorlow) mid_mst = test_polemiddle.actOnMST(test_MST2, actormiddle) high_mst = test_polehigh.actOnMST(test_MST3, actorhigh) self.assertTrue(low_mst.containsMove(move5)) self.assertFalse(low_mst.containsMove(move1) and low_mst.containsMove(move2) and low_mst.containsMove( move3) and low_mst.containsMove(move4)) self.assertFalse(mid_mst.containsMove(move1)) self.assertFalse(mid_mst.containsMove(move4)) self.assertFalse(mid_mst.containsMove(move5)) self.assertTrue(mid_mst.containsMove(move2)) self.assertFalse(mid_mst.containsMove(move3))
def test_RiskPole(self): curstate1 = State({"f1": 100, "f2": 0}, {"i1": 0}) desState1 = State({'f1': 1000}, {'i1': 1000}) move1 = Move({"f1": 0, "f2": 0}, {"i1": 1}, [], 1, None) move2 = Move({"f1": 50, "f2": 0}, {"i1": 2}, [], 1, None) move3 = Move({"f1": 100, "f2": 0}, {"i1": 3}, [], 1, None) move4 = Move({"f1": 200, "f2": 0}, {"i1": 3}, [], 1, None) test_MST1 = MST(curstate1, desState1, [move1, move2, move3, move4], 2) test_MST2 = MST(curstate1, desState1, [move1, move2, move3, move4], 2) test_MST3 = MST(curstate1, desState1, [move1, move2, move3, move4], 2) test_polelow = RiskPole(-1, 1) test_polemiddle = RiskPole(0, 1) test_polehigh = RiskPole(1, 1) actorlow = Actor([test_polelow], curstate1, None, None, 0.05, None, None, [], None) # actormiddle = Actor([test_polemiddle], curstate1, None, None, 0.05, None, None, [], None) # actorhigh = Actor([test_polehigh], curstate1, None, None, 0.05, None, None, [], None) low_mst = test_polelow.actOnMST(test_MST1, actorlow) # contain only move1 mid_mst = test_polemiddle.actOnMST(test_MST2, actormiddle) # containmove1 and 2 high_mst = test_polehigh.actOnMST(test_MST3, actorhigh) # contain 123 self.assertTrue(low_mst.containsMove(move1)) self.assertFalse(low_mst.containsMove(move2)) self.assertFalse(low_mst.containsMove(move3)) self.assertFalse(low_mst.containsMove(move4)) self.assertTrue(mid_mst.containsMove(move1)) self.assertTrue(mid_mst.containsMove(move2)) self.assertFalse(mid_mst.containsMove(move3)) self.assertFalse(mid_mst.containsMove(move4)) self.assertTrue(high_mst.containsMove(move1)) self.assertTrue(high_mst.containsMove(move2)) self.assertTrue(high_mst.containsMove(move3)) self.assertFalse(high_mst.containsMove(move4))
def test_rationalityPole(self): move1 = Move({"f1": 1}, {"i1": 1}, [], 0, None) move2 = Move({"f1": 2}, {"i1": 2}, [], .45, None) move3 = Move({"f1": 3}, {"i1": 3}, [], .95, None) curstate1 = State({'f1': 0}, {'i1': 0}) desState1 = State({'f1': 100}, {'i1': 100}) test_MST1 = MST(curstate1, desState1, [move1, move2, move3], 2) test_MST2 = MST(curstate1, desState1, [move1, move2, move3], 2) test_MST3 = MST(curstate1, desState1, [move1, move2, move3], 2) test_polelow = RationalityPole(-1, 1) test_polemiddle = RationalityPole(0, 1) test_polehigh = RationalityPole(1, 1) actorlow = Actor([test_polelow], None, None, None, 0.05, None, None, [], None) # will remove no moves actormiddle = Actor([test_polemiddle], None, None, None, 0.05, None, None, [], None) # will remove move1 actorhigh = Actor([test_polehigh], None, None, None, 0.05, None, None, [], None) # will remove move1, move2 low_mst = test_polelow.actOnMST(test_MST1, actorlow) self.assertTrue(low_mst.containsMove(move1) and low_mst.containsMove(move2) and low_mst.containsMove(move3)) mid_mst = test_polemiddle.actOnMST(test_MST2, actormiddle) print("middle test_MST") self.assertTrue(mid_mst.containsMove(move2)) self.assertFalse(mid_mst.containsMove(move1)) self.assertTrue(mid_mst.containsMove(move3)) high_mst = test_polehigh.actOnMST(test_MST3, actorhigh) self.assertTrue(high_mst.containsMove(move3)) self.assertFalse(high_mst.containsMove(move1)) self.assertFalse(high_mst.containsMove(move2))
def testMSTremove(self): curstate1 = State({'f1': 0}, {'i1:': 0}) desState1 = State({'f1': 100}, {'i1:': 100}) curState2 = State({'f1': 0}, {'i1:': 0}) desState2 = State({'f1': 0}, {'i1:': 0}) move1 = Move({"f1": 1}, {'i1:': 0}, [], .5, None) move2 = Move({"f1": 2}, {'i1:': 0}, [], .5, None) move0 = Move({"f1": 0}, {'i1:': 0}, [], 0, None) moves = [move1, move2, move0] test_mst1 = MST(curstate1, desState1, moves, 2) print(len(test_mst1.getMoves())) G = test_mst1.graph edges = [ G[test_mst1.currentState][childNode]['object'] for childNode in test_mst1.graph.neighbors(test_mst1.currentState) ] self.assertTrue(move0 in edges) self.assertTrue(test_mst1.containsMove(move0)) test_mst1.removeMove(move0) G1 = test_mst1.graph # edges = G1.edges() # edges = [G1[node1][node2]['object'] for (node1, node2) in edges] edges = [ G1[test_mst1.currentState][childNode]['object'] for childNode in test_mst1.graph.neighbors(test_mst1.currentState) ] self.assertFalse(move0 in edges) self.assertFalse(test_mst1.containsMove(move0))
def map_moves(moves): move_map = {} IO_string_set = set() for move in moves: IO_list = [IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] IO_string = list_to_string(IO_list) while IO_string in IO_string_set: IO_list = [IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] IO_string = list_to_string(IO_list) IO_string_set.add(IO_string) IO_string = list_to_string(IO_list) # TODO fill category in csv file. Random category for now. Blocks Emotional pole from working correctly. move_map[IO_string] = Move(move["code"], move["move_name"], move["move_type"], IO_list, move["ph"], [resource.strip() for resource in move["low_resources"].replace(",", " ").split()], [resource.strip() for resource in move["med_resources"].replace(",", " ").split()], [resource.strip() for resource in move["high_resources"].replace(",", " ").split()], move["infrastructure"], category='Build political infrastructure') return move_map
def test_GenerosityPole(self): test_polelow = GenerosityPole(-1, 1) test_polemiddle = GenerosityPole(0, 1) test_polehigh = GenerosityPole(1, 1) actorlow = Actor([test_polelow], None, None, None, .05, None, None, [], []) actormiddle = Actor([test_polemiddle], None, None, None, .05, None, None, [], []) actorhigh = Actor([test_polehigh], None, None, None, .05, None, None, [], []) move1 = Move({ "test1": 100, "test2": 100, "test3": 100 }, None, [], .5, None) move2 = Move({ "test1": 200, "test2": 200, "test3": 200 }, None, [], .5, None) move3 = Move({"test1": 0, "test2": 0, "test3": 0}, None, [], .5, None) move4 = Move({ "test1": 1000, "test2": 1000, "test3": 1000 }, None, [], .5, None) move5 = Move({ "test1": 500, "test2": 1000, "test3": 1000 }, None, [], .5, None) moves = [move1, move2, move3, move4, move5] moveslow = test_polelow.actOnList(moves, actorlow) movesmiddle = test_polemiddle.actOnList(moves, actormiddle) moveshigh = test_polehigh.actOnList(moves, actorhigh) self.assertTrue(move3 in moveslow) self.assertTrue(len(moveslow) == 1) self.assertTrue(len(moveshigh) == 5) self.assertTrue((move4 not in movesmiddle))
def test_EmotionalPole(self): # need to make categories and see if they add moves # pretty much only need to make actors, poles, and moves w only categories test_polelow = EmotionalPole(-.21, 1) test_polemiddle = EmotionalPole(0, 1) test_polehigh = EmotionalPole(.6, 1) actorlow = Actor([test_polelow], None, None, None, 0.05, None, None, [], []) actormiddle = Actor([test_polemiddle], None, None, None, 0.05, None, None, [], []) actorhigh = Actor([test_polehigh], None, None, None, 0.05, None, None, [], []) move1 = Event( None, None, Move({"t1": 0}, None, [], .5, 'Engage in diplomatic cooperation'), 0) move2 = Event( None, None, Move({"t1": 0}, None, [], .5, 'Engage in in material cooperation'), 0) move3 = Event(None, None, Move({"t1": 0}, None, [], .5, 'Appeal'), 0) # .4-.6 move4 = Event( None, None, Move({"t1": 0}, None, [], .5, 'Build economic infrastructure'), 0) move5 = Event( None, None, Move({"t1": 0}, None, [], .5, 'Build energy infrastructure'), 0) move6 = Event( None, None, Move({"t1": 0}, None, [], .5, 'Build military infrastructure'), 0) moveneg = Event(None, None, Move({"t1": 0}, None, [], .5, 'Assault'), 0) moveneg2 = Event(None, None, Move({"t1": 0}, None, [], .5, 'Coerce'), 0) history = [move1, move2, move3, move4, move5, move6, moveneg, moveneg2] actorlow.history = history actormiddle.history = history actorhigh.history = history moves = [] moveslow = test_polelow.actOnList(moves, actorlow) movesmiddle = test_polemiddle.actOnList(moves, actormiddle) moveshigh = test_polehigh.actOnList(moves, actorhigh) print("emotionalpole move length") print(len(moveslow)) print(len(movesmiddle)) print(len(moveshigh))
def test_ParticularHolisticPole(self): move1 = Move({ "test1": 5, "test2": 10, "test3": 20 }, None, [0, 0, 0, 0], .5, None) move2 = Move({ "test1": 100, "test2": 200, "test3": 300 }, None, [15, 20, 14, 19], .5, None) move3 = Move({ "test1": 1, "test2": 1, "test3": 1 }, None, [200, -350, 900, 3], .5, None) move4 = Move({ "test1": -10, "test2": 10, "test3": -100 }, None, [39, 189, 289, 398], .5, None) move5 = Move({ "test1": 500, "test2": 1000, "test3": 10000 }, None, [10, 20, 30, 40], .5, None) move0 = Move({ "test1": 0, "test2": 0, "test3": 0 }, None, [1000, 1000, 1000, 1000], 0, None) moves = [move1, move2, move3, move4, move5, move0] test_polelow = ParticularHolisticPole(-1, 1) test_polemiddle = ParticularHolisticPole(0, 1) test_polehigh = ParticularHolisticPole(1, 1) actorlow = Actor([test_polelow], None, None, None, 0.05, None, None, [], [0, 0, 0, 0]) actormiddle = Actor([test_polemiddle], None, None, None, 0.05, None, None, [], [0, 0, 0, 0]) actorhigh = Actor([test_polehigh], None, None, None, 0.05, None, None, [], [0, 0, 0, 0]) moveslow = test_polelow.actOnList(moves, actorlow) movesmiddle = test_polemiddle.actOnList(moves, actormiddle) moveshigh = test_polehigh.actOnList(moves, actorhigh) self.assertTrue(len(moveslow) != 6) self.assertTrue(len(moveshigh) >= 5)
def test_riskPole(self): move1 = Move({ "test1": 5, "test2": 10, "test3": 20 }, None, [], .5, None) move2 = Move({ "test1": 100, "test2": 200, "test3": 300 }, None, [], .5, None) move3 = Move({"test1": 1, "test2": 1, "test3": 1}, None, [], .5, None) move4 = Move({ "test1": -10, "test2": 10, "test3": -100 }, None, [], .5, None) move5 = Move({ "test1": 500, "test2": 1000, "test3": 10000 }, None, [], .5, None) move0 = Move({"test1": 0, "test2": 0, "test3": 0}, None, [], 0, None) moves = [move1, move2, move3, move4, move5, move0] test_polelow = RiskPole(-1, 1) test_polemiddle = RiskPole(0, 1) test_polehigh = RiskPole(.99, 1) actorlow = Actor([test_polelow], None, None, None, 0.05, None, None, [], None) actormiddle = Actor([test_polemiddle], None, None, None, 0.05, None, None, [], None) actorhigh = Actor([test_polehigh], None, None, None, 0.05, None, None, [], None) moveslow = test_polelow.actOnList(moves, actorlow) movesmiddle = test_polemiddle.actOnList(moves, actormiddle) moveshigh = test_polehigh.actOnList(moves, actorhigh) self.assertTrue(actorlow.error < 1) print("low error", actorlow.resourcesError) # print("high error", actorhigh.error) print("high error" + str(actorhigh.resourcesError)) print("middle error", actormiddle.resourcesError) # print(actormiddle.error) print("done")
def test_rationalityPole(self): move1 = Move({ "test1": 5, "test2": 10, "test3": 20 }, None, [], .5, None) move2 = Move({ "test1": 100, "test2": 200, "test3": 300 }, None, [], .5, None) move3 = Move({"test1": 1, "test2": 1, "test3": 1}, None, [], .5, None) move4 = Move({ "test1": -10, "test2": 10, "test3": -100 }, None, [], .5, None) move5 = Move({ "test1": 500, "test2": 1000, "test3": 10000 }, None, [], .5, None) move0 = Move({"test1": 0, "test2": 0, "test3": 0}, None, [], 0, None) moves = [move1, move2, move3, move4, move5, move0] test_polelow = RationalityPole(-1, 1) test_polemiddle = RationalityPole(-.5, 1) test_polehigh = RationalityPole(1, 1) actorlow = Actor([test_polelow], None, None, None, 0.05, None, None, [], None) actormiddle = Actor([test_polemiddle], None, None, None, 0.05, None, None, [], None) actorhigh = Actor([test_polehigh], None, None, None, 0.05, None, None, [], None) moveslow = test_polelow.actOnList(moves, actorlow) movesmiddle = test_polemiddle.actOnList(moves, actormiddle) moveshigh = test_polehigh.actOnList(moves, actorhigh) self.assertEqual(len(moveshigh), 6) self.assertEqual(len(moveslow), 0) self.assertTrue(len(movesmiddle) < 4)
def __init__(self, N): super().__init__(N) self.num_agents = N self.schedule = RandomActivation(self) ################### Create global resources#################################### rationality = RationalityPole(0, 1) risk = RiskPole(0, 1) emotion = EmotionalPole(0, 1) generosity = GenerosityPole(0, 1) particularHolistic = ParticularHolisticPole(1, 1) primacyRecency = PrimacyRecencyPole(0, 1) routineCreative = RoutineCreativePole(0, 1) data = utils.read_moves("../data/moves.csv") moves = [] for move in data: IO_string_set = set() IO_list = [utils.IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] IO_string = utils.list_to_string(IO_list) while IO_string in IO_string_set: IO_list = [utils.IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] moves.append(Move(move["code"], move["move_name"], move["move_type"], IO_list, move["ph"], [resource.strip() for resource in move["low_resources"].replace(",", " ").split()], [resource.strip() for resource in move["med_resources"].replace(",", " ").split()], [resource.strip() for resource in move["high_resources"].replace(",", " ").split()], move["infrastructure"], category='Build political infrastructure')) generate_resource_vocab(moves) # TODO # one hot for infrastructure as well s1 = [1000] * 52 s2 = [100] * 52 s3 = [-1000] * 52 curState = State({i: s1[i] for i in range(len(s1))}, {0: 0}) desState = State({i: s2[i] for i in range(len(s2))}, {0: 100}) criticalState = State({i: s3[i] for i in range(len(s3))}, {0: -1000}) io_values = {"A": 0, "B": 0, "C": 0, "D": 0, "E": 0} globalresource = Actor(unique_id=0,model=self, poles=[rationality, risk, emotion, generosity, particularHolistic, primacyRecency, routineCreative], currentState = curState, desiredState=desState, maxTime=2, error=0, history=[], criticalState=criticalState, allActors=[], ioValues=io_values, end_io_state=io_values) self.schedule.add(globalresource) ############################################################################# ############################# add an actor################################### rationality = RationalityPole(0, 1) risk = RiskPole(0, 1) emotion = EmotionalPole(0, 1) generosity = GenerosityPole(0, 1) particularHolistic = ParticularHolisticPole(1, 1) primacyRecency = PrimacyRecencyPole(0, 1) routineCreative = RoutineCreativePole(0, 1) data = utils.read_moves("../data/moves.csv") moves = [] for move in data: IO_string_set = set() IO_list = [utils.IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] IO_string = utils.list_to_string(IO_list) while IO_string in IO_string_set: IO_list = [utils.IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] moves.append(Move(move["code"], move["move_name"], move["move_type"], IO_list, move["ph"], [resource.strip() for resource in move["low_resources"].replace(",", " ").split()], [resource.strip() for resource in move["med_resources"].replace(",", " ").split()], [resource.strip() for resource in move["high_resources"].replace(",", " ").split()], move["infrastructure"], category='Build political infrastructure')) generate_resource_vocab(moves) # TODO # one hot for infrastructure as well s1 = [0] * 52 s2 = [100] * 52 s3 = [-1000] * 52 curState = State({i: s1[i] for i in range(len(s1))}, {0: 0}) desState = State({i: s2[i] for i in range(len(s2))}, {0: 100}) criticalState = State({i: s3[i] for i in range(len(s3))}, {0: -1000}) io_values = {"A": 0, "B": 0, "C": 0, "D": 0, "E": 0} actor = Actor(unique_id=1,model=self, poles=[rationality, risk, emotion, generosity, particularHolistic, primacyRecency, routineCreative], currentState = curState, desiredState=desState, maxTime=2, error=0, history=[], criticalState=criticalState, allActors=[], ioValues=io_values, end_io_state=io_values) self.schedule.add(actor) ############################################################################## ############################# add an actor################################### rationality = RationalityPole(0, 1) risk = RiskPole(0, 1) emotion = EmotionalPole(0, 1) generosity = GenerosityPole(0, 1) particularHolistic = ParticularHolisticPole(1, 1) primacyRecency = PrimacyRecencyPole(0, 1) routineCreative = RoutineCreativePole(0, 1) data = utils.read_moves("../data/moves.csv") moves = [] for move in data: IO_string_set = set() IO_list = [utils.IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] IO_string = utils.list_to_string(IO_list) while IO_string in IO_string_set: IO_list = [utils.IO_random_sampler(x) for x in [move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"]]] moves.append(Move(move["code"], move["move_name"], move["move_type"], IO_list, move["ph"], [resource.strip() for resource in move["low_resources"].replace(",", " ").split()], [resource.strip() for resource in move["med_resources"].replace(",", " ").split()], [resource.strip() for resource in move["high_resources"].replace(",", " ").split()], move["infrastructure"], category='Build political infrastructure')) generate_resource_vocab(moves) # TODO # one hot for infrastructure as well s1 = [10] * 52 s2 = [100] * 52 s3 = [-1000] * 52 curState = State({i: s1[i] for i in range(len(s1))}, {0: 0}) desState = State({i: s2[i] for i in range(len(s2))}, {0: 100}) criticalState = State({i: s3[i] for i in range(len(s3))}, {0: -1000}) io_values = {"A": 0, "B": 0, "C": 0, "D": 0, "E": 0} actor2 = Actor(unique_id=2,model=self, poles=[rationality, risk, emotion, generosity, particularHolistic, primacyRecency, routineCreative], currentState = curState, desiredState=desState, maxTime=2, error=0, history=[], criticalState=criticalState, allActors=[], ioValues=io_values, end_io_state=io_values) self.schedule.add(actor2)
def test_PrimacyRecencyPole(self): curstate1 = State({"f1": 100, "f2": 0}, {"i1": 0}) desState1 = State({'f1': 1000}, {'i1': 1000}) test_polelow = PrimacyRecencyPole(-1, .1) test_polemiddle = PrimacyRecencyPole(0, 1) test_polehigh = PrimacyRecencyPole(1, 1) move1 = Move({"f1": 101, "f2": 0}, {"i1": 1}, [], 1, None) move2 = Move({"f1": 102, "f2": 0}, {"i1": 1}, [], 1, None) move3 = Move({"f1": 110, "f2": 0}, {"i1": 1}, [], 1, None) move4 = Move({"f1": 106, "f2": 0}, {"i1": 1}, [], 1, None) move5 = Move({"f1": 101, "f2": 0}, {"i1": 0}, [], 1, None) move6 = Move({"f1": 102, "f2": 0}, {"i1": 0}, [], 1, None) move7 = Move({"f1": 110, "f2": 0}, {"i1": 0}, [], 1, None) move8 = Move({"f1": 106, "f2": 0}, {"i1": 0}, [], 1, None) move00 = Move({"f1": 0, "f2": 0}, {"i1": 0}, [], 1, None) event1 = Event(None, None, move1, 0) event2 = Event(None, None, move2, 0) event3 = Event(None, None, move3, 0) event4 = Event(None, None, move4, 0) event5 = Event(None, None, move5, 0) event6 = Event(None, None, move6, 0) event7 = Event(None, None, move7, 0) event8 = Event(None, None, move8, 0) actorlow = Actor([test_polelow], curstate1, None, None, .05, None, None, [], []) actormiddle = Actor([test_polemiddle], curstate1, None, None, .05, None, None, [], []) # high recency actorhigh = Actor([test_polehigh], curstate1, None, None, .05, None, None, [], []) actorlow.memory = [event1, event2, event3, event4] actorhigh.memory = [event1, event2, event3, event4] actormiddle.memory = [event1, event2, event3, event4] actorlow.history = [event5, event6, event7, event8] actormiddle.history = [event5, event6, event7, event8] actorhigh.history = [event5, event6, event7, event8] test_MST1 = MST(curstate1, desState1, [move1, move2, move3, move4, move5, move6, move7, move8, move00], 2) test_MST2 = MST(curstate1, desState1, [move1, move2, move3, move4, move5, move6, move7, move8, move00], 2) test_MST3 = MST(curstate1, desState1, [move1, move2, move3, move4, move5, move6, move7, move8, move00], 2) low_mst = test_polelow.actOnMST(test_MST1, actorlow) # contain only move 1,2,5,6,7,8,00 mid_mst = test_polemiddle.actOnMST(test_MST2, actormiddle) # contain 1,2,5,6,00 high_mst = test_polehigh.actOnMST(test_MST3, actorhigh) # contain 1,2,3,,4 ,5,6,00 self.assertTrue(low_mst.containsMove(move1)) self.assertTrue(low_mst.containsMove(move2)) self.assertTrue(low_mst.containsMove(move5)) self.assertTrue(low_mst.containsMove(move6)) self.assertTrue(low_mst.containsMove(move7)) self.assertTrue(low_mst.containsMove(move00)) self.assertFalse(low_mst.containsMove(move3)) self.assertFalse(low_mst.containsMove(move4)) self.assertTrue(low_mst.containsMove(move8)) self.assertTrue(mid_mst.containsMove(move1)) self.assertTrue(mid_mst.containsMove(move2)) self.assertTrue(mid_mst.containsMove(move5)) self.assertTrue(mid_mst.containsMove(move6)) self.assertTrue(mid_mst.containsMove(move00)) self.assertFalse(mid_mst.containsMove(move3)) self.assertFalse(mid_mst.containsMove(move4)) self.assertFalse(mid_mst.containsMove(move7)) self.assertFalse(mid_mst.containsMove(move8)) self.assertFalse(mid_mst.containsMove(move3)) self.assertTrue(high_mst.containsMove(move2)) self.assertTrue(high_mst.containsMove(move3)) self.assertTrue(high_mst.containsMove(move4)) self.assertTrue(high_mst.containsMove(move5)) self.assertTrue(high_mst.containsMove(move6)) self.assertTrue(high_mst.containsMove(move00)) self.assertTrue(not high_mst.containsMove(move7)) self.assertTrue(not high_mst.containsMove(move8)) self.assertTrue(high_mst.containsMove(move1))
def test_RoutineCreativePole(self): test_polelow = RoutineCreativePole(-.75, 1) test_polemiddle = RoutineCreativePole(0, 1) test_polehigh = RoutineCreativePole(1, 1) # high primacy actorlow = Actor([test_polelow], State({ "test1": 1, "test2": 1, "test3": 1, "test4": 1 }, None), None, None, .1, None, None, [], []) actormiddle = Actor([test_polemiddle], State( { "test1": 1, "test2": 1, "test3": 1, "test4": 1 }, None), None, None, .1, None, None, [], []) # high recency actorhigh = Actor([test_polehigh], State( { "test1": 1, "test2": 1, "test3": 1, "test4": 1 }, None), None, None, .1, None, None, [], []) event1 = Event( None, None, Move({ "test1": 1, "test2": 1, "test3": 1, "test4": 1 }, None, [], .5, None), 0) event2 = Event( None, None, Move({ "test1": 0, "test2": 0, "test3": 0, "test4": 0 }, None, [], .5, None), 0) # event3 = Event(None, None, Move({"test1":100, "test2": 100, "test3": 200, "test4": 300}, None, [], .5, None),0) # event4 = Event(None, None, Move({"test1":0, "test2": 0, "test3": 0, "test4": 1}, None, [], .5, None),0) # event5 = Event(None, None, Move({"test1":1, "test2": 1, "test3": 1, "test4": 2}, None, [], .5, None),0) # event6 = Event(None, None, Move({"test1":101, "test2": 100, "test3": 100, "test4": 100}, None, [], .5, None),0) # event7 = Event(None, None, Move({"test1":501, "test2": 500, "test3": 500, "test4": 500}, None, [], .5, None),0) # event8 = Event(None, None, Move({"test1":1, "test2": 1, "test3": 0, "test4": 0}, None, [], .5, None),0) moves = [ Move({ "test1": 1, "test2": 1, "test3": 1, "test4": 1 }, None, [], .5, None), Move({ "test1": 0, "test2": 0, "test3": 0, "test4": 0 }, None, [], .5, None), Move({ "test1": 1000, "test2": 1000, "test3": 1000, "test4": 1000 }, None, [], .5, None), Move({ "test1": .75, "test2": .75, "test3": .75, "test4": .75 }, None, [], .5, None), Move({ "test1": .89, "test2": .99, "test3": .99, "test4": 1 }, None, [], .5, None) ] successfulMoves = [ event1, event2 ] # ,event3, event4, event5, event6, event7, event8] actorlow.timeTicks = 8 actormiddle.timeTicks = 8 actorhigh.timeTicks = 8 actorlow.successfulMoves = successfulMoves actorhigh.successfulMoves = successfulMoves actormiddle.successfulMoves = successfulMoves moveslow = test_polelow.actOnList(moves, actorlow) movesmiddle = test_polemiddle.actOnList(moves, actormiddle) moveshigh = test_polehigh.actOnList(moves, actorhigh) print("PRINTING MOVES LOW MIDDLE HIGH") print(len(moveslow)) print(len(movesmiddle)) print(len(moveshigh))
def test_PrimacyRecencyPole(self): test_polelow = PrimacyRecencyPole(-1, 1) test_polemiddle = PrimacyRecencyPole(0, 1) test_polehigh = PrimacyRecencyPole(1, 1) # high primacy actorlow = Actor([test_polelow], State({ "test1": 1, "test2": 0, "test3": 0, "test4": 0 }, None), None, None, .05, None, None, [], []) actormiddle = Actor([test_polemiddle], State( { "test1": 1, "test2": 0, "test3": 0, "test4": 0 }, None), None, None, .05, None, None, [], []) # high recency actorhigh = Actor([test_polehigh], State( { "test1": 1, "test2": 0, "test3": 0, "test4": 0 }, None), None, None, .05, None, None, [], []) event1 = Event( None, None, Move({ "test1": 1, "test2": 1, "test3": 1, "test4": 1 }, None, [], .5, None), 0) event2 = Event( None, None, Move({ "test1": 1, "test2": 1, "test3": 1, "test4": 2 }, None, [], .5, None), 0) event3 = Event( None, None, Move({ "test1": .96, "test2": 0, "test3": 0, "test4": 0 }, None, [], .5, None), 0) event4 = Event( None, None, Move({ "test1": 0, "test2": 0, "test3": 0, "test4": 0 }, None, [], .5, None), 0) event5 = Event( None, None, Move({ "test1": 1, "test2": 1, "test3": 1, "test4": 2 }, None, [], .5, None), 0) event6 = Event( None, None, Move({ "test1": 101, "test2": 100, "test3": 100, "test4": 100 }, None, [], .5, None), 0) event7 = Event( None, None, Move({ "test1": 501, "test2": 500, "test3": 500, "test4": 500 }, None, [], .5, None), 0) event8 = Event( None, None, Move({ "test1": 1, "test2": 1, "test3": 0, "test4": 0 }, None, [], .5, None), 0) moves = [] history = [event1, event2, event3, event4] memory = [event5, event6, event7, event8] actorlow.history = [event1, event2, event3, event4] actorhigh.history = [event1, event2, event3, event4] actormiddle.history = [event1, event2, event3, event4] actorlow.memory = [event5, event6, event7, event8] actormiddle.memory = [event5, event6, event7, event8] actorhigh.memory = [event5, event6, event7, event8] print("MOVES LOW") moveslow = test_polelow.actOnList(moves, actorlow) print("MOVES MID:") movesmiddle = test_polemiddle.actOnList(moves, actormiddle) print("MOVES HIGH:") moveshigh = test_polehigh.actOnList(moves, actorhigh)
while IO_string in IO_string_set: IO_list = [ utils.IO_random_sampler(x) for x in [ move["warmth"], move["affinity"], move["legitimacy"], move["dominance"], move["competence"] ] ] moves.append( Move(move["code"], move["move_name"], move["move_type"], IO_list, move["ph"], [ resource.strip() for resource in move["low_resources"].replace(",", " ").split() ], [ resource.strip() for resource in move["med_resources"].replace(",", " ").split() ], [ resource.strip() for resource in move["high_resources"].replace(",", " ").split() ], move["infrastructure"], category='Build political infrastructure')) generate_resource_vocab(moves) # TODO # one hot for infrastructure as well s1 = [0] * 52 s2 = [100] * 52 s3 = [-1000] * 52
def testMSTbuild(self): curstate1 = State({ 'f1': 100, 'f2': 100, 'f3': 100 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }) desState1 = State({ 'f1': 100, 'f2': 100, 'f3': 100 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }) curState2 = State({ 'f1': 0, 'f2': 0, 'f3': 0 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }) desState2 = State({ 'f1': 0, 'f2': 0, 'f3': 0 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }) move1 = Move({ "f1": 5, "f2": 10, "f3": 20 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }, [], .5, None) move2 = Move({ "f1": 100, "f2": 200, "f3": 300 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }, [], .5, None) move0 = Move({ "f1": 0, "f2": 0, "f3": 0 }, { 'i1:': 0, 'i2': 0, 'i3': 0 }, [], 0, None) moves = [move1, move2, move0] test_mst1 = MST(curstate1, desState1, moves, 2) G = test_mst1.graph # nx.draw(test_mst1.graph) # plt.show() root = test_mst1.tree edges = G.edges() print(edges) edges = [G[node1][node2]['object'] for (node1, node2) in edges] self.assertTrue(move2 in edges)