COST is a library of several classes that facilitates the development of discrete event simulation using CompC++, a component-oriented extension to C++. It differs from many other tools in the simulation worldview it adopts. There are primarily two worldviews that are widely used in the discrete event simulation community: Event Scheduling and Process Interaction. Both have their strengths and weaknesses. The Event Scheduling is much more efficient, but it is hard to program. Process Interaction technique requires less programming effort. However, it is difficult to implement using imperative programming languages and many implementations based on special simulation languages are not efficient.

COST adopts a component-oriented worldview, which is a variation of the Event Scheduling worldview. Using this technique, a discrete event simulation is viewed as a collection of components that interact with each other by exchanging messages through communication ports. Besides components, the simulation contains a simulation engine that is responsible for synchronizing components. An event-oriented view is adopted to model individual components, i.e., the component has one or more event handlers each of which performs corresponding actions upon the arrival of a certain type events. Events are divided into two categories. Synchronous events are the messages arriving at the input ports, which is sent by its neighboring components. Asynchronous events are associated with timers, a special kind of ports lying between the components and the simulation engine. Components receive and schedule asynchronous events through timers.

COST takes advantage of component-oriented features that are only available in CompC++.




How It Works

Here is the graphical representation of a component.

Using COST, you need to design a new component class for each kind of components. The new component class must be derived from the TypeII class and defined as follows:

    component Server : public TypeII
    {
     private:
        /* private variables */
     public:
        /* parameters */
        unsigned int queue_length;
        double service_time;
        
        /* inports, outports, timers */
        inport inline void in(DATATYPE&);
        outport void out(DATATYPE&);
        Timer<trigger_t> wait;
        inport inline void depart(trigger_t&);
        
        void Start();
        void Stop();
    };
    void CServer::Start()
    {
        /* initialization */
    } 
    void CServer::Stop()
    {
        /* clean up */
    }
    /* implementation of inports */
The system is constructed by integrating components, as shown in the following figure.

To model the system, derive a new system component from the CostSimEng class. It first declares several components as its data members, and then initializes and connects them in the Setup() function. Like other components, a system component contains a Start() and a Stop() function.

    component MM1 : public CostSimEng
    {
    private:
        /* private variables */
    public:
        /* sub-components */
        Source source;
        Server <packet_t>> fifo_server;
        Sink sink;
        
        /* parameters here */
        /* several functions are also needed */
        void Setup();
        void Start();
        void Stop();
    };
    void MM1::Setup()
    {
        /* instantiate components */
        /* connect components */
    }
    void MM1::Start()
    {
        /* initialization */
    }
    void MM1::Stop()
    {
        /* clean up */
    } 

To run the simulation, first create a system instance. After setting all parameters, call the Setup() function followed by the Run() function:

    int main(int argc, char* argv[])
    {
        MM1 mm1;

        /* setting parameters */
        mm1.interval=1;
        mm1.queue_length=100;
        mm1.service_time=0.5;
        mm1.StopTime=1000000.0;
        mm1.Seed=10;

        mm1.Setup(); // must be called first
        mm1.Run(); // run the simulation

       return 0;
    }



Gilbert (Gang) Chen
Boleslaw K Szymanski
Computer Science Department
Rensselaer Polytechnic Institute
(Last updated July 30, 2004)