Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
    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()
Beispiel #4
0
    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))
Beispiel #5
0
    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))
Beispiel #6
0
    def getPossibleState(self, curState):
        resources = {}
        for i in curState.resources:
            resources[i] = curState.resources[i] - self.resources[i]

        infrastructure = {}
        # TODO turn this on once infrastructure is fixed
        '''
        for i in curState.infrastructure:
            infrastructure[i] = curState.infrastructure[i] - self.infrastructure[i]
            '''
        return State(resources, infrastructure)
Beispiel #7
0
    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)
Beispiel #8
0
    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))
Beispiel #9
0
             ], [
                 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([
    rationality, risk, emotion, generosity, particularHolistic, primacyRecency,
    routineCreative
],
              curState,
              desState,
              maxTime=2,
              error=0,
              history=[],
              criticalState=criticalState,
Beispiel #10
0
    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)
Beispiel #11
0
def post_index():
    #    def __init__(self, poles, currentState, desiredState, maxTime, error, history, criticalState, allActors, ioValues, end_io_state):
    poles_list = [pole for pole in request.form if pole.endswith("val")]
    poles = []
    for pole in poles_list:
        name = pole.replace(" ", "").replace("_val", "")
        MyClass = getattr(importlib.import_module("dm.Pole"), name + "Pole")
        val = float(request.form.get(pole)) / 100
        weight = float(request.form.get(pole.replace("val", "weight"))) / 100

        poles.append(MyClass(val, weight))

    with open("static/resource_vocab.txt", 'r') as file:
        resources = [line.rstrip('\n') for line in file]

    current_resources = {
        resource: 1
        for resource in request.form.get("cur_resources").replace(","
                                                                  "").split()
    }
    desired_resources = {
        resource: 1
        for resource in request.form.get("des_resources").replace(","
                                                                  "").split()
    }
    critical_resources = {
        resource: 1
        for resource in request.form.get("critical_resources").replace(
            ","
            "").split()
    }

    current_infra = {
        infra: 1
        for infra in request.form.get("cur_infra").replace(","
                                                           "").split()
    }
    desired_infra = {
        infra: 1
        for infra in request.form.get("des_infra").replace(","
                                                           "").split()
    }
    critical_infra = {
        infra: 1
        for infra in request.form.get("critical_infra").replace(","
                                                                "").split()
    }

    current_state = State(current_resources, current_infra)
    desired_state = State(desired_resources, desired_infra)
    critical_state = State(critical_resources, critical_infra)
    max_time = int(request.form.get("max_time"))

    error = int(request.form.get("error"))

    # TODO history is blank for now

    # TODO allActors is blank for now

    io_list = [io for io in request.form if io.endswith("end")]
    io_values = {}
    desired_io_values = {}
    for io in io_list:
        val = float(request.form.get(io)) / 100
        io_values[io.replace("_value_end", "")] = val

        desired_val = float(request.form.get(io.replace("_end", "")))
        desired_io_values[io.replace("_value_end", "")] = desired_val

    actor = Actor(poles, current_state, desired_state, max_time, error, [],
                  critical_state, [], io_values, desired_io_values)
Beispiel #12
0
    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))
Beispiel #13
0
    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)