Last change
on this file since 13412 was
13412,
checked in by abeham, 9 years ago
|
#2221:
- Completely refactored PTSP branch
- Added two sets of problem instances based on TSPLIB: homogeneous and heterogeneous
- Implemented missing EvaluateByCoordinates for 1-shift moves
- Made it clear that move evaluators are for estimated PTSP only
- Changed parameter realization from a rather strange list of list of ints to a list of bool arrays
- Reusing code of the 2-opt and 1-shift move evaluators in 2.5 move evaluator
- Introducing distance calculators to properly handle the case when no distance matrix is given (previous code only worked with distance matrix and without only with euclidean distance in some settings)
- Fixed several smaller code issues: protected, static, method parameters, copy & paste, interfaces, naming, parameters, serialization hooks, license headers, doc comments, data types
|
File size:
1.4 KB
|
Line | |
---|
1 |
|
---|
2 | namespace HeuristicLab.Problems.Instances.TSPLIB {
|
---|
3 | /// <summary>
|
---|
4 | /// This class is used to randomly generate PTSP instances given the TSPLIB instances.
|
---|
5 | /// An own implementation of a RNG was used in order to avoid possible implementation changes
|
---|
6 | /// in future .NET versions which would result in entirely different instances.
|
---|
7 | /// </summary>
|
---|
8 | internal class MarsagliaRandom {
|
---|
9 | /*
|
---|
10 | * S = 2111111111*X[n-4] + 1492*X[n-3] + 1776*X[n-2] + 5115*X[n-1] + C
|
---|
11 | * X[n] = S modulo 2^32
|
---|
12 | * C = floor(S / 2^32)
|
---|
13 | *
|
---|
14 | */
|
---|
15 | private readonly uint[] mem = new uint[4];
|
---|
16 | private uint c;
|
---|
17 |
|
---|
18 | public MarsagliaRandom(uint s) {
|
---|
19 | Seed(s);
|
---|
20 | }
|
---|
21 |
|
---|
22 | private uint Next() {
|
---|
23 | unchecked {
|
---|
24 | ulong wsum = 2111111111 * mem[0]
|
---|
25 | + 1492 * mem[1]
|
---|
26 | + 1776 * mem[2]
|
---|
27 | + 5115 * mem[3]
|
---|
28 | + c;
|
---|
29 |
|
---|
30 | mem[0] = mem[1];
|
---|
31 | mem[1] = mem[2];
|
---|
32 | mem[2] = mem[3];
|
---|
33 | mem[3] = (uint)wsum;
|
---|
34 | c = (uint)(wsum >> 32);
|
---|
35 | return mem[3];
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public double NextDouble() {
|
---|
40 | return (double)Next() / uint.MaxValue;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void Seed(uint seed) {
|
---|
44 | int i;
|
---|
45 | for (i = 0; i < mem.Length; i++) {
|
---|
46 | unchecked {
|
---|
47 | seed = seed * 31294061 + 1;
|
---|
48 | }
|
---|
49 | mem[i] = seed;
|
---|
50 | }
|
---|
51 | unchecked {
|
---|
52 | c = seed * 31294061 + 1;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.