Queues//stacks
How-to


Introduction

It is often nice to be able to simulate a queue or stack disipline for places, e.g. for communication over a TCP channel.

Alas, CPN Tools does not currently support this, but this is easy done by the modeller.

Example

image unordered.jpg

This is a very simple model of a sender and a receiver.

The sender, sends packages onto a network.

The receiver receives packages from the network.

Stack

We want the network to have a LIFO (last in, first out), or stack behaviour. (Yes, this is not realistic, but then I only need to introduce one example).

We change the type of the place from "T" to "list T", and make all ingoing arcs preprend to the list, and all outgoing arcs should then remove the head from the list.

When I do this to the above example, I get:

image stack.jpg

Changes to Declarations

Changes to the Network Place

Changes to Arcs (ingoing and outgoing)

Queues

We want the network to have a FIFO (first in, first out), or queue behaviour. This is like the behaviour of TCP streams.

We change the type of the place from "T" to "list T", and make all ingoing arcs append to the list, and all outgoing arcs should then remove the head from the list.

The only difference from stacks is that instead of prepending to the list, we append to it. When I do this to the example, I obtain:

image queue.jpg

Changes to Declarations

Changes to the Network Place

Changes to Outgoing Arcs

Changes to Ingoing Arcs

Priority Queues

We want the network to have a priority-queue behaviour, i.e. the priority of a packet determines the order in which it is handled. This is similar to IP quality-of-service options which allow datagrams to be identified (and possibly handled) with eight levels of precedence.

We change the type of the place from "T" to "list T", and make all ingoing arcs insert elements into the list according to precedence/priority, and all outgoing arcs should then remove the head from the list.

The difference from FIFO queues is that instead of appending to the list, elements are added according to their priority. When I do this to the example, I obtain:

Priority queue

Changes to Declarations

Changes to the Network Place

Changes to Outgoing Arcs

Changes to Ingoing Arcs

Examples

The examples described in this document can be downloaded