Disim Highway Simulator/Creating an infrastructure controller

Simple Example
Disim allows the creation of totally arbitrary infrastructure control without having to modify its internal code. To illustrate this, let us start by a simple example: imagine that a ramp meter is present on the network and we want to increase the entry rate on the corresponding ramp when the density of the traffic measured by a sensor on the same highway is too low. The script would look like this:

What is the scripting language?
This script was made using LUA (http://www.lua.org/manual/5.1/manual.html): ''Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight scripting language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++).''

Disim allows anyone to create and redefine the infrastructure behavior using LUA as a scripting language. Creating your infrastructure controller in LUA has several advantages: compilation is not needed, a simplified API is available and you benefit from all the LUA capabilities (tables, anonymous functions, dictionaries, ...). As we can observe from the example above, each script should provide the following 3 functions:

This function takes as input a single variable. This variable is a LuaInfrastructure pointer on the current highway network. This function does not return any values, but it might be useful to save some pointers on the different sensors and actuators in the network that we plan to use.

This function takes three variables as input:
 * self: Just like the input function, this is a pointer to the infrastructure controlled.
 * t: This is the absolute time elapsed since the beginning of the simulation.
 * dt: This is the time-step duration in seconds since the last call to that function.

This function does not return any values.

This function takes as input a single variable. This variable is a pointer on the current infrastructure. In this function you should clean up any variable that has been initialized by init.

The API
As seen above, all the functions provided take as an argument a pointer to the current infrastructure being controlled. This pointer describes an object in LUA: the LuaInfrastructure. To see what you can do with this object, check out the LUA API of Disim available here.

What's next?
In the next section, we are going to see how one can combine all that we have seen so far to gather data from a fictitious highway.