Posted: 21 Oct 2019 11:59 EDT Last activity: 28 Oct 2019 15:44 EDT
Forward and backward chaining in declarative networks
There is such a mock question:
You have created a series of forms for a vacation booking process. Declarative expressions are used to calculate values such as the cost of the flight, hotel, car rental, and taxes. The last form includes a field that displays the total amount that will be charged on the user's credit card. How do you configure the calculations so that the total amount is calculated only when the user reaches the last form?
I know we should use backward chaining for the total amount. But for the other expressions like the cost of the flight, hotel etc. could you please explain according to what criteria should we determine whether it should be forward or backward chaining?
Forward chaining updates a target value whenever one of the inputs to the expression changes. If the network of calculations is extensive enough, forward chaining may impact performance. If the calculated value doesn't need to change that frequently, backward chaining limits the impact.
So, if you wanted to sum the cost of the items on an order in real-time, forward chaining would be an appropriate option. However, if the total cost also depends on the shipping charge, tax, gift wrapping charge, or other fees that are determined later in the check-out process, then there is no value to constantly recalculating the total cost until the user provides information that can be used to determine those other charges.
If changes are infrequent, it doesn't really matter, so you can use forward chaining.
If changes are frequent, and there is business value in staying current with the inputs, then use forward chaining.
If the network is extensive and there is limited (or no) value in staying current with the changes, then use backward chaining.