Ejemplo n.º 1
0
            /**
             * 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);
                }
            }
Ejemplo n.º 2
0
 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());
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
            /**
             * 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;
                }
            }
Ejemplo n.º 5
0
 public Constellation(Dibit leftDibit, Dibit rightDibit, int value)
 {
     mLeftDibit  = leftDibit;
     mRightDibit = rightDibit;
     mValue      = value;
 }
Ejemplo n.º 6
0
 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());
 }
Ejemplo n.º 7
0
 public bool startsWith(Dibit dibit)
 {
     return(mConstellation.getLeft() == dibit);
 }
Ejemplo n.º 8
0
            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;
            }
Ejemplo n.º 9
0
 public Constellation(Dibit leftDibit, Dibit rightDibit, int value)
 {
     mLeftDibit = leftDibit;
     mRightDibit = rightDibit;
     mValue = value;
 }
Ejemplo n.º 10
0
            /**
             * 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;
                }
            }
Ejemplo n.º 11
0
            /**
             * 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;
			}
		}
Ejemplo n.º 12
0
 public bool startsWith(Dibit dibit)
 {
     return mConstellation.getLeft() == dibit;
 }