You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Framework for modelling Kripke structures and solving modal logic formulas [](https://travis-ci.org/erohkohl/ai-modal-logic)[](https://codecov.io/gh/erohkohl/ai-modal-logic)
5
4
6
-
This framework provides a tool for modelling Kripke structures, modal and multi modal
7
-
logic formulas in **Python 3**. The aim of this framework is to describe the knowledge base of a multi agent system and its model, after one agent made an announcement. This knowledge base is mapped by a Kripke structure and one agents announcement is wrapped in a multi modal logic formula.
5
+
This framework provides a tool for modelling Kripke structuresand solving modal
6
+
logic formulas in **Python 3.6**. The aim of this framework is to describe the knowledge base of a multi agent system and its model, after one agent made an announcement. This knowledge base is mapped by a Kripke structure and one agents announcement is wrapped in a multi modal logic formula.
8
7
9
8
#### Modelling Kripke structure
10
9
A Kripke Frame describes a simple directed graph and its extension, Kripke structure,
@@ -15,7 +14,7 @@ assigns to each node a subset of propositional variables. In Kripke's semantic a
15
14
The following code snipped shows, how you can build the above Kripke structure with this framework. The Python syntax allows to model the transition relation of a Kripke frame very similar to its mathematical description. To model a valid Kripke frame, you have to ensure, that each node name of the transition relation appears in the list of worlds.
I decided to model the set of propositional variables as dict, therefore it is not necessary to explicit assign false to a variable. Moreover World('2', {'p': False}) and World('2', {}) are equivalent.
28
+
I decided to model the set of propositional variables as dict, therefore it is not necessary to explicit assign false to a variable. Moreover ```World('2', {'p': False})``` and ```World('2', {})``` are equivalent.
30
29
31
30
#### Describe modal logic formula and check its semantic over one world
32
31
Further more this framework allows you to check wether a node of your Kripke structure forces a given modal logic formula. Therefore you can map a formula with this framework as following code snipped shows. To calculate the semantic of a modal logic formula over one world just call *semantic()*, pass in the Kripke structure and the name of the world, you want to check.
33
32
34
-
<imgsrc="./doc/formula_example.png"width="250">
33
+
<imgsrc="./doc/formula_example.png"width="265">
35
34
36
35
```python
37
-
fromsrc.formula import*
36
+
frommlsolver.formula import*
38
37
39
38
formula = Implies(
40
39
Diamond(Atom('p')),
@@ -44,9 +43,92 @@ formula = Implies(
44
43
)
45
44
)
46
45
47
-
assertTrue==formula.semantic(ks, '1')
46
+
assert formula.semantic(ks, '1')isTrue
48
47
```
49
48
49
+
#### Solve modal logic formula with tableau calculus
50
+
A common challenge in artificial intelligence is, to determine a valid Kripke
51
+
structure to a given modal logic formula. Therefore the modal logic tableau
52
+
calculus gives us a tool, that constructs a Kripke structure starting from
53
+
one world. If the formula is satisfiable, it is true in this world. Imagine we
54
+
are searching for a valid Kripke structure, that satisfies the below formula
55
+
in the world *s*. The only thing to do, is to build this formula, like we already
56
+
saw in the snippet above, pass it to an instance of ProofTree and call the *derive()*
57
+
method. To check, whether the resolved Kripke structure really satisfies the formula
58
+
in world s, you can again make use of Formula's semantic() function.
The output shows, that the tableau calculus determines two possible Kripke
106
+
structures, because both paths are not closed. Thus the second satisfiable Kripke
107
+
structure would be ```(W = {(s,{'r': True}), (t,{'q': True})}, R = set(('s', 't')))```.
108
+
One path is closed, if there is a conflict in one worlds partial assignment. The bottom
109
+
symbol ```-|``` at the end of a leaf indicates a closed path (see snippet below).
110
+
111
+
```bash
112
+
s:((p or q) and not (p -> q))
113
+
|
114
+
|_ s:(p or q)
115
+
|
116
+
|_ s:not (p -> q)
117
+
|
118
+
|_ s:p
119
+
|
120
+
|_ s:p
121
+
|
122
+
|_ s: not q
123
+
|
124
+
|_ s:q
125
+
|
126
+
|_ s:p
127
+
|
128
+
|_ s: not q -|# this path is closed
129
+
```
130
+
131
+
50
132
#### Modelchecking
51
133
Moreover this framework allows to process new knowledge in addition to the current knowledge base, thus it applies a modal logic formula to a Kripke structure (knowledge base) and returns a model. This model is a valid Kripke structure, in terms all of its worlds forces the formula. Therefore the function*solve()* removes the minimum subset of worlds, that prevent the Kripke structure to force the formula.
52
134
@@ -55,10 +137,10 @@ model = ks.solve(formula)
55
137
```
56
138
57
139
#### Modelling multi agent systems
58
-
Further this framework extends the classical modal logic by the semantics of Box_a and Diamond_a operators for describing multi agent systems. You can find their implementation in the Pyhton file [src.fromula](https://github.com/erohkohl/ai-modal-logic/blob/master/src/formula.py). To use this operators it is necessary to build a Kripke structure with additional transition relations for each agent. To illustrate the usage of the framework's multi modal logic implementation, I implemented the *three wise men puzzle*.
140
+
Further this framework extends the classical modal logic by the semantics of Box_a and Diamond_a operators fordescribing multi agent systems. You can find their implementationin the Pyhton file [mlsolver.formula](https://github.com/erohkohl/mlsolver/blob/master/src/formula.py). To use this operators it is necessary to build a Kripke structure with additional transition relations for each agent. To illustrate the usage of the framework's multi modal logic implementation, I implemented the *three wise men puzzle*.
59
141
60
142
##### Example: Three wise men with hat
61
-
The data model of this example is located in [src.model](https://github.com/erohkohl/ai-modal-logic/blob/master/src/model.py) and the Pyhton file [test_model.py](https://github.com/erohkohl/ai-modal-logic/blob/master/test/test_model.py) proves its results.
143
+
The data model of this example is located in [mlsolver.model](https://github.com/erohkohl/mlsolver/blob/master/src/model.py) and the Pyhton file [test_model.py](https://github.com/erohkohl/mlsolver/blob/master/test/test_model.py) proves its results.
62
144
63
145
This puzzle is about three wise men, all of them wear either a red or a white hat. All in all there are two white and three red hats. Each wise men is only able to see the hats of his two neighbors and has to guess the color of his own hat. You can see the Kripke structure, that describes this knowledge base, in the picture below. For example the world name *RWW* denotes, that in this scenario the first wise man wears a red hat, the second and third wise man a white hat. The transition relation is defined by equivalence of two worlds for one agent. For example World *RWW* and *RRW* are equivalent for agent 2, because he can't distinguish these two possible scenarios.
64
146
@@ -82,9 +164,9 @@ model = ks.solve(And(f, g))
82
164
83
165
#### Test-driven development
84
166
85
-
While developing this framework I made use of the test-driven approach. Thus this repository contains 56 py.test case to ensure, that the framework works as expected, andfor documentation purposes. Before you are able to run all tests, make sure you have installed the setup.py, which only contains py.test as dependency, and you use **Python 3**.
167
+
While developing this framework I made use of the test-driven approach. Thus this repository contains **106 py.test cases** to ensure, that the framework works as expected, and for documentation purposes. Before you are able to run all tests, make sure you have installed the setup.py, which only contains py.test as dependency, and you use **Python 3.6**.
0 commit comments