#include "smpl.h" // Needed for SMPL
#include <stdio.h>
//===== Main program ==========================================================
int main(void)
{
real Ts = 10; // Start identification time
real te = 1.0e6; // Total simulation time
int customer = 1; // Customer id (always '1' for this simulation)
int event; // Event (1 = Start identification procedure, 2 = End identification procedure)
int n_reader = 5; // Number of readers
int reader[n_reader]; // Handle for readers facility
int channel = 0; // Channel state: idle=0; busy=1
int i,a,j;
// Initialize SMPL subsystem
smpl(0, "Readers collision");
// Initialize readers facility
reader[0] = facility("reader_0", 1);
reader[1] = facility("reader_1", 1);
reader[2] = facility("reader_2", 1);
reader[3] = facility("reader_3", 1);
reader[4] = facility("reader_4", 1);
// Schedule "start identification" event at random time for each reader
real start_time[n_reader];
for (i=0; i<n_reader; i++) {
start_time = expntl(Ts);
}
real start_time_min = te;
for (i=0; i<n_reader; i++) {
if (start_time_min>start_time)
start_time_min=start_time;
}
for (i=0; i<n_reader; i++) {
schedule(1, start_time-start_time_min, customer);
}
// Loop while simulation time is less than te
while (time() < te)
{
// "Cause" the next event on the event list
cause(&event,&customer);
// Process the event
switch(event)
{
case 1: // *** Start identification procedure and use of the protocol if it's necessary
if (channel == 0)
{
channel = 1;
// Schedule "finish identification" event at random time for each reader
real finish_time[n_reader];
finish_time = start_time + expntl(Ts);
schedule(2, finish_time, costomer);
}
else //Ci sono collisioni
reset(start_time);
start_time=random(CW);
schedule(1,start_time,costomer);
}
break;
case 2: // *** End identification procedure
channel = 0;
// release(server, customer);
break;
}
}
// Output standard SMPL report
report();
return 0;
}
Io ho scritto questo anche se penso ci siano dei problemi sulla gestione della collisione
comunque dacci un'occhiata e fammi sapere