Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/MIConvexHull/ConvexHull/VertexSort.cs @ 10159

Last change on this file since 10159 was 9945, checked in by ascheibe, 11 years ago

#1886

  • added new convex hull algorithm based on SMO/SVM
  • added unit test and a visualization
  • updated MIConvexHull
File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace MIConvexHull
7{
8    class VertexSort:IComparer<VertexWrap>
9    {
10        private readonly int dimension;
11        public List<VertexWrap> Duplicates { get; private set; }
12
13        public VertexSort(int Dimension)
14        {
15            this.dimension = Dimension;
16            Duplicates = new List<VertexWrap>();
17        }
18        public int Compare(VertexWrap x, VertexWrap y)
19        {
20            if (x == y) return 0;
21            for (int i = 0; i < dimension; i++)
22            {
23                if (x.PositionData[i] < y.PositionData[i]) return -1;
24                if (x.PositionData[i] > y.PositionData[i]) return 1;
25            }
26            if (isANewDuplicate(x)) Duplicates.Add(x);
27            return 0;
28        }
29
30        private bool isANewDuplicate(VertexWrap x)
31        {
32            for (int i = 0; i < Duplicates.Count; i++)
33            {
34                if (Constants.SamePosition(x.PositionData, Duplicates[i].PositionData, dimension))
35                    return false;
36            }
37            return true;
38        }
39
40    }
41}
Note: See TracBrowser for help on using the repository browser.