Skip to content

Commit 14f1ffd

Browse files
authored
Update README.md
1 parent d482a87 commit 14f1ffd

File tree

1 file changed

+11
-102
lines changed

1 file changed

+11
-102
lines changed

DecisionNetwork/README.md

+11-102
Original file line numberDiff line numberDiff line change
@@ -107,135 +107,44 @@ utility | D
107107
-10 -
108108
```
109109

110-
111-
112110
#### Output:
113111

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:
115113

116114
(output01 for input sample01.txt)
115+
```text
117116
0.25
118117
0.43
118+
```
119119

120120
(output02 for input sample02.txt)
121+
```text
121122
0.76
122123
59
123124
37
124125
+ 59
125126
- 44
127+
```
126128

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:
128130

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):
130132
e.g. 0.40
131133
1) “EU” query: An integer value:
132134
e.g. 50
133135
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:
134136
e.g. + 50
135137

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.
137139
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 class in CNF with DPLL and WalkSAT algorithm.
148-
149-
Operators include: AND, OR, NOT can be defined in global variable
150-
151-
The CNF sentence '(A OR B) AND (NOT C)' can be represented as below data structure:
152-
153-
sentence[clause1{Literal1, Literal2}, clause2{~Literal3}]
154-
155-
1. sentence is a list to contain sets.
156-
157-
2. Clause is a set with Literals.
158-
159-
3. Literal presents by string.
160-
161-
The sentence should be in CNF, which equal to
162-
163-
1. every set in list should be associated with AND, and
164-
165-
2. every literal in set should be associated with OR
166-
167-
168-
169-
Major Functions:
170-
171-
1. is_satisfiable(KB, algorithm = 'DPLL'): This implementation include DPLL and PL_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 in class.
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).
178143

179-
3. WalkSAT: Inference methods which are implemented to provide one of models in CNF 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 or not.
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): input CNF clauses.
192-
193-
ask(CNF_query) will not implement in this case.
194-
195-
get_sentence(): will present the KB in 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 KB is satisfiable or not.
206-
207-
4. If the KB is satisfiable, then get a model/solution by WalkSAT.
208-
209-
5. Printing the results.
210-
```
211-
212-
```python
213-
def getWeddingRules(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-
```
234144

235145
## Reference:
236146
* 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/)
237147
* AIMA reference code, aimacode/aima-python : https://github.com/aimacode/aima-python
238-
* 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)
239148

240149
## Notice:
241150

0 commit comments

Comments
 (0)