Permalink
Browse files

Guarantee stops in cases where the problem is ill-posed.

  • Loading branch information...
1 parent 53573fa commit cf5a428d6180186c249231b622875bcb3b429a84 @jwills jwills committed Apr 11, 2012
@@ -38,7 +38,7 @@
*/
public class BipartiteMatchingVertex extends EdgeListVertex<Text, VertexState, IntWritable, AuctionMessage> {
- private static final BigDecimal REALLY_BIG_NUMBER = new BigDecimal(1000L * 1000L * 1000L * 1000L * 1000L);
+ private static final BigDecimal ONE_HUNDRED_BILLION_DOLLARS = new BigDecimal(100L * 1000L * 1000L * 1000L);
@Override
public void compute(Iterator<AuctionMessage> msgIterator) throws IOException {
@@ -65,16 +65,25 @@ public void compute(Iterator<AuctionMessage> msgIterator) throws IOException {
// Compute the value I assign to each object, based on its current price.
List<AuctionMessage> values = Lists.newArrayList();
for (Text vertexId : this) {
- BigDecimal value = new BigDecimal(getEdgeValue(vertexId).get()).subtract(vpd.getPrice(vertexId));
- values.add(new AuctionMessage(vertexId, value));
+ BigDecimal price = vpd.getPrice(vertexId);
+ if (price.compareTo(ONE_HUNDRED_BILLION_DOLLARS) < 0) {
+ BigDecimal value = new BigDecimal(getEdgeValue(vertexId).get()).subtract(price);
+ values.add(new AuctionMessage(vertexId, value));
+ }
+ }
+
+ if (values.isEmpty()) {
+ // Nothing to bid on, problem is ill-posed. :(
+ voteToHalt();
+ return;
}
// Compare the value I get from the object I own now (if any) to the highest-value
// object that I am interested in.
Text currentMatchId = state.getMatchId();
AuctionMessage target = getMax(values, currentMatchId);
if (currentMatchId == null || !currentMatchId.equals(target.getVertexId())) {
- BigDecimal bid = REALLY_BIG_NUMBER; // Infinite bid, if it's the only match for me.
+ BigDecimal bid = ONE_HUNDRED_BILLION_DOLLARS; // Infinite bid, if it's the only match for me.
if (values.size() > 1) {
// Otherwise, compute the bid relative to the value I get from the first runner-up.
AuctionMessage runnerUp = values.get(1);
@@ -15,6 +15,7 @@
package com.cloudera.science.matching.graph;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.Map;
@@ -207,6 +208,20 @@ public void testSingleBidder() throws Exception {
}
@Test
+ public void testDisaster() throws Exception {
+ VertexData d1 = new VertexData("1", true, ImmutableMap.of("3", 3));
+ VertexData d2 = new VertexData("2", true, ImmutableMap.of("3", 1));
+ VertexData d3 = new VertexData("3", false, ImmutableMap.of("1", -1, "2", -1));
+
+ String[] data = new String[] { mapper.writeValueAsString(d1),
+ mapper.writeValueAsString(d2),
+ mapper.writeValueAsString(d3),
+ };
+ Map<String, VertexData> out = run(data);
+ assertTrue(out.get("1").getMatchId().equals("") || out.get("2").getMatchId().equals(""));
+ }
+
+ @Test
public void testMarriageTheorem() throws Exception {
VertexData beauty = new VertexData("beauty", true,
ImmutableMap.of("beast", 9, "donald", 7, "mickey", 7, "popeye", 7));

0 comments on commit cf5a428

Please sign in to comment.