Columns


CUG New Release

Socket++, SGPC, CForms, and Small Matrix Toolbox

Victor R. Volkman


Victor R. Volkman received a BS in Computer Science from Michigan Technological University. He has been a frequent contributor to The C Users Journal since 1987. He is currently employed as Senior Analyst at H.C.I.A. of Ann Arbor, Michigan. He can be reached by dial-in at the HAL 9000 BBS (313) 663-4173 or by Usenet mail to sysop@hal9k.com.

This month's additions to the C Users Group Library include three useful tools for UNIX systems, plus a handy shareware package that compiles on both UNIX and MS-DOS systems to perform matrix arithmetic:

Socket++: CUG #400

BSD UNIX sockets have been growing in popularity since their first appearance in 4.1cBSD UNIX release for DEC VAX-11 in 1982. Today, sockets can be found in nearly all BSD derivatives and even in MS-Windows. BSD sockets emulate file descriptors and appear to programs as an extension of the UNIX file I/O system. Accordingly, you can call the standard library functions, such as read and write, to receive and transmit data through sockets. Since network communications requires more control than the file descriptor functions alone can provide, several new functions were added for use with sockets. For example, establishing a connection requires details about hosts, ports, protocols, and other options that simply cannot be expressed by open alone. For a brief overview of BSD sockets, see "Programming with Sockets" by Marco Tomassini in the September 1991 issue of CUJ, Vol. 9, No. 9, pp. 39-56.

Socket++, by Gnanasekaran Swaminathan (Centreville, VA), is an iostream-like class for UNIX and inet sockets, pipes, and socket-pairs. Socket++ classes can be used more effectively than directly calling the underlying low-level system functions. Since Socket++ has the same interface as the LibG++ iostream (i.e. like cout and cin), it automatically performs type-safe input and output.

Socket++ provides the following classes:

Even though Socket++ is very easy to use with its own standard functions, it still supports a full complement of socket options including the following: error reporting, debug mode, keepalives, routing, broadcast datagrams, out-of-band data, and buffer resizing. Socket++ includes a mechanism for handling timeouts gracefully as well.

Socket++ runs on many UNIX platforms including Sun Sparc, IBM RS/6000, DECstation, and SGI Indigo boxes. Socket++ version 1.4, released on 13-Jun-93, is now available as CUG Library volume #400.

SGPC: CUG #401

SGPC or "Simple Genetic Programming in C," by Walter Alden Tackett and Aviram Carmi, supports the "Adaptive Automatic Program Induction" method defined by Koza and Rice (Stanford University). The Koza and Rice method generates LISP programs designed to solve problems specified by the user. Tackett and Carmi have produced SGPC by porting the underlying algorithm for program creation from LISP to C. Thus, SGPC is a C program that generates LISP genetic programs as its output. Since SGPC is now available in C, it offers greater portability and a 25 to 50 times speed improvement, according to Tackett and Carmi. One notable improvement over the original is its ability to handle multiple populations. SGPC has been successfully built on many UNIX workstations including Sun Sparcs, DECstations, HP-UX, and SGI Indigo. SGPC version 1.0 is now available as volume #401 in the CUG Library.

Problem definition takes place within three predefined files named setup.c, fitness. c, and prob.h. Specifically, setup.c contains a function table and the functions it references as well as the terminals table. Next, prob.h must contain prototypes for the user-defined functions. Last, fitness.c contains functions to evaluate and validate populations and trees, and to perform early termination, as well as the definition of the fitness (training and test) cases. Since each problem uses the same filenames, you'll need to have a separate subdirectory for each problem. SGPC includes an example set to solve Koza's simple regression problem and the ADF problem with a simple 2-class dendritic classifier.

For a complete description of genetic methods see Genetic Programming by John R. Koza, MIT Press, 1992. For other reading, Tackett delivered a paper entitled "Genetic Programming for Feature Discovery and Image Discrimination" for "Genetic_Algorithms: Proceedings of the Fifth International Conference" (GA93), S. Forrest Ed., Morgan-Kaufman 1993.

CForms: CUG #402

CForms, by Lars Berntzon (Stockholm, Sweden), is a tool for building interactive forms-driven applications. CForms applications can run on any type of library supported by the curses library. CForms uses a language-based design to define forms. An application may contain C source modules, field pictures, field definitions, literals, and events. CForms applications must be compiled with the CFC compiler and linked with the CFL linker. CForms runs on most UNIX SYSV-compatible platforms including SunOS, Dell-SVR4, and Diab SYSV.3. It requires a curses library and yacc or GNU Bison. CForms version 2.1 is now available as volume #402 in the CUG Library.

A CForm application consists of modules containing "pictures" to handle the various functions in the application. A picture in turn consists of fields and text literals describing the appearance. Fields are named regions of the screen used for input and output. Fields have attributes for type, size, and event-handling functions. Before creating a picture, you must first create a viewport. A viewport describes the width, height, and position on the real screen where the picture will appear.

You may specify field positions in absolute or relative coordinates. Alternately, you may ask to "center" on a particular row or column or use "max" to place it on the furthest row or column. CForms fields can be either numeric, character, or alphanumeric. Last, a field can have any combination of the following modifiers: protected (read-only), forbidden, uppercase, highlighted, and invisible.

CForms shows its flexibility and ease of operation best in its event handling. Each field can have special handling for any of the following events: key, refresh, draw, left, entry, and exit. CForms includes a library of more than 30 functions for handling the most common types of event processing. For example, the function fld_ismodified will tell you if the user actually changed anything.

The key event allows you to intercept each keypress as the user types along in the field. CForms supports an extremely extensive set of keys including function keys, editing keys, numeric keypad function keys (e.g. SUN), and special purpose keys (e.g. HELP key). Many keys have separate shift-state identifications (e.g. shift-delete-char). However, control keys and alt keys are not supported.

Small Matrix Toolbox for C: CUG #403

Patrick KO Shu Pui (Tai Po, Hong Kong) contributes the Small Matrix Toolbox for C Programmers. The toolbox is a set of C functions for matrix creation, arithmetic, inversion, and solving linear equations. This product has been released as shareware. Although you may freely use it for academic purposes, commercial users must register with the author for $25. The Small Matrix Toolbox can be compiled on most UNIX workstations as well as Borland C++ on MS-DOS. The toolbox provides makefiles for both UNIX and MS-DOS environments. The Small Matrix Toolbox for C version 0.41 (released 09/23/93) is now immediately available as CUG volume #403.

The toolbox includes an abstract data type called MATRIX plus eighteen functions for manipulating MATRIX objects (see Table 1) . Specifically, the toolbox supplies these functions, where "M" denotes a MATRIX object:

The algorithms themselves are well documented and referenced. KO draws from established computer science texts by Boas, Atkinson, Saito/Nakata, and Aho/Hopcroft/Ullman.