Wednesday, May 31, 2006

Syntax for Interprocess Communication in the Simulation Collection

I am planning on extending the simulation collection to include interprocess communications (and synchronization) functionality based of Ada task interactions. Note that this is between processes in the simulation collection, not OS processes.

This will allow the model developer to more easily specify process interactions. For examples, resources could be implemented using this functionality.

Entry Definition
Each process entry must be declared in the define-process macro call that defines the process.
(entry (name . arguments))
Entry Acceptance
The simplest use of an entry is the accept statement.
(accept (name . arguments)
body...)
This is an executable statement that will either accept the first (i.e. highest priority) call to name or wait until such a call occurs.
The select statement allows more control over the selection of entry calls.
(select
accept-clause
...)
Each select clause has one of the following forms:
((accept (name . arguments)
body ...)
body ...)

((expr)
(accept (name . arguments)
body ...)
body ...)

((delay n)
body ...)

(else
body ...)
The first clause specifies an unguarded accept statement. That is, there are no conditions on its acceptance. The second clause specified a guarded clause. The accept is only active if the guard expression evaluates to true. The third clause is a timeout. The body will be evaluated if none of the alternatives have been accept before the specified (simulated) time has elapsed. The last is an else clause. Its body will be evaluated of no other clause is active.

[We could also allow a simple accept statement as an alternative when no code is specified other than the entry code itself. That is, allow the following:
(select (name . arguments)
body ...)
Simple examples:
(define-process (test)
(entry (abc a b c))
...
(accept (abc a b c)
(printf "a=~s b=~s c=~s~n" a b c))
...)

(define-process (test)
(entry (abc a b c))
...
(select
(accept (abc a b c)
(printf "a=~s b=~s c=~s~n" a b c))
(else
(printf "No entry waiting~n")))
...)

(define-process (test)
(entry (abc a b c))
...
(select
(accept (abc a b c)
(printf "a=~s b=~s c=~s~n" a b c))
((delay 10.0)
(printf "No entry after waiting 10.0 units~n")))
...)

Entry Calls
For now, I will implement an enter statement with a syntax similar to the send statement for classes:

(enter process-instance name . arguments)

A more advanced use is to also allow the select statement with wither a delay or an else clause.
(define my-test (make-process test))

(select
(enter my-test x y z)
((delay 10.0)
(printf "Entry no accepted after 10.0 units~n")))

(select
(enter my-test x y z)
(else
(printf "Entry not open~n")))

I need to decide if it makes any sense to allow other code after the entry call but withn the select.

Since the delay and else clauses don't make sense together (because a delay will always be open), I could combine them:

(else
[(delay n)]
body ...)
I will cover possible implementation strategies in a later post.

Labels:

PLT Scheme Simulation Collection

The PLT Scheme Simulation Collection implements a combined discrete event and continuous event simulation engine for developing simulation models in PLT Scheme. The simulation engine:
  • Provides a process-based, discrete event simulation engine
  • Supports combined discrete and continuous simulation models
  • Provides automatic data collection
  • Is designed to facilitate construction of component-based simulation models
The source code is distributed with the simulation collection and licensed under the GNU Lesser General Public License (LGPL).

The PLT Scheme Simulation Collection provides the following functionality for building and executing simulation models:
  • Simulation Environments (Basic)
  • Simulation Control (Basic)
  • Events
  • Processes
  • Resources
  • Data Collection
  • Sets
  • Continuous Simulation Models
  • Monitors
  • Simulation Classes
  • Simulation Control (Advanced)
  • Simulation Environments (Hierarchical)
  • Components
The PLT Scheme Simulation Collection is available via the PLaneT repository using the following form:

(require (planet "simulation.ss" ("williams" "simulation.plt")))

This will download and install the latest version of the simulation collection. The reference manual is available on the PLT Scheme Help Desk once the collection is installed.

I am still actively developing the PLT Scheme Simulation Collection. The Simulation Classes needs to be enhanced. The Hierarchical Simulation Environments and Components functionality needs to be completed, Also, I plan on added a process interaction capability using a rendezvous mechanism (similar to Ada task interactions).

Verson 2.0
Version 2.0 of the PLT Scheme Simulation Collection features a full Reference Manual that is compatible with the PLT Scheme Help Desk. The reference manual was written in TEX and converted to HTML using tex2page. A pdf version of the reference manual is also available.

Version 2.0 also provides priority ordering for events and resource allocation; reneging for resources; and linking event execution.

Finally, Version 2.0 adds a monitor capability for simulation timing and for variables.

Bug Fixes
The schedule macro was changed to generate code that is compatible with its use within a module. Previously, it generated code that worked only at the top level.


Labels:

Tuesday, May 30, 2006

PLT Scheme Science Collection

The PLT Scheme Science Collection is a collection of modules that provide functions for numerical computing. The structure of the science collection and many of the underlying algorithms were inspired by the GNU Scientific Library (GSL). The functions are written entirely in PLT Scheme and present a true Scheme look-and-feel throughout. The source code is distributed with the science collection and licensed under the GNU Lesser General Public License (LGPL).
The PLT Scheme Science Collection covers a range of topics in numerical computing. Functions are available for the following areas:
  • Mathematical Constants and Functions
  • Special Functions
  • Random Numbers
  • Random Distributions
  • Statistics
  • Histograms
  • Orginary Differential Equations
  • Chebyshev Approximations
The PLT Scheme Science Collection is available via the PLaneT repository using the following form:

(require (planet "science.ss" ("williams" "science.plt")))

This will download and install the latest version of the science collection. The reference manual is available on the PLT Scheme Help Desk once the collection is installed.
I don't have any updates scheduled for the PLT Scheme Science Collection. Bugs reports or requests for enhancements are welcome, however.

Version 2.2.1
Version 2.2.1 is a point release of Version 2.2 where the discrete random routines were reimplemented using Walker's O(1) algorithm.

Version 2.2
Version 2.2 of the PLT Scheme Science Collection features a reformatted Reference Manual that is compatible with the PLT Scheme Help Desk. The reference manual was written in TeX and converted to HTML using tex2page. A pdf version of the reference manual is also available.

Bug Fixes
The gamma-inc-Q function has been added. It was accidentally stubbed out in Version 2.1

Version 2.1
Version 2.1 of the PLT Scheme Science Collection added cummulative density functions for the rest of the 1-dimensional, continuous distributions (except the Gaussian tail distribution). The corresponding graphics routines were also updated to plot the cummulative density functions. Also, beta, incomplete gamma, and exponential integral special functions were implemented.

Bug Fixes
The lngamma function returned incorrect values for positive values less than 0.5.

Downloading the science collection from PLaneT on a computer with less than(approximately) 1GB of memory failed. This is caused in a bug in the PLT Scheme setup collection that fails on large files. The pdf file for the reference manual -- the large file that caused the problem -- was removed from the distributed science collection.

2-dimensional histogram plots failed. This was an error in the PLoT package distributed with PLT Scheme. It is fixed in V301.5 and later.

Version 2.0
Version 2.0 of the PLT Scheme Science Collection added ordinary differential equations. These were needed for the PLT Scheme Simulation Collection.

Labels:

Saturday, May 27, 2006

PLT Scheme Projects

This blog is about my various open source PLT Scheme projects. There are three major Scheme projects I am currently working on. Two of these - PLT Scheme Science Collection and PLT Scheme Simulation Collection - have already been released. The third - PLT Scheme Inference Collection - is currently under development.
I had developed a knowledge-based simulation capability in Symbolics Common Lisp back in the late 1980s. I moved on to more traditional simulation technologies in my professional career and the work was largely forgotten. In the 1990s as PCs made their way into the classroom, I began using Scheme for teaching AI. However, at the time I didn't consider Scheme to be suitable for production quality software.
A few years ago, I came across PLT Scheme that seemed to meet my needs: it had an integrated development environment, it supported modern programming paradigms (e.g. object oriented programming, graphical user interfaces, exception handling, and modules), it was reasonably efficient, and it was portable across Windows and Linux, which are my two main platforms. Eventually I decided to resurrect my knowledge-based simulation work in PLT Scheme.
It was obvious that a simple port of the original Common Lisp code was not the best approach to the problem. I decomposed the problem into three basic components: the underlying mathematical and analysis capability, the simulation engine, and the inference engine. These became the science collection, simulation collection, and inference collection.
As I began developing the science collection, I noticed that much of what I needed was in the GNU Scientific Library (GSL). So, I decided that I would use the structure, and algorithms to the extent practical, of the GSL for the science collection. Version 1.0 of the PLT Scheme Science Collection was released via PLaneT in October 2004.
The simulation collection is a complete rewrite from the Common Lisp code. One of the advantages of Scheme is the availability of continuations, which are ideally suited for the implementation of a process-based simulation engine. I also decided to add a continuous simulation capability to the simulation engine. Version 1.0 of the PLT Scheme Simulation Collection was released in August 2005.
With my background in Artificial Intelligence, I was somewhat surprised at myself for leaving the inference collection as the last of the three to be implemented; particularly since I already have a Scheme version of a naive inference engine written. But, it made sense that way. It also turns out that the inference collection is a complete rewrite of the Common Lisp (and earlier Scheme) code. I plan on releasing Version 1.0 of the PLT Scheme Inference Collection during the summer of 2006.
I also have some Scheme programs that I have used in teaching AI classes over the years. Over time, I will convert these to PLT Scheme and make them available. The only one I have converted so far is a collection for defining state space problems and solving them using a graph search algorithm.

Labels: , , ,