Model Description

The main purpose of this example is to show how the cumulative value of a reward defined for an object can be modified by the execution of an action. The main function to accomplish this is called set_cr . We can also obtain the current value of the amount of reward accumulated using the get_cr function. Note: these functions can be used only in simulation.

The model is shown in Figure [*]. In that figure, a source sends packets to a finite exponential queue. The behavior of the source is described in Figure [*]. While in state where the variable state is equal to zero, the source generates packets at an exponential rate. From Figure [*], the state variable status can only change its value when the elapsed time since the last change is at least 10. This elapsed time is stored in the reward elapsed_time.

Figure: Set Cumulative Rewards Values.
\includegraphics[width=4in]{figuras/setreward.eps}
Figure: The Packet Source object (Set Cumulative Rewards Values).
\includegraphics[width=5in]{figuras/objectrewards1.eps}

The description of the Server_Queue object is shown in Figure [*].

Figure: The Server Queue object(Set Cumulative Rewards Values).
\includegraphics[width=5in]{figuras/objectrewards2.eps}

NOTE: get_cr gets the total value of the corresponding rate reward accumulated so far, and set_cr sets the cumulative rate reward value. We can use get_ir to get the total value of the corresponding impulse reward accumulated so far and set_ir to set the impulse reward cumulative value. Again, these functions can be used only in simulation.

: If you need some information about the value of any variable during simulation you can use set_cr to generate a trace containing the values.

Imagine you want to know the values assumed by the queue during simulation. Suppose this state var is called QUEUE. How to do it step by step:

  1. Specify a reward like this:
           rate_reward = NAME_RELATED
           condition=(FALSE)
           value=0;
    
    This reward will not accumulate by itself. Instead, you need to specify its value with the set_cr command.
  2. Inside the code (message or event of the same object) you put the following command: set_cr( NAME_RELATED, QUEUE). This command will modify the cr value of the reward called NAME_RELATED to QUEUE value and will plot the new value in a trace file under condition 3.
  3. To generate the trace file you need to press the trace button at the Reward Option (button) in the Simulation window. You can visualize the values as text in any editor or plot it with Gnuplot.
In order to make the debug action and the analysis of the simulation time easier the following commands can be used:
  1. get_simul_time(). This command is used to get the current simulation time (float). Examples:
         (1) var_float = get_simul_time();
         (2) if (get_simul_time () > var_time)
             {
               do_something;
             }
    
  2. . This command is similar to the print command found in the C language. Example:
    printf ("Debug message1: %d %f \n", int_var, float_var);     
    
  3. . This the same as the fprintf found in the C language. Example:
    fprintf (stderr, "Debug message2: %d %f \n", int_var, float_var); 
    fprintf (stdout, "Debug message3: %d %f \n", int_var, float_var);     
    

Guilherme Dutra Gonzaga Jaime 2010-10-27