// A,u,v,B,_,C,w,D,p
// A,_,_,B,x,C,y,D,_
int sizeX = 8;
int sizeY = 6;
BipartiteCavityMatcher matcher = new OrderedBipartiteCavityMatcher(
sizeX, sizeY);
for (int y = 0; y < sizeY; ++y) {
matcher.setDelCostY(y, 2);
}
for (int x = 0; x < sizeX; ++x) {
matcher.setDelCostX(x, 2);
for (int y = 0; y < sizeY; ++y) {
matcher.setMatchCost(x, y, 5);
}
}
matcher.setMatchCost(0, 4, -1);
matcher.setMatchCost(3, 5, -1);
matcher.setMatchCost(4, 1, -1);
matcher.setMatchCost(6, 3, -1);
matcher.setMatchCost(5, 2, 3);
Assert.assertEquals("Cavity matching answer is wrong", 13,
matcher.minCostCavityMatching(7, 5), 0.001);
TIntArrayList[] matching = matcher.getCavityMatching(7, 5);
IntPairComparator comp = new IntPairComparator();
ArrayList<IntPair> ans = new ArrayList<IntPair>();
ArrayList<IntPair> exp = new ArrayList<IntPair>();
ans.add(new IntPair(6, 3));
ans.add(new IntPair(5, 2));
ans.add(new IntPair(4, 1));
for (int i = 0; i < matching[0].size(); ++i) {
exp.add(new IntPair(matching[0].get(i), matching[1].get(i)));
}
Collections.sort(ans, comp);
Collections.sort(exp, comp);
isSame(ans, exp);
Assert.assertEquals("Minimum matching answer is wrong", 7,
matcher.minCostMatching(), 0.001);
ans = new ArrayList<IntPair>();
exp = new ArrayList<IntPair>();
matching = matcher.getCurrMatching();
ans.add(new IntPair(3, 5));
ans.add(new IntPair(0, 4));
ans.add(new IntPair(6, 3));
ans.add(new IntPair(5, 2));