Question
Forward and backward chaining in declarative networks
Hi:
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?
Thanks a lot!
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.
Basically: