A Object-Oriented Implementation of a Chemical Waste Consolidation Expert System
Return to front page 1. Background and Rationale 2. Interface Design
3. System Design
4. Evaluation and Results 5. Future Work 6. Conclusions Bibliography and References Appendix A. Example Drum Report Appendix B. Chemical Compatibility Testing Data |
3.3.The Chemical Library: Class ChemBook
The lowest level class that is absolutely essential to the success of the software is the chemical library, which is encapsulated in the ChemBook class. The ChemData structure for the ChemBook class is shown below. struct ChemData { ChemData* next; // POINTER TO NEXT CHEMICAL STRUCT int chemicalID; // REFERENCE NUMBER String60 chemName; // CHEMICAL NAME int casNum1, casNum2, casNum3; // CAS ID NUMBER int wasteType; // CHEMICAL WASTETYPE int wasteHcode; // H-CODE WASTE TYPE DESCRIPTOR // NFPA RATINGS int flammNFPA; // FLAMMABILITY NFPA RATING 0-4 int healthNFPA; // HEALTH NFPA RATING 0-4 int reactNFPA; // REACTIVITY NFPA RATING 0-4 int contactNFPA; // CONTACT NFPA RATING 0-4 // PHYSICAL DATA ON THE CHEMICAL float meltPt; // MELTING POINT IN CELSIUS DEGREES float boilPt; // BOILING POINT IN CELSIUS DEGREES float moleWt; // FORMULA WEIGHT OF THE COMPOUND float density; // DENSITY float flashPt; // FLASH POINT OF CHEMICAL float solH2O; // SOLUBILITY G PER LITER OF WATER // THERMODYNAMIC DATA float heatDilution; // HEAT OF DILUTION KJ/G-Mol }; The arrays for chemical type and incompatibles are separate linked lists private to the ChemBook class. This became obvious when it was realized that the average number of incompatibles was four, but some chemicals, such as iron, have more than ten. Some chemicals can have a large number of chemical type descriptors. Designing for the worst case would demand static arrays of huge proportions, and sorting and other manipulations become logistically demanding. For this and other reasons, the second prototype moved to complete dynamic memory allocation for the libraries. For ease of programming, a limited number of local subroutines that manipulate the libraries use static arrays for the task, and memory is deallocated at the end of these routines. The chemical type linked list is comprised of nodes containing a next pointer, chemical name and the type descriptor such as “Organic” or “Oxidizer”. The incompatibles linked list nodes have an additional integer value to describe the level of incompatibility on a zero to ten scale, with zero representing total compatibility and ten representing dangerously incompatible in any concentration. This information was built from the interrogatory data input by the user when the chemical data was initially entered into theChemBook library. It is explained that a mixture such as sodium metal and water, which ignites and burns in miniscule amounts, gets a rating of 10; mixtures of a weak acid and water that only warm slightly rate a 1. The software also has interfaces to add incompatibles and descriptors. Alternately, the user can open the input files using Excel and add the data manually. Chemical compatibility is determined in the ChemicalCompatibility function of the ChemBook class, which compares the chemical type and incompatibles linked lists plus the chemical names of the two chemicals in question. The function accepts a passed node structure containing two chemical names. In the determination, the chemical name of the first chemical is compared to the incompatibles list of the second chemical followed by the comparison of all the chemical type descriptors of the first chemical against all the incompatibles of the second chemical. Finally, the chemicals are reversed and the comparisons are made again. The largest value from the comparisons is returned from the function call. The four linked lists of the ChemBook class all have native functions to insert, delete and reset the lists, plus functions to sequentially serve the lists for searches and display. The functions in the C++ program that utilize the ChemBook class functions are the human interfaces to utilize the chemical library. The AddChemicalToList function is the user interface to add a new chemical or mixture to the library. The LoadChemicalDatafunction reads the chemical data from a comma-delineated file and the LoadChemAuxData function performs the same service for the chemical type descriptors, incompatibles and mixtures. As previously explained, these files are easily edited using many standard applications.InterfaceChemicalData is the function that permits the user to access the chemical data by invoking the ChemLookup function and feeding theDisplayChemicalInfo function. DeleteChemical is the final housekeeping function to remove extraneous or erroneous chemicals. |