it.unimi.dsi.util.XoRoShiRo128PlusRandom Java Examples
The following examples show how to use
it.unimi.dsi.util.XoRoShiRo128PlusRandom.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LayeredLabelPropagation.java From fasten with Apache License 2.0 | 6 votes |
/** Creates a new instance using a specific initial permutation and specified number of threads. * * <p>If <code>exact</code> is true, the final permutation is * <em>exactly</em> the same as if you first permute the graph with <code>startPerm</code> and * then apply LLP with an {@code null} starting permutation. * * @param symGraph a symmetric, loopless graph. * @param startPerm an initial permutation of the graph, or {@code null} for no permutation. * @param numberOfThreads the number of threads to be used (0 for automatic sizing). * @param seed a random seed. * @param exact a boolean flag that forces the algorithm to run exactly. */ public LayeredLabelPropagation(final ImmutableGraph symGraph, final int[] startPerm, final int numberOfThreads, final long seed, final boolean exact) throws IOException { this.symGraph = symGraph; this.n = symGraph.numNodes(); this.startPerm = startPerm; this.seed = seed; this.r = new XoRoShiRo128PlusRandom(seed); this.exact = exact; this.label = new AtomicIntegerArray(n); this.volume = new AtomicIntegerArray(n); cumulativeOutdegrees = new EliasFanoCumulativeOutdegreeList(symGraph, symGraph.numArcs(), 1); this.gapCost = new MutableDouble(); this.updateList = Util.identity(n); simpleUncaughtExceptionHandler = new SimpleUncaughtExceptionHandler(); labelling = File.createTempFile(this.getClass().getName(), "labelling"); labelling.deleteOnExit(); this.numberOfThreads = numberOfThreads != 0 ? numberOfThreads : Runtime.getRuntime().availableProcessors(); this.canChange = new boolean[n]; this.modified = new AtomicInteger(0); this.objectiveFunction = new double[this.numberOfThreads]; }
Example #2
Source File: ByteArrayDiskQueuesTest.java From BUbiNG with Apache License 2.0 | 6 votes |
@Test public void testReadWriteVByte() throws IOException { final File dir = File.createTempFile(ByteArrayDiskQueuesTest.class.getName() + "-", "-temp"); dir.delete(); dir.mkdir(); final ByteArrayDiskQueues queues = new ByteArrayDiskQueues(dir, LOG2_LOG_FILE_SIZE); final XoRoShiRo128PlusRandom random = new XoRoShiRo128PlusRandom(1); queues.pointer(0); for(int i = 0; i < 10000000; i++) queues.encodeInt(random.nextInt(Integer.MAX_VALUE)); queues.pointer(0); random.setSeed(1); for(int i = 0; i < 10000000; i++) assertEquals(random.nextInt(Integer.MAX_VALUE), queues.decodeInt()); queues.close(); FileUtils.deleteDirectory(dir); }
Example #3
Source File: ByteArrayDiskQueueTest.java From BUbiNG with Apache License 2.0 | 6 votes |
@Ignore @Test public void testLarge() throws IOException { final File queue = File.createTempFile(this.getClass().getName(), ".queue"); queue.deleteOnExit(); final ByteArrayDiskQueue q = ByteArrayDiskQueue.createNew(queue, 128, true); final XoRoShiRo128PlusRandom random = new XoRoShiRo128PlusRandom(0); final long n = 3000000005L; for(long i = n; i -- != 0;) q.enqueue(new byte[random.nextInt(4)]); assertEquals(n, q.size64()); final XoRoShiRo128PlusRandom random2 = new XoRoShiRo128PlusRandom(0); for(long i = n; i -- != 0;) { q.dequeue(); assertEquals(random2.nextInt(4), q.buffer().size()); } q.close(); }
Example #4
Source File: ReorderingBlockingQueueTest.java From BUbiNG with Apache License 2.0 | 6 votes |
@Test public void testBlocking() throws InterruptedException { for(final int size: new int[] { 10, 100, 128, 256 }) { for(final int d: new int[] { 1, 2, 3, 4 }) { final ReorderingBlockingQueue<Integer> q = new ReorderingBlockingQueue<>(size / d); final int[] perm = Util.identity(size); IntArrays.shuffle(perm, new XoRoShiRo128PlusRandom()); for(int i = perm.length; i-- != 0;) { final int t = perm[i]; new Thread() { @Override public void run() { try { q.put(Integer.valueOf(t), t); } catch (final InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } } }.start(); } for(int i = 0; i < perm.length; i++) assertEquals(i, q.take().intValue()); assertEquals(0, q.size()); } } }
Example #5
Source File: NamedGraphServerHttpProxy.java From BUbiNG with Apache License 2.0 | 5 votes |
public Task(final Socket socket, final NamedGraphServer graphServer, final Semaphore stuckInCapriciousWriting, final int generalPageSpeed, final double frac404, final double frac500, final double fracDelayed, final long averageDelay, final long delayDeviation, boolean undigitize, boolean notescurl) { this.socket = socket; this.graphServer = graphServer; this.stuckInCapriciousWriting = stuckInCapriciousWriting; this.generalPageSpeed = generalPageSpeed; this.frac404 = frac404; this.frac500 = frac500; this.frac500Random = new XoRoShiRo128PlusRandom(); this.fracDelayed = fracDelayed; this.averageDelay = averageDelay; this.delayDeviation = delayDeviation; this.uniquify = undigitize; this.notescurl = notescurl; }
Example #6
Source File: ReorderingBlockingQueueTest.java From BUbiNG with Apache License 2.0 | 5 votes |
@Test public void testNoBlocking() throws InterruptedException { for(final int size: new int[] { 1, 10, 100, 128, 256 }) { final ReorderingBlockingQueue<Integer> q = new ReorderingBlockingQueue<>(size); final int[] perm = Util.identity(size); IntArrays.shuffle(perm, new XoRoShiRo128PlusRandom()); for(int i = perm.length; i-- != 0;) q.put(Integer.valueOf(perm[i]), perm[i]); for(int i = 0; i < perm.length; i++) assertEquals(i, q.take().intValue()); assertEquals(0, q.size()); } }
Example #7
Source File: NamedGraphServerHttpProxy.java From BUbiNG with Apache License 2.0 | 4 votes |
public CapriciousPrintWriter(final Writer writer, final long averageDelay, final long delayDeviation, final XoRoShiRo128PlusRandom random) { super(writer); this.averageDelay = averageDelay; this.delayDeviation = delayDeviation; this.random = random; }
Example #8
Source File: RandomNumbersGenerator.java From tutorials with MIT License | 4 votes |
public Integer generateRandomWithXoRoShiRo128PlusRandom(int min, int max) { XoRoShiRo128PlusRandom xoroRandom = new XoRoShiRo128PlusRandom(); int randomWithXoRoShiRo128PlusRandom = xoroRandom.nextInt(max - min) + min; return randomWithXoRoShiRo128PlusRandom; }