Question
Implement the Forward Chaining Algorithm Create a C++ program that performs the forward chaining algorithm. point 2 = cannot add any headers Requirements: You must
Implement the Forward Chaining Algorithm
Create a C++ program that performs the forward chaining algorithm.
point 2 = cannot add any headers Requirements:
You must use the C++ programming language.
You can only use C++ code that you have learnt in SEHH2042 Computer Programming.
For example, you are NOT allowed to use other classes or libraries that were not taught in SEHH2042. The only exception to this is given below, under the heading "How to implement Step 7 above.
Your program should either work on Visual Studio, or an online C++ compiler (e.g. www.programiz.com).
The program should start with the following:
O A knowledge base, which consists of:
Sentences with one implication and one single literal (one symbol) in the conclusion, with a conjunction of one or more literals in the premise
e.g. AB=L Single literals, consisting of only one symbol
e.g. A A single proposition The program should output a result: whether the proposition can be proven (using the knowledge base) or not. . .
Recommended Steps
I strongly recommend that you follow these steps in this order:
1. Do NOT start writing any code until you first watch and understand the end of lecture 5 tutorial 6, and end of tutorial 7, which explains the summary of the code on lecture 4-5, slide 64. This shows exactly how this algorithm is used with real data.
2. In your entire C++ program, I strongly recommend that you always use the string class (remember to Hinclude ) and never use c-string (i.e. char[]). Page 1 of 4
3. Initially, write the code so that there is no user input (i.e. do NOT use cin initially). Just write the code where you always create the same knowledge base and single proposition, shown in lecture 4-5, slide 54.
4. This initial knowledge base is described in lecture 4-5, slide 63, but as explained in tutorial 6, you will need a lot more than 3 data structures, because in CH, an array cannot have more than one data type.
5. Then, write the code to represent the forward chaining algorithm (lecture 4-5, slide 64).
6. Then, test your code to make sure it works, You can try making small changes to your knowledge base, to see that the algorithm still works in those situations.
7. Then, add more code so that the user can also create their own knowledge base and proposition (using cin). This part requires a lot of work and is quite difficult, so it should be done last.
8. Test your code in a variety of situations.
Help to implement Step 7 above (reading user input)
You may use the following example to help you:
#include
#include
#include
#include
using namespace std;
c Marking Scheme
Data Structures (specific case)
o The data structures representing the knowledge base and proposition for a single, specific case (lecture 4-5, slide 54) are correctly implemented in code (without using user input, or cin).
o This is step 3 in the Recommended Steps.
. Forward Chaining Algorithm
o The forward chaining algorithm is correctly implemented (lecture 4-5 slide 64).
This is step 5 in the Recommended Steps.
Data Structures (general case)
The data structures representing the knowledge base and proposition for a general case (which the user can create using user input, or cin) are correctly implemented.
o This is step 7 in the Recommended Steps.
Warning: This part requires a lot more work than the previous parts.
. User friendliness
o Program is intuitive to use
o Results (output) are clearly and nicely presented to the user
Comments and good coding style
o The program code is generally easy to understand quickly
o Follow the same coding conventions and style as taught in SEHH2042, e.g.:
Comments (should be placed above code, NOT on the right of code, with blank lines above comments)
Indentation Variable naming conventions, etc.
o Code that is unnecessary is removed o Code repetition is avoided
o Large methods are broken down into smaller methods
Forward chaining algorithm
(a) (b) Forward chaining algorithm
(b) The algorithm starts with data:
(c) - count a table, where count[c) is initially the + number of symbols in clause c's premise
(d) - inferred a table, where inferred[s) is initially ] false for all symbol -queue
(e) - a queue of symbols, initially symbols known to be true in KB (? A
You may use the following example to help you:
#include #include #include #include using namespace std;
int main() { //Read user choices menuSpecificGenerak();
//Print initial state of data structures printAllVariables();
//Use algorithm and print result bool proven = forwardChainingAlgorithm(); if (proven) cout < targerliteral="">< "="" is="" true="" (can="" be="" proven)."=""><> else cout < targetliteral="">< "="" is="" not="" true="" (cannot="" be="" proven)."=""><>
// End program return 0;
}
int main0() { // Prompt user for sentence. // Always use string, never use char[] string input; cout < "enter="" a="" sentence:=""> getline(cin, input); // Prepare to break up string into parts stringstream ss(input); // This will be each word (part separated by a space) string token; // Keep breaking up string until we reach end of line while (getline(ss, token, ' ')) { // Print current token cout < token=""><> }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started