private static NodePairings GetPairings(List <LabeledVertex> sourceGraphLabeled, List <LabeledVertex> imageGraphLabeled) { NodePairings nodePairings = new NodePairings(sourceGraph: sourceGraphLabeled, imageGraph: imageGraphLabeled); Random rnd = new Random(); Dictionary <Code[], IEnumerable <LabeledVertex> > sourceGraphGrouped; Dictionary <Code[], IEnumerable <LabeledVertex> > imageGraphGrouped; GetGrouped(sourceGraphLabeled: sourceGraphLabeled, imageGraphLabeled: imageGraphLabeled, sourceGraphGrouped: out sourceGraphGrouped, imageGraphGrouped: out imageGraphGrouped); //Parallel.ForEach(sourceGraphGrouped.Keys, (codeGroup) => foreach (var codeGroup in sourceGraphGrouped.Keys) { //not gonna lock for now foreach (var sourceGraphVertex in sourceGraphGrouped[codeGroup]) { VertexMatch winningPair; if (!imageGraphGrouped.ContainsKey(codeGroup)) { winningPair = null; } //Parallel.ForEach(imageGraphGrouped[codeGroup].OrderBy(x => rnd.Next()).ToList(), (imageGraphCandidate) => else { var vertexPossiblePairings = new ConcurrentBag <VertexMatch>(); foreach (var imageGraphCandidate in imageGraphGrouped[codeGroup].OrderBy(x => rnd.Next()).ToList()) { vertexPossiblePairings.Add(new VertexMatch() { SourceGraphVertex = sourceGraphVertex, ImageGraphVertex = imageGraphCandidate, Score = VertexScorer.GetScore(sourceGraphVertex, imageGraphCandidate, nodePairings) }); } winningPair = vertexPossiblePairings.Where(x => x.Score > 0).OrderByDescending(x => x.Score).ThenBy(x => rnd.Next()).FirstOrDefault(); } //}); if (winningPair != null) { lock (nodePairings.Pairings) { winningPair.NormalizedScore = winningPair.Score / VertexScorer.GetSelfScore(winningPair.SourceGraphVertex); nodePairings.Pairings[winningPair.ImageGraphVertex].Add(winningPair); nodePairings.TotalScore += winningPair.Score; } } } } // }); return(nodePairings); }
public static NodePairings GetGraphSelfScore(List <LabeledVertex> labeledGraph) { NodePairings nodePairings = new NodePairings(imageGraph: labeledGraph, sourceGraph: labeledGraph); foreach (var node in labeledGraph) { double score = VertexScorer.GetSelfScore(node); nodePairings.Pairings[node].Add(new VertexMatch() { SourceGraphVertex = node, ImageGraphVertex = node, Score = score, NormalizedScore = 1 }); nodePairings.TotalScore += score; } return(nodePairings); }