X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fmatching%2FVotingMatchingStrategy.java;h=d23cf332abd091d4fccded2434eb20e0fc642583;hb=refs%2Fchanges%2F38%2F238%2F2;hp=2220b6e9d3e540c6f5dca5e8453ff4ea9c9314d4;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/matching/VotingMatchingStrategy.java b/bundles/org.simantics.graph/src/org/simantics/graph/matching/VotingMatchingStrategy.java index 2220b6e9d..d23cf332a 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/matching/VotingMatchingStrategy.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/matching/VotingMatchingStrategy.java @@ -1,122 +1,122 @@ -package org.simantics.graph.matching; - -import gnu.trove.list.array.TIntArrayList; -import gnu.trove.map.hash.TIntDoubleHashMap; -import gnu.trove.map.hash.TIntIntHashMap; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.procedure.TIntDoubleProcedure; -import gnu.trove.procedure.TIntObjectProcedure; - -public enum VotingMatchingStrategy implements GraphMatchingStrategy { - INSTANCE; - - public static void vote( - final TIntDoubleHashMap[] voting, - int[] aToB, - int[] bToA, - Stat[] aStat, - Stat[] bStat, - final String[] bNames) { - final TIntObjectHashMap aMap = - new TIntObjectHashMap(); - for(Stat stat : aStat) { - int mp = aToB[stat.p]; - if(mp >= 0 && aToB[stat.o] < 0) { - TIntArrayList l = aMap.get(mp); - if(l == null) { - l = new TIntArrayList(2); - aMap.put(mp, l); - } - l.add(stat.o); - } - } - TIntObjectHashMap bMap = - new TIntObjectHashMap(); - for(Stat stat : bStat) { - int p = stat.p; - int o = stat.o; - if(bToA[p] >= 0 && bToA[o] < 0) { - TIntArrayList l = bMap.get(p); - if(l == null) { - l = new TIntArrayList(2); - bMap.put(p, l); - } - l.add(o); - } - } - /*System.out.println("---------------------------------------"); - aMap.forEachEntry(new TIntObjectProcedure() { - @Override - public boolean execute(int a, TIntArrayList b) { - System.out.println("a " + bNames[a] + " -> " + b); - return true; - } - }); - bMap.forEachEntry(new TIntObjectProcedure() { - @Override - public boolean execute(int a, TIntArrayList b) { - System.out.println("b " + bNames[a] + " -> " + b); - return true; - } - });*/ - bMap.forEachEntry(new TIntObjectProcedure() { - @Override - public boolean execute(int p, TIntArrayList bos) { - TIntArrayList aos = aMap.get(p); - if(aos != null && aos.size() <= 4 && bos.size() <= 4) { - final double weight = 1.0 / bos.size(); - for(int i=0;i= 0 && ms < bStatements.length) - vote(voting, aToB, bToA, aStatements[s], bStatements[ms], matching.bGraph.names); - } - - for(int a=0;a bestWeight && bToA[b] < 0) { - bestWeight = weight; - best[0] = b; - } - return true; - } - }); - if(best[0] >= 0) { - int b = best[0]; - matching.map(a, b); - if(aInv.contains(a) && bInv.contains(b) && aInv.get(a) != a) - matching.map(aInv.get(a), bInv.get(b)); - } - } - } - } - -} +package org.simantics.graph.matching; + +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.hash.TIntDoubleHashMap; +import gnu.trove.map.hash.TIntIntHashMap; +import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.procedure.TIntDoubleProcedure; +import gnu.trove.procedure.TIntObjectProcedure; + +public enum VotingMatchingStrategy implements GraphMatchingStrategy { + INSTANCE; + + public static void vote( + final TIntDoubleHashMap[] voting, + int[] aToB, + int[] bToA, + Stat[] aStat, + Stat[] bStat, + final String[] bNames) { + final TIntObjectHashMap aMap = + new TIntObjectHashMap(); + for(Stat stat : aStat) { + int mp = aToB[stat.p]; + if(mp >= 0 && aToB[stat.o] < 0) { + TIntArrayList l = aMap.get(mp); + if(l == null) { + l = new TIntArrayList(2); + aMap.put(mp, l); + } + l.add(stat.o); + } + } + TIntObjectHashMap bMap = + new TIntObjectHashMap(); + for(Stat stat : bStat) { + int p = stat.p; + int o = stat.o; + if(bToA[p] >= 0 && bToA[o] < 0) { + TIntArrayList l = bMap.get(p); + if(l == null) { + l = new TIntArrayList(2); + bMap.put(p, l); + } + l.add(o); + } + } + /*System.out.println("---------------------------------------"); + aMap.forEachEntry(new TIntObjectProcedure() { + @Override + public boolean execute(int a, TIntArrayList b) { + System.out.println("a " + bNames[a] + " -> " + b); + return true; + } + }); + bMap.forEachEntry(new TIntObjectProcedure() { + @Override + public boolean execute(int a, TIntArrayList b) { + System.out.println("b " + bNames[a] + " -> " + b); + return true; + } + });*/ + bMap.forEachEntry(new TIntObjectProcedure() { + @Override + public boolean execute(int p, TIntArrayList bos) { + TIntArrayList aos = aMap.get(p); + if(aos != null && aos.size() <= 4 && bos.size() <= 4) { + final double weight = 1.0 / bos.size(); + for(int i=0;i= 0 && ms < bStatements.length) + vote(voting, aToB, bToA, aStatements[s], bStatements[ms], matching.bGraph.names); + } + + for(int a=0;a bestWeight && bToA[b] < 0) { + bestWeight = weight; + best[0] = b; + } + return true; + } + }); + if(best[0] >= 0) { + int b = best[0]; + matching.map(a, b); + if(aInv.contains(a) && bInv.contains(b) && aInv.get(a) != a) + matching.map(aInv.get(a), bInv.get(b)); + } + } + } + } + +}