#include #include #include #include // RETURNS A PROBABILITY IN THE RANGE [0.0 .. 1.0] double PROB(void) { return ((double)rand()/(double)RAND_MAX); } // SIMULATE THE COMMUNICATION, RETURN ITS UTILISATION double SlottedAloha(int nslots, int nnodes, double ProbNew, double ProbRetry) { double utilisation = 0.0; // SIMULATE THE COMMUNICATION // ...... // CALCULATE THE utilisation HERE return utilisation; } int main(int argc, char *argv[]) { // DEFAULT ATTRIBUTES FOR OUR SIMULATION int nslots = 10000; int nnodes = 5; double ProbNew = 0.1; double ProbRetry = 0.1; // ACCEPT COMMAND-LINE ARGUMENTS TO MODIFY THE DEFAULT ATTRIBUTES if(argc == 5) { nslots = atoi(argv[1]); nnodes = atoi(argv[2]); ProbNew = atof(argv[3]); ProbRetry = atof(argv[4]); } // CHECK THE CHOSEN ATTRIBUTES if(nslots<1 || nnodes<1 || ProbNew<0.0 || ProbNew>1.0 || ProbRetry<0.0 || ProbRetry>1.0) { fprintf(stderr, "Usage: %s nslots nnodes prob-new prob-Tx\n", argv[0]); exit(EXIT_FAILURE); } // SEED RANDOM NUMBER SEQUENCE srand((long)time(NULL)); // SIMULATE THE COMMUNICATION, PRINT ITS UTILISATION printf("%.2f%%\n", 100.0 * SlottedAloha(nslots, nnodes, ProbNew, ProbRetry)); exit(EXIT_SUCCESS); return 0; }