Chapter 6 Recursive Techniques i n Property Information Retrieval a n d Calculation for Computer-Aided Formulation R. Albrecht-Mallinger and E. H. Givens
Downloaded by RUTGERS UNIV on December 28, 2017 | http://pubs.acs.org Publication Date: August 29, 1989 | doi: 10.1021/bk-1989-0404.ch006
Automotive Research Laboratory, The Sherwin-Williams Company, Chicago, IL 60628 Software to predict the properties of formulated products is made more powerful by a recursive procedure which can use formulas stored in files as raw materials. Particular care must be taken with program flow control and data structures for the recursion to be effective. This paper illustrates these issues using an example derived from a working formulation system for coatings development. INTRODUCTION: FORMULATED PRODUCTS USED AS RAW MATERIALS Polymer and coating chemists use computer models to predict the properties of formulated products from the characteristics of the raw materials and processing conditions (I, 2). Usually, the chemist supplies the identification and amounts of the materials. The software retrieves raw material property data needed for the modelling calculations from a raw material database. However, the chemist often works with groups of materials that are used as a unit. For instance, intermediates used in multiple products or premixes are themselves formulated products, not raw materials in the sense of being purchased or basic chemical species. Also, some ingredients are often used in constant ratio. In these cases, experimentation and calculation are simplified if the chemist can refer to these sets of materials as a unit, even though the unit may not be part of the raw material database. A recursive modelling procedure will let the chemist use formulated products as a raw materials. In this paper, we illustrate this use of recursion, and provide a working example that highlights some of the complexities encountered when using this technique. The key is being able to calculate and return the same type of data for a formula as is normally retrieved from a raw material database. A simple example is material cost: knowing the cost and concentration of each raw material in a formula, the material cost of the formula is easily calculated. A slightly more complex example is calculating specific gravity and solids from the raw material properties and processing conditions of a reacted product. frEgVRgiQN Recursion, when used in the context of computer programs, refers to a procedure that calls itself as a subprocedure. The classic examples cited in programming texts (3, 4) are computation of the factorial function and 0097-6156/89/0404-0054$06.00/0 © 1989 American Chemical Society
Provder; Computer Applications in Applied Polymer Science II ACS Symposium Series; American Chemical Society: Washington, DC, 1989.
Downloaded by RUTGERS UNIV on December 28, 2017 | http://pubs.acs.org Publication Date: August 29, 1989 | doi: 10.1021/bk-1989-0404.ch006
6. ALBRECHT-MALLINGER & GIVENS
Information Retrieval and Calculation
Fibonacci numbers, where the number sought is the nth number in a series defined in terms of relationships to the n-1, n-2, etc. members of the series. All recursive procedures must have a terminating condition, so that they do not call themselves endlessly. In our case, we define a formula as consisting of raw materials and/or other formulas. We develop a modelling procedure we call to determine formula characteristics from raw material properties, and give it the recursive property of being able to call itself when it encounters a formula used as a raw material. The procedures terminate when all formulas are resolved into basic raw materials. This terminating condition cannot be met if any formula contains a reference to itself, either directly or indirectly, through another formula. Figure 1 shows a flow chart for part of a recursive modelling procedure, illustrated in this paper, which accepts as input a formula consisting of constituent raw material codes or formula names, and quantities. The procedure retrieves property data for each raw material in order to perform the required calculations. When the procedure encounters a constituent that is a formulated product, it calls itself using that product as input. The output of the procedure consists of the calculated properties of the formula, including those properties of the formula that would be retrieved from data files for non-formulated or purchased raw materials. By returning this latter set of properties, the procedure can treat formulas as raw materials. Recursion is not necessary in a formula modelling system if the only material inputs have the necessary characteristics available in a raw material database. The flow chart in Figure 2 shows how the retrieval process occurs in this case. Compare this with the flow chart in Figure 1. PROGRAMMING ISSUES Recursive procedures demand special attention to flow control and data structures. For instance, the flow control within the procedure must correctly handle an error, say missing file information or inconsistent data, that is discovered several iterations deep. Should the procedure break and return to the previous level only? Should it force return to the level of the original invocation of the procedure? Should it allow an interactive user a choice of supplying missing data, and if so, on any level of iteration? If files are opened within the procedures, should they be closed when a recursive call is needed, or are new channel numbers to be requested, using up system resources? These and other issues about flow control become critical as real-world features to enhance ease of use are added to a system, features we do not illustrate in our example. We will instead focus on complications of the data structure that are evident even in our simple procedure. In a non-recursive modelling program, one that permits only materials for which raw material type data is available, the data structure and naming of variables is straightforward. For instance, consider this table summarizing types of data for a modelling procedure that calculates the pigment-to-binder ratio (PBR) of a coating. Source of formula and raw material data for a non-recursive modelling procedure Formula characteristics Retrieved from database Calculated in program
No. Yes. (eg. pigment-tobinder ratio)
Raw material characteristics Yes. (eg. solids, cost) No.
Provder; Computer Applications in Applied Polymer Science II ACS Symposium Series; American Chemical Society: Washington, DC, 1989.
55
56
COMPUTER APPLICATIONS IN APPLIED POLYMER SCIENCE II
Downloaded by RUTGERS UNIV on December 28, 2017 | http://pubs.acs.org Publication Date: August 29, 1989 | doi: 10.1021/bk-1989-0404.ch006
GET C0DE(1..N), QUANTITY!1..N), N>=1 FOR FORMULA
±
,
RETRIEVE RAW MATERIAL DATA FOR CODE(ROW) FROM DATABASE
±
i
1 CALL THIS PROCEDURE WITH I FORMULA = CODE(ROW). RETURN j DATA NEEDED FOR CALCULATIONS
!~ROW = ROW + 1
I
yes CACULCATE FORMULA PROPERTIES FROM RAW MATERIAL DATA. ALSO, CALCULATE DATA NEEDED TO TREAT FORMULA AS RAW MATERIAL. Figure 1: Flow chart of recursive procedure, accepting both raw material and formulas as inputs.
Provder; Computer Applications in Applied Polymer Science II ACS Symposium Series; American Chemical Society: Washington, DC, 1989.
Information Retrieval and Calculation
Downloaded by RUTGERS UNIV on December 28, 2017 | http://pubs.acs.org Publication Date: August 29, 1989 | doi: 10.1021/bk-1989-0404.ch006
ALBRECHT-MALLINGER & GIVENS
I GET C0DE(1..N), QUANTITY(1..N), N>=li
I SET ROW = 1 i