Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Utils/Util.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 8 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Core;
8using HeuristicLab.Random;
9
10namespace 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.