Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Oct 10, 2020
2 parents 9514748 + e4b9fa2 commit 7185d3c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/Advanced.Algorithms/Geometry/BentleyOttmann.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BentleyOttmann
{
private readonly PointComparer pointComparer;

private HashSet<Event> verticalHorizontalLines;
private HashSet<Event> verticalAndHorizontalLines;
private HashSet<Event> otherLines;

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

verticalHorizontalLines = new HashSet<Event>();
verticalAndHorizontalLines = new HashSet<Event>();
otherLines = new HashSet<Event>();

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

//special case
if (verticalHorizontalLines.Count > 0)
if (verticalAndHorizontalLines.Count > 0)
{
foreach (var line in verticalHorizontalLines)
foreach (var line in verticalAndHorizontalLines)
{
var intersection = findIntersection(currentEvent, line);
recordIntersection(currentEvent, line, intersection);
Expand All @@ -94,7 +94,7 @@ public Dictionary<Point, List<Line>> FindIntersections(IEnumerable<Line> lineSeg
//special case
if (currentEvent.Segment.IsVertical || currentEvent.Segment.IsHorizontal)
{
verticalHorizontalLines.Add(currentEvent);
verticalAndHorizontalLines.Add(currentEvent);

foreach (var line in otherLines)
{
Expand Down Expand Up @@ -129,7 +129,7 @@ public Dictionary<Point, List<Line>> FindIntersections(IEnumerable<Line> lineSeg
//special case
if (currentEvent.Segment.IsVertical || currentEvent.Segment.IsHorizontal)
{
verticalHorizontalLines.Remove(currentEvent);
verticalAndHorizontalLines.Remove(currentEvent);
break;
}

Expand Down
25 changes: 18 additions & 7 deletions src/Advanced.Algorithms/Graph/Coloring/MColorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,32 @@ public class MColorer<T, C>
/// </summary>
public MColorResult<T, C> Color(IGraph<T> graph, C[] colors)
{
var totalProgress = new Dictionary<IGraphVertex<T>, C>();

var first = graph.ReferenceVertex;

var progress = canColor(first, colors,
new Dictionary<IGraphVertex<T>, C>(),
new HashSet<IGraphVertex<T>>());
foreach (var vertex in graph.VerticesAsEnumberable)
{
var progress = canColor(vertex, colors,
new Dictionary<IGraphVertex<T>, C>(),
new HashSet<IGraphVertex<T>>());

foreach(var item in progress)
{
if (!totalProgress.ContainsKey(item.Key))
{
totalProgress.Add(item.Key, item.Value);
}
}

}

if (progress.Count != graph.VerticesCount)
if (totalProgress.Count != graph.VerticesCount)
{
return new MColorResult<T, C>(false, null);
}

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

foreach (var vertex in progress)
foreach (var vertex in totalProgress)
{
if (!result.ContainsKey(vertex.Value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ public void MaxBiPartiteMatch_AdjacencyListGraph_Smoke_Test()
Assert.AreEqual(result.Count, 4);
}

/// <summary>
/// Test Max BiParitite Edges using Ford-Fukerson algorithm
/// </summary>
[TestMethod]
public void MaxBiPartiteMatch_AdjacencyListGraph_Accuracy_Test_1()
{
var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyList.Graph<char>();

graph.AddVertex('0');
graph.AddVertex('1');
graph.AddVertex('2');
graph.AddVertex('3');


graph.AddEdge('0', '2');
graph.AddEdge('1', '3');


var algorithm = new BiPartiteMatching<char>(new BiPartiteMatchOperators());

var result = algorithm.GetMaxBiPartiteMatching(graph);

Assert.AreEqual(result.Count, 2);
}

[TestMethod]
public void MaxBiPartiteMatch_AdjacencyMatrixGraph_Smoke_Test()
{
Expand Down Expand Up @@ -74,6 +99,31 @@ public void MaxBiPartiteMatch_AdjacencyMatrixGraph_Smoke_Test()

Assert.AreEqual(result.Count, 4);
}

/// <summary>
/// Test Max BiParitite Edges using Ford-Fukerson algorithm
/// </summary>
[TestMethod]
public void MaxBiPartiteMatch_AdjacencyMatrixGraph_Accuracy_Test_1()
{
var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix.Graph<char>();

graph.AddVertex('0');
graph.AddVertex('1');
graph.AddVertex('2');
graph.AddVertex('3');


graph.AddEdge('0', '2');
graph.AddEdge('1', '3');


var algorithm = new BiPartiteMatching<char>(new BiPartiteMatchOperators());

var result = algorithm.GetMaxBiPartiteMatching(graph);

Assert.AreEqual(result.Count, 2);
}
/// <summary>
/// operators for generics
/// implemented for int type for edge weights
Expand Down

0 comments on commit 7185d3c

Please sign in to comment.