-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated lib-sumo for SUMO 0.26; includes vehicle API.
- Loading branch information
William Emfinger
committed
Apr 25, 2016
1 parent
7f6a1ea
commit 0e12a65
Showing
98 changed files
with
1,205 additions
and
1,005 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
|
||
#include <iostream> | ||
#include <limits.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <time.h> | ||
#include <math.h> | ||
|
@@ -75,6 +76,7 @@ class MTRand { | |
// Data | ||
public: | ||
typedef unsigned long uint32; // unsigned integer type, at least 32 bits | ||
typedef unsigned long long int uint64; // unsigned integer type, at least 64 bits | ||
|
||
enum { N = 624 }; // length of state vector | ||
enum { SAVE = N + 1 }; // length of array for save() | ||
|
@@ -106,6 +108,8 @@ class MTRand { | |
double randDblExc( const double& n ); // real number in (0,n) | ||
uint32 randInt(); // integer in [0,2^32-1] | ||
uint32 randInt( const uint32& n ); // integer in [0,n] for n < 2^32 | ||
|
||
uint64 randInt64( const uint64& n ); // integer in [0,n] for n < 2^64 | ||
double operator()() { return rand(); } // same as rand() | ||
|
||
// Access to 53-bit random numbers (capacity of IEEE double precision) | ||
|
@@ -218,6 +222,30 @@ inline MTRand::uint32 MTRand::randInt( const uint32& n ) | |
} | ||
|
||
|
||
inline MTRand::uint64 MTRand::randInt64( const uint64& n ) | ||
{ | ||
if (n <= INT_MAX) { | ||
return randInt((uint32)n); | ||
} | ||
// Find which bits are used in n | ||
// Optimized by Magnus Jonsson ([email protected]) | ||
uint64 used = n; | ||
used |= used >> 1; | ||
used |= used >> 2; | ||
used |= used >> 4; | ||
used |= used >> 8; | ||
used |= used >> 16; | ||
used |= used >> 32; | ||
|
||
// Draw numbers until one is found in [0,n] | ||
uint64 i; | ||
do | ||
i = (((uint64)randInt() << 32) | randInt()) & used; // toss unused bits to shorten search | ||
while( i > n ); | ||
return i; | ||
} | ||
|
||
|
||
inline void MTRand::seed( const uint32 oneSeed ) | ||
{ | ||
// Seed the generator with a simple uint32 | ||
|
Oops, something went wrong.