Exemplo n.º 1
0
        // count the number of difference of matches
        private static int matchDiff(ref Equation root, ref Equation result)
        {
            // Assert: root.optr == result.optr
            Debug.Assert(root.ssds.Count == result.ssds.Count);
            int count = 0;

            for (int i = 0; i < root.ssds.Count; i++)
            {
                count += SSD.diff(root.ssds[i], result.ssds[i]);
            }
            return(count);
        }
Exemplo n.º 2
0
        // display operator
        public void display(char c)
        {
            // opnd
            if (c - '0' >= 0 && c - '0' <= 9)
            {
                displayDigit(SSD.digit2binary(c - '0'));
                return;
            }
            // optr
            Clear();
            switch (c)
            {
            case '+':
            {
                add2.Visible = true;
                G.Visible    = true;
                break;
            }

            case '-':
            {
                G.Visible = true;
                break;
            }

            case '*':
            {
                mul.Visible = true;
                break;
            }

            case '/':
            {
                divide.Visible = true;
                break;
            }

            case '=':
            {
                eq1.Visible = true;
                eq2.Visible = true;
                break;
            }

            default: return;
            }
        }
Exemplo n.º 3
0
        // display digit
        public void displayDigit(byte bcd)
        {
            int d = SSD.binary2digit(bcd);

            Debug.Assert(d >= 0 && d <= 9);
            for (int i = 0; i < 7; i++)
            {
                if (checkOnebit(bcd, i))
                {
                    turnUp(i);
                }
                else
                {
                    turnDown(i);
                }
            }
        }
Exemplo n.º 4
0
        // expand One Possible random equation List, define its ancestors, attribute, ssds and optr
        private static void expand(Equation father, out List <Equation> children)
        {
            children = new List <Equation>();

            for (int i = 0; i < father.ssds.Count; i++)
            {
                SSD cur_ssd = father.ssds[i];

                // expand curent ssd
                var cur_ssd_list = cur_ssd.expand(father.Attribute);

                for (int j = 0; j < cur_ssd_list.Count; j++)
                {
                    Equation son = new Equation();
                    // ssds
                    son.ssds = new List <SSD>(father.ssds);
                    // change the i'th ssd to a new one.
                    son.ssds[i] = cur_ssd_list[j];

                    // optr
                    son.optr = new Dictionary <int, char>(father.optr);
                    // attribute
                    son.Attribute = inverse(father.Attribute);
                    // ancestors
                    son.anncestors = new List <Equation>(father.anncestors);
                    son.anncestors.Insert(0, father);

                    //* Cut branch Operation*/
                    // if same as grandpa: (means it goes back! ) then should be cut!
                    if (sameAsGrandpa(son, i))
                    {
                        continue;
                    }
                    // if the son's depth = 3, and son's ssds[i] == grandpa's ssds[i], then cut!
                    if (father.get_depth() == 2 && son.ssds[i] == father.anncestors[0].ssds[i])
                    {
                        continue;
                    }

                    children.Add(son);
                }
            }
        }
Exemplo n.º 5
0
 public static int diff(SSD left, SSD right)
 {
     return(countOnes(Convert.ToByte(left.BCD ^ right.BCD)));
 }
Exemplo n.º 6
0
 public bool Equals(SSD rt)
 {
     return(BCD == rt.BCD);
 }