Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng-Lin-Li authored Oct 8, 2017
1 parent d482a87 commit 14f1ffd
Showing 1 changed file with 11 additions and 102 deletions.
113 changes: 11 additions & 102 deletions DecisionNetwork/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,135 +107,44 @@ utility | D
-10 -
```



#### Output:

The result should be printed to a file called output.txt. Given the sample input above, the output content should be as follows:
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:

(output01 for input sample01.txt)
```text
0.25
0.43
```

(output02 for input sample02.txt)
```text
0.76
59
37
+ 59
- 44
```

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

“P” query: A decimal value between 0 and 1, rounded to two decimals (for example, we want 0.395 to be 0.40):
* “P” query: A decimal value between 0 and 1, rounded to two decimals (for example, we want 0.395 to be 0.40):
e.g. 0.40
1) “EU” query: An integer value:
e.g. 50
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:
e.g. + 50

When there are multiple decisions, the order of decisions should be the same as in the query.
* When there are multiple decisions, the order of decisions should be the same as in the query.
e.g. Input: MEU(I, L)
● Output: + - 50
● The test cases will be designed so that there will always be one unique solution with MEU.
● 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).
● Don’t print additional whitespace after the value, or extra line break in the end.

## Program structure:

It defines classes_and_methods below:
```python
Propositional_Logic: A propositional logic operation class in CNF with DPLL and WalkSAT algorithm.

Operators include: AND, OR, NOT can be defined in global variable

The CNF sentence '(A OR B) AND (NOT C)' can be represented as below data structure:

sentence[clause1{Literal1, Literal2}, clause2{~Literal3}]

1. sentence is a list to contain sets.

2. Clause is a set with Literals.

3. Literal presents by string.

The sentence should be in CNF, which equal to

1. every set in list should be associated with AND, and

2. every literal in set should be associated with OR



Major Functions:

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.

You can choose either 'DPLL' or 'PL_Resolution' to switch the algorithm.

2. DPLL: This algorithm is used for checking satisfiability of a CNF sentence in propositional logic.

The method will also store the satisfiable model into the 'model' variable in class.
* Output: + - 50
* The test cases will be designed so that there will always be one unique solution with MEU.
* 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).

3. WalkSAT: Inference methods which are implemented to provide one of models in CNF sentence of propositional logic.

4. PL_Resolution: A structure only class. Need to be completed in the future.

The class will check a propositional logic sentence is satisfy or not.
```

```python
Prop_KB: A knowledge base can be Ask, Tell in propositional logic by CNF.

Major Functions:

tell(clauses): input CNF clauses.

ask(CNF_query) will not implement in this case.

get_sentence(): will present the KB in a CNF sentence.
```

```python
Wedding: A wedding arrangement class to solve a the question.

1. According to given rule to generate CNF sentence.

2. Input the sentence to KB.

3. Verifing the KB is satisfiable or not.

4. If the KB is satisfiable, then get a model/solution by WalkSAT.

5. Printing the results.
```

```python
def getWeddingRules(self):
# Every clause is 'OR' connect with each other clause, every sentence is 'AND' connect with each other sentence.
# atomic = [guest, table]
# CNF: (AvB) ^ (~C) = [{'A','B'}, {'~C'}]
#The outer list is a conjunction of clauses. Each inner list is a clause, i.e. a disjunction of literals.
```

## Global Variables:
* You can switch the global variable, `ALGORITHM = 'DPLL' # or 'PL_Resolution'`, to change it.
* Logic operation define as below:

```python
AND = '^'
OR = 'v'
NOT = '~'
```
* 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.
```
RESOURCE_DPLL = 70
RESOURCE_WALKSAT = 49
```

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

## Notice:

Expand Down

0 comments on commit 14f1ffd

Please sign in to comment.