Ocelet

Scenario

A scenario contains the series of instructions to be executed during a simulation. These instructions are executed one after the other in the order given.

Syntax

Definition of a scenario scenario scenario name { series of instructions }

The name of a scenario must begin with a letter (preferably upper case) but can eventually be followed by numbers, and not contain blanks or special characters.

In the present version of Ocelet, only one scenario is written containing all the instructions for a simulation. The scenario has the same name as the project. Upon creation of a new project, a minimal scenario with the correct name is also created.

Examples

scenario HelloW {

  println("Hello world !")

}

The scenario will simply display the text: Hello world !

jar and command line

It may be required to run a model from the command line, like when performing a sensitivity analysis. To do that, there is a function Export to jar that can be accessed from the File menu.

Once the model has been exported to jar, and if the model contains a definition of parameters in the metadata {...} bloc, it is possible to pass different parameter values from the command line.

A few constraints must however be respected:

  • The parameters must be given in the same order as in the metadata {...} declaration bloc. If the number of parameters from the command line is different, default values will be used.
  • The parameters are separated with a space character on the command line. Use quotes when parameters are texts containing spaces.
  • The parameter values given in command line must also respect the type of the parameters declared. For example, if a parameter is declared as Integer and the value given is 4.5, this parameter value will be considered invalid, and the default value will be used instead. A message will be displayed to notify of a type conversion problem.
    • A limited number of types are recognized for automatic conversion: Boolean, Byte, Double, Float ,Integer, Long, Short, String
    • If you need to declare a parameter with a type other than these, a solution would be to declare it as String then do the parameter conversion yourself within Ocelet.

Example

Let us consider the Ocelet model Mymodel.oclt written like this:

metadata {
    parameter Integer p1 {default 0}
    parameter Double  p2 {default 0.0}
    parameter String  p3 {default "nothing"}
    parameter Boolean p4 {default false}
}

scenario Mymodel {

  println("Model Mymodel")

  println("p1: "+p1)
  println("p2: "+p2)
  println("p3: "+p3)
  println("p4: "+p4)

  println("Done.")
}

and exported as mymodel.jar

The model can be run without parameters:

> java -jar mymodel.jar 
Model Mymodel
p1: 0
p2: 0.0
p3: nothing
p4: false
Done.

It can be given new values:

> java -jar mymodel.jar 42 3.14159 demo true
Model Mymodel
p1: 42
p2: 3.14159
p3: demo
p4: true
Done.

If we want to pass a text containing spaces for p3, use quotes:

> java -jar mymodel.jar 42 3.14159 "Eat at Joe's" true
Model Mymodel
p1: 42
p2: 3.14159
p3: Eat at Joe's
p4: true
Done.

If there is a type error on a parameter, a message is displayed, but the model is not halted:

> java -jar mymodel.jar douze 3.14159 "Eat at Joe's" true
Warning: could not convert the argument "douze" into an Integer value
         for the parameter p1. The default value will be used instead.
Model Mymodel
p1: 0
p2: 3.14159
p3: Eat at Joe's
p4: true
Done.

If the number of parameters passed is not correct, they are ignored:

> java -jar mymodel.jar 42 3.14159 "Eat at Joe's" true 100
Model Mymodel
p1: 0
p2: 0.0
p3: rien
p4: false
Done.