/** * Calculates the cost (hamming distance) of using the argument as the * left side dibit for the current node, and recursively finding the * cheapest corresponding right dibit. * * @param leftTest * @return */ public int costTo(Dibit leftTest) { if (isCurrentConnectionCorrect()) { Constellation c = Constellation. fromDibits(leftTest, mConstellation.getRight()); return(mConstellation.costTo(c)); } else { int cheapestCost = 100; //arbitrary foreach (Dibit d in Dibit.values()) { Constellation c = Constellation.fromDibits(leftTest, d); int cost = mConnectedNode.costTo(d) + mConstellation.costTo(c); if (cost < cheapestCost) { cheapestCost = cost; } } return(cheapestCost); } }
public static bool Equals(Dibit first, Dibit second) { if (first == null || second == null) { return(false); } else { return(first.firstBit() == second.firstBit() && first.secondBit() == second.secondBit()); } }
public static Constellation fromDibits(Dibit left, Dibit right) { if (Dibit.Equals(left, Dibit.D0)) { } else if (Dibit.Equals(left, Dibit.D1)) { } else if (Dibit.Equals(left, Dibit.D2)) { } else { // } return(null); }
/** * Executes a correction down the line of connected nodes. Only nodes * with the mCorrect flag set to false will be corrected. * * Note: Assumes that the starting node's value is 0. Initiate the * corrective sequence by invoking this method with Dibit.D0 on the * first node. * * @param dibit to use for the left side. */ public void correctTo(Dibit dibit) { if (mCorrect && mConstellation.getLeft() == dibit) { return; } if (isCurrentConnectionCorrect()) { mConstellation = Constellation. fromDibits(dibit, mConstellation.getRight()); mCorrect = true; if (mConnectedNode != null) { mConnectedNode.correctTo(mConstellation.getRight()); } } else { Constellation cheapest = mConstellation; int cost = 100; //arbitrary foreach (Dibit d in Dibit.values()) { Constellation test = Constellation.fromDibits(dibit, d); int testCost = mConstellation.costTo(test) + mConnectedNode.costTo(d); if (testCost < cost) { cost = testCost; cheapest = test; } } mConstellation = cheapest; mConnectedNode.correctTo(mConstellation.getRight()); mCorrect = true; } }
public Constellation(Dibit leftDibit, Dibit rightDibit, int value) { mLeftDibit = leftDibit; mRightDibit = rightDibit; mValue = value; }
public static bool Equals(Dibit first, Dibit second) { if (first == null || second == null) return false; else return (first.firstBit() == second.firstBit() && first.secondBit() == second.secondBit()); }
public bool startsWith(Dibit dibit) { return(mConstellation.getLeft() == dibit); }
public static Constellation fromDibits(Dibit left, Dibit right) { if (Dibit.Equals(left, Dibit.D0)) { } else if (Dibit.Equals(left, Dibit.D1)) { } else if (Dibit.Equals(left, Dibit.D2)) { } else { // } return null; }
/** * Calculates the cost (hamming distance) of using the argument as the * left side dibit for the current node, and recursively finding the * cheapest corresponding right dibit. * * @param leftTest * @return */ public int costTo(Dibit leftTest) { if (isCurrentConnectionCorrect()) { Constellation c = Constellation. fromDibits(leftTest, mConstellation.getRight()); return mConstellation.costTo(c); } else { int cheapestCost = 100; //arbitrary foreach (Dibit d in Dibit.values()) { Constellation c = Constellation.fromDibits(leftTest, d); int cost = mConnectedNode.costTo(d) + mConstellation.costTo(c); if (cost < cheapestCost) { cheapestCost = cost; } } return cheapestCost; } }
/** * Executes a correction down the line of connected nodes. Only nodes * with the mCorrect flag set to false will be corrected. * * Note: Assumes that the starting node's value is 0. Initiate the * corrective sequence by invoking this method with Dibit.D0 on the * first node. * * @param dibit to use for the left side. */ public void correctTo(Dibit dibit) { if( mCorrect && mConstellation.getLeft() == dibit ) { return; } if( isCurrentConnectionCorrect() ) { mConstellation = Constellation. fromDibits( dibit, mConstellation.getRight() ); mCorrect = true; if( mConnectedNode != null ) { mConnectedNode.correctTo( mConstellation.getRight() ); } } else { Constellation cheapest = mConstellation; int cost = 100; //arbitrary foreach( Dibit d in Dibit.values() ) { Constellation test = Constellation.fromDibits( dibit, d ); int testCost = mConstellation.costTo( test ) + mConnectedNode.costTo( d ); if( testCost < cost ) { cost = testCost; cheapest = test; } } mConstellation = cheapest; mConnectedNode.correctTo( mConstellation.getRight() ); mCorrect = true; } }
public bool startsWith(Dibit dibit) { return mConstellation.getLeft() == dibit; }