You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Output Strategy

Applying options for output destination.

Concept

OMS provides three options for output files: (1) Simple (default), which overwrites the previous simulation output in the same file, (2) Numbered, which provides a new numbered folder for the output with each simulation, and (3) Time, which provides a time stamped folder for output with each simulation.

Implementation

The 'IterationControl' component in the previous example is re-used. The component consumes the 'count' and 'output' path and file name, and while 'done' is false, prints the count to the file and prints the count to system output. When 'done' is true, a summary message is printed to standard output.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ex21;

import java.io.PrintWriter;
import java.io.IOException;
import java.io.File;
import oms3.annotations.*;
import static oms3.annotations.Role.*;

public class IterationControl {

    @Role(PARAMETER)
    @In public int count;

    @Role(PARAMETER + OUTPUT)
    @In public File output;

    // flag for controlling the iteration
    @Out public boolean done;

    // current iteration variable
    int i;
    PrintWriter w;

    @Execute
    public void execute() throws IOException {
        if (i==0) {
            w = new PrintWriter(output);
            i = count;
        }
        w.println(i);
        done = i-- > 1;
        System.out.println("Count " + i);
    }


    @Finalize
    public void done() throws IOException {
        if (w != null)
            w.close();
        System.out.println("Wrote output to " + output);
    }
}

The simulation file is the same as in the previous example except output strategy specifies the path as shown and strategy type as NUMBERED (line 7). Parameter 'output' is set to the file name. As with the previous example, simulation specifies one component in the model (line 21), sets iteration (line 10), and parameter 'count' set to 5 (line 14).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import static oms3.SimBuilder.instance as OMS3

OMS3.sim(name:"ex17") {

    // define output strategy: output base dir and
    // the strategy NUMBERED|SIMPLE|TIME
    outputstrategy(dir: "$oms_prj/output", scheme:NUMBERED)

    // the iteration is controlled by the 'c' component's 'done' field.
    model(iter:"c.done") {

       parameter {
          // repeat the iteration 5 times
          'c.count'  5
          // output file, the full path is managed by the outputstrategy
          'c.output' "out.txt"
       }

       components {
          // c is the counter control component.
          'c' 'ex20.IterationControl'
       }
    }
}