Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Random;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.BioBoost.Utils {
|
---|
11 | public class Util {
|
---|
12 |
|
---|
13 | public static double Distance(Point p1, Point p2) {
|
---|
14 | return Math.Sqrt(Sqr(p1.X - p2.X) + Sqr(p1.Y - p2.Y));
|
---|
15 | }
|
---|
16 |
|
---|
17 | public static double Sqr(double x) { return x * x; }
|
---|
18 |
|
---|
19 | public static void Shuffle<T>(T[] elements, IRandom random) {
|
---|
20 | for (int i = elements.Length - 1; i > 0; i--) {
|
---|
21 | // Swap element "i" with a random earlier element (including itself)
|
---|
22 | int swapIndex = random.Next(i + 1);
|
---|
23 | T temp = elements[swapIndex];
|
---|
24 | elements[swapIndex] = elements[i];
|
---|
25 | elements[i] = temp;
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public static T[] Clone<T>(T[] t) {
|
---|
30 | return (T[]) (t == null ? null : t.Clone());
|
---|
31 | }
|
---|
32 |
|
---|
33 | public static T Clone<T>(T t) where T : ICloneable {
|
---|
34 | return (T) (t == null ? null : t.Clone());
|
---|
35 | }
|
---|
36 |
|
---|
37 | }
|
---|
38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.