#ifndef _UTILS_H #define _UTILS_H #include "main.h" #include #include #include #include #define SIGN(x) ((x >= 0) ? 1 : -1) #define MAX3(x, y, z) ( (x>y) ? ((x>z) ? x : z) : y ) #define MIN3(x, y, z) ( (x Event; deque events; Timer() {} // add an event that needs to be done at time 'when' void add(int what, double when); // checks if an event is ready, ie the current time (now) is past one // of the times for an event. bool is_ready(double now); // clears all events void clear(); // return the earliest-to-occur event. note: this (obviously) does not // check that the current time is past the event's time. int pop(); }; // a random variable which takes on a given value with a given probability class RandVar { public: typedef pair Event; vector events; double max_prob; // the sum of probabilities of all events RandVar() : max_prob(0.0) {} // add a value and it's probability weight to the set void add(int val, double prob); // change a value's probability weight. if val is not in the set, // it is added. void change(int val, double newprob); // clear all events void clear(); // return one of the values based on the weighted probability of each // value. for example, if value '0' has probability 0.9, it will be // returned 90% of the time. int rand(); }; #endif // _UTILS_H