Skip to content

Commit 7185d3c

Browse files
committed
Merge branch 'master' into beta
2 parents 9514748 + e4b9fa2 commit 7185d3c

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed

src/Advanced.Algorithms/Geometry/BentleyOttmann.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class BentleyOttmann
1212
{
1313
private readonly PointComparer pointComparer;
1414

15-
private HashSet<Event> verticalHorizontalLines;
15+
private HashSet<Event> verticalAndHorizontalLines;
1616
private HashSet<Event> otherLines;
1717

1818
private BHeap<Event> eventQueue;
@@ -41,7 +41,7 @@ private void initialize(IEnumerable<Line> lineSegments)
4141
currentlyTrackedLines = new RedBlackTree<Event>(true, pointComparer);
4242
intersectionEvents = new Dictionary<Point, HashSet<Tuple<Event, Event>>>(pointComparer);
4343

44-
verticalHorizontalLines = new HashSet<Event>();
44+
verticalAndHorizontalLines = new HashSet<Event>();
4545
otherLines = new HashSet<Event>();
4646

4747
rightLeftEventLookUp = lineSegments
@@ -82,9 +82,9 @@ public Dictionary<Point, List<Line>> FindIntersections(IEnumerable<Line> lineSeg
8282
case EventType.Start:
8383

8484
//special case
85-
if (verticalHorizontalLines.Count > 0)
85+
if (verticalAndHorizontalLines.Count > 0)
8686
{
87-
foreach (var line in verticalHorizontalLines)
87+
foreach (var line in verticalAndHorizontalLines)
8888
{
8989
var intersection = findIntersection(currentEvent, line);
9090
recordIntersection(currentEvent, line, intersection);
@@ -94,7 +94,7 @@ public Dictionary<Point, List<Line>> FindIntersections(IEnumerable<Line> lineSeg
9494
//special case
9595
if (currentEvent.Segment.IsVertical || currentEvent.Segment.IsHorizontal)
9696
{
97-
verticalHorizontalLines.Add(currentEvent);
97+
verticalAndHorizontalLines.Add(currentEvent);
9898

9999
foreach (var line in otherLines)
100100
{
@@ -129,7 +129,7 @@ public Dictionary<Point, List<Line>> FindIntersections(IEnumerable<Line> lineSeg
129129
//special case
130130
if (currentEvent.Segment.IsVertical || currentEvent.Segment.IsHorizontal)
131131
{
132-
verticalHorizontalLines.Remove(currentEvent);
132+
verticalAndHorizontalLines.Remove(currentEvent);
133133
break;
134134
}
135135

src/Advanced.Algorithms/Graph/Coloring/MColorer.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,32 @@ public class MColorer<T, C>
1414
/// </summary>
1515
public MColorResult<T, C> Color(IGraph<T> graph, C[] colors)
1616
{
17+
var totalProgress = new Dictionary<IGraphVertex<T>, C>();
1718

18-
var first = graph.ReferenceVertex;
19-
20-
var progress = canColor(first, colors,
21-
new Dictionary<IGraphVertex<T>, C>(),
22-
new HashSet<IGraphVertex<T>>());
19+
foreach (var vertex in graph.VerticesAsEnumberable)
20+
{
21+
var progress = canColor(vertex, colors,
22+
new Dictionary<IGraphVertex<T>, C>(),
23+
new HashSet<IGraphVertex<T>>());
24+
25+
foreach(var item in progress)
26+
{
27+
if (!totalProgress.ContainsKey(item.Key))
28+
{
29+
totalProgress.Add(item.Key, item.Value);
30+
}
31+
}
32+
33+
}
2334

24-
if (progress.Count != graph.VerticesCount)
35+
if (totalProgress.Count != graph.VerticesCount)
2536
{
2637
return new MColorResult<T, C>(false, null);
2738
}
2839

2940
var result = new Dictionary<C, List<T>>();
3041

31-
foreach (var vertex in progress)
42+
foreach (var vertex in totalProgress)
3243
{
3344
if (!result.ContainsKey(vertex.Value))
3445
{

tests/Advanced.Algorithms.Tests/Graph/Matching/BiPartiteMatching_Tests.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ public void MaxBiPartiteMatch_AdjacencyListGraph_Smoke_Test()
4242
Assert.AreEqual(result.Count, 4);
4343
}
4444

45+
/// <summary>
46+
/// Test Max BiParitite Edges using Ford-Fukerson algorithm
47+
/// </summary>
48+
[TestMethod]
49+
public void MaxBiPartiteMatch_AdjacencyListGraph_Accuracy_Test_1()
50+
{
51+
var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyList.Graph<char>();
52+
53+
graph.AddVertex('0');
54+
graph.AddVertex('1');
55+
graph.AddVertex('2');
56+
graph.AddVertex('3');
57+
58+
59+
graph.AddEdge('0', '2');
60+
graph.AddEdge('1', '3');
61+
62+
63+
var algorithm = new BiPartiteMatching<char>(new BiPartiteMatchOperators());
64+
65+
var result = algorithm.GetMaxBiPartiteMatching(graph);
66+
67+
Assert.AreEqual(result.Count, 2);
68+
}
69+
4570
[TestMethod]
4671
public void MaxBiPartiteMatch_AdjacencyMatrixGraph_Smoke_Test()
4772
{
@@ -74,6 +99,31 @@ public void MaxBiPartiteMatch_AdjacencyMatrixGraph_Smoke_Test()
7499

75100
Assert.AreEqual(result.Count, 4);
76101
}
102+
103+
/// <summary>
104+
/// Test Max BiParitite Edges using Ford-Fukerson algorithm
105+
/// </summary>
106+
[TestMethod]
107+
public void MaxBiPartiteMatch_AdjacencyMatrixGraph_Accuracy_Test_1()
108+
{
109+
var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix.Graph<char>();
110+
111+
graph.AddVertex('0');
112+
graph.AddVertex('1');
113+
graph.AddVertex('2');
114+
graph.AddVertex('3');
115+
116+
117+
graph.AddEdge('0', '2');
118+
graph.AddEdge('1', '3');
119+
120+
121+
var algorithm = new BiPartiteMatching<char>(new BiPartiteMatchOperators());
122+
123+
var result = algorithm.GetMaxBiPartiteMatching(graph);
124+
125+
Assert.AreEqual(result.Count, 2);
126+
}
77127
/// <summary>
78128
/// operators for generics
79129
/// implemented for int type for edge weights

0 commit comments

Comments
 (0)