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
Copy file name to clipboardexpand all lines: DecisionNetwork/README.md
+11-102
Original file line number
Diff line number
Diff line change
@@ -107,135 +107,44 @@ utility | D
107
107
-10 -
108
108
```
109
109
110
-
111
-
112
110
#### Output:
113
111
114
-
The result should be printed to a file called output.txt. Given the sample input above, the output content should be as follows:
112
+
The result should be printed to console (or a file called output.txt by modify the global variable `OUTPUT_FILE = output.txt #COULD BE 'OUTPUT_FILE = None' for console or file name (e.g. 'OUTPUT_FILE = 'output.txt') for file.'`). Given the sample input above, the output content should be as follows:
115
113
116
114
(output01 for input sample01.txt)
115
+
```text
117
116
0.25
118
117
0.43
118
+
```
119
119
120
120
(output02 for input sample02.txt)
121
+
```text
121
122
0.76
122
123
59
123
124
37
124
125
+ 59
125
126
- 44
127
+
```
126
128
127
-
For each query in the input file, your program should generate a corresponding result (one result per line) as the output. The result may have three forms:
129
+
For each query in the input file, the program should generate a corresponding result (one result per line) as the output. The result may have three forms:
128
130
129
-
● “P” query: A decimal value between 0 and 1, rounded to two decimals (for example, we want 0.395 to be 0.40):
131
+
*“P” query: A decimal value between 0 and 1, rounded to two decimals (for example, we want 0.395 to be 0.40):
130
132
e.g. 0.40
131
133
1) “EU” query: An integer value:
132
134
e.g. 50
133
135
2) “MEU” query: One sign(“+” or “-” ) for each decision node, followed by an integer value representing the maximum expected utility, all separated with a single whitespace:
134
136
e.g. + 50
135
137
136
-
● When there are multiple decisions, the order of decisions should be the same as in the query.
138
+
*When there are multiple decisions, the order of decisions should be the same as in the query.
137
139
e.g. Input: MEU(I, L)
138
-
● Output: + - 50
139
-
● The test cases will be designed so that there will always be one unique solution with MEU.
140
-
● For EU and MEU queries, all calculations should be done in decimal number accuracy, but the output expected utility value should be rounded to the nearest integer (for example, we want 3.5 to be rounded to 4).
141
-
● Don’t print additional whitespace after the value, or extra line break in the end.
142
-
143
-
## Program structure:
144
-
145
-
It defines classes_and_methods below:
146
-
```python
147
-
Propositional_Logic: A propositional logic operation classinCNFwithDPLLand WalkSAT algorithm.
148
-
149
-
Operators include: AND, OR, NOT can be defined inglobal variable
150
-
151
-
The CNF sentence '(A OR B) AND (NOT C)' can be represented as below data structure:
1. every setinlist should be associated withAND, and
164
-
165
-
2. every literal inset should be associated withOR
166
-
167
-
168
-
169
-
Major Functions:
170
-
171
-
1. is_satisfiable(KB, algorithm='DPLL'): This implementation include DPLLandPL_Resolution algorithm to verify the satisfiability of the sentence. You can switch the global variable, ALGORITHM='DPLL'# or 'PL_Resolution', to change it.
172
-
173
-
You can choose either 'DPLL'or'PL_Resolution' to switch the algorithm.
174
-
175
-
2. DPLL: This algorithm is used for checking satisfiability of a CNF sentence in propositional logic.
176
-
177
-
The method will also store the satisfiable model into the 'model' variable inclass.
140
+
* Output: + - 50
141
+
* The test cases will be designed so that there will always be one unique solution with MEU.
142
+
* For EU and MEU queries, all calculations should be done in decimal number accuracy, but the output expected utility value should be rounded to the nearest integer (for example, we want 3.5 to be rounded to 4).
178
143
179
-
3. WalkSAT: Inference methods which are implemented to provide one of models inCNF sentence of propositional logic.
180
-
181
-
4. PL_Resolution: A structure only class. Need to be completed in the future.
182
-
183
-
The class will check a propositional logic sentence is satisfy ornot.
184
-
```
185
-
186
-
```python
187
-
Prop_KB: A knowledge base can be Ask, Tell in propositional logic by CNF.
188
-
189
-
Major Functions:
190
-
191
-
tell(clauses): inputCNF clauses.
192
-
193
-
ask(CNF_query) will not implement in this case.
194
-
195
-
get_sentence(): will present the KBin a CNF sentence.
196
-
```
197
-
198
-
```python
199
-
Wedding: A wedding arrangement class to solve a the question.
200
-
201
-
1. According to given rule to generate CNF sentence.
202
-
203
-
2. Input the sentence to KB.
204
-
205
-
3. Verifing the KBis satisfiable ornot.
206
-
207
-
4. If the KBis satisfiable, then get a model/solution by WalkSAT.
208
-
209
-
5. Printing the results.
210
-
```
211
-
212
-
```python
213
-
defgetWeddingRules(self):
214
-
# Every clause is 'OR' connect with each other clause, every sentence is 'AND' connect with each other sentence.
215
-
# atomic = [guest, table]
216
-
# CNF: (AvB) ^ (~C) = [{'A','B'}, {'~C'}]
217
-
#The outer list is a conjunction of clauses. Each inner list is a clause, i.e. a disjunction of literals.
218
-
```
219
-
220
-
## Global Variables:
221
-
* You can switch the global variable, `ALGORITHM = 'DPLL' # or 'PL_Resolution'`, to change it.
222
-
* Logic operation define as below:
223
-
224
-
```python
225
-
AND='^'
226
-
OR='v'
227
-
NOT='~'
228
-
```
229
-
* The implement add one more constraint. All tasks have to be done in 2 minutes. Below parameters can help you to define the resource (time/seconds) for each process. According to the default setting below, if the DPLL cannot find a confirmation in 70 seconds, the program will try WalkSAt to get a solution in 49 seconds.
230
-
```
231
-
RESOURCE_DPLL = 70
232
-
RESOURCE_WALKSAT = 49
233
-
```
234
144
235
145
## Reference:
236
146
* Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach (AIMA). Prentice Hall, 3rd Edition. [http://aima.cs.berkeley.edu/](http://aima.cs.berkeley.edu/)
* MIT Open Course Ware. [Resolution Theorem Proving: Propositional Logic](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-825-techniques-in-artificial-intelligence-sma-5504-fall-2002/lecture-notes/Lecture7FinalPart1.pdf)
0 commit comments