Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            int size = 5;

            double[] distortionto1Probability       = { 0.1, 0.0, 0.3, 0.3, 0.1, 0.1, 0.0, 0.3, 0.3, 0.1 };
            double[] distortionto0Probability       = { 0.3, 0.1, 0.2, 0.1, 0.2, 0.3, 0.1, 0.2, 0.1, 0.2 };
            double[] distortiontoInverseProbability = { 0.3, 0.5, 0.0, 0.2, 0.1, 0.3, 0.5, 0.0, 0.2, 0.1 };
            AdderTruthTableBuilder attBuilder       = new AdderTruthTableBuilder(size);

            attBuilder.SetDistortionProbabities(distortionto0Probability,
                                                distortionto1Probability, distortiontoInverseProbability);
            AdderTruthTable tt             = attBuilder.BuildDistortedTable();
            TruthTableView  truthTableView = new TruthTableView(tt);
            DataView        v = truthTableView.GetViewWithProbabilities();

            tableGridView.DataSource = v;
            foreach (DataGridViewRow row in tableGridView.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }
                row.HeaderCell.Value = String.Format("{0}", row.Index + 1);
            }
            tableGridView.AutoResizeRowHeadersWidth(
                DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
        }
Example #2
0
 public BitAdderTruthTable(int bitIndex, AdderTruthTable table)
     : base(table)
 {
     _table = table;
     this._outputNumberOfDigits = 1;
     _bitIndex = bitIndex;
 }
Example #3
0
        public AdderTruthTable BuildTable()
        {   // TODO: refactor BuildTable mathods avoid code duplication
            if ((_inputDigits < 1) || (_resultDigits < 1))
            {
                throw new System.Exception("Wrong Table Builder Arguments");
            }
            AdderTruthTable table = new AdderTruthTable(_inputDigits, _resultDigits, _inputDigits << 1);

            return(CalculateFunctionValues(table, null));
        }
Example #4
0
        public AdderTruthTable BuildTable(bool[] fixedValues)
        {
            if ((_inputDigits < 1) || (_resultDigits < 1))
            {
                throw new System.Exception("Wrong Table Builder Arguments");
            }
            AdderTruthTable table = new AdderTruthTable(_inputDigits, _resultDigits, (_inputDigits << 1)
                                                        - fixedValues.Length);

            return(CalculateFunctionValues(table, fixedValues));
        }
Example #5
0
        public AdderTruthTable BuildDistortedTable()
        {
            if ((_distortionToInverseProbability == null) ||
                (_distortionToOneProbability == null) ||
                (_distortionToZeroProbability == null))
            {
                throw new System.Exception("Empty distirtion probabilities in TableBuilder");
            }
            AdderTruthTable table = new AdderTruthTable(_inputDigits, _resultDigits, _inputDigits << 1);

            return(CalculateDistotedFunctionValues(table));
        }
Example #6
0
        private void AddOperands(AdderTruthTable table, bool[] op1, bool[] op2, int i)
        {
            bool carryFlag = false;

            for (int j = 0; j < _inputDigits; j++)
            {
                // data saves in reverse oder for good view in table
                table.functionValue[i][_resultDigits - j - 1] = op1[j] ^ op2[j] ^ carryFlag;
                carryFlag = op1[j] & op2[j] | (op1[j] ^ op2[j]) & carryFlag;
            }
            table.functionValue[i][0] = carryFlag;
        }
Example #7
0
 private AdderTruthTable CalculateDistotedFunctionValues(AdderTruthTable table)
 {
     bool[] op1 = new bool[_inputDigits];
     bool[] op2 = new bool[_inputDigits];
     // for every line in truth table
     for (int i = 0; i < table.functionValue.Count; i++)
     {
         // calculate sum result
         SetOperand(op1, i, op1.Length);
         SetOperand(op2, i);
         // attach incoming distortion
         DoOperandsDistortion(op1, op2);
         AddOperands(table, op1, op2, i);
     }
     return(table);
 }
Example #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            int size = 5;
            AdderTruthTableBuilder attBuilder     = new AdderTruthTableBuilder(size);
            AdderTruthTable        tt             = attBuilder.BuildTable();
            TruthTableView         truthTableView = new TruthTableView(tt);
            DataView v = truthTableView.GetView();

            tableGridView.DataSource = v;
            foreach (DataGridViewRow row in tableGridView.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }
                row.HeaderCell.Value = String.Format("{0}", row.Index + 1);
            }
            tableGridView.AutoResizeRowHeadersWidth(
                DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
        }
Example #9
0
        static public int[] ConvertBoolArrToIntTable(AdderTruthTable table)
        {
            int[] intTable = new int[table.functionValue.Count];
            int   index    = 0;

            foreach (bool[] bits in table.functionValue)
            {
                int r = 0;
                for (int i = 0; i < bits.Length; i++)
                {
                    if (bits[i])
                    {
                        r |= 1 << (bits.Length - i);
                    }
                }
                intTable[index] = r;
                ++index;
            }
            return(intTable);
        }
Example #10
0
 private AdderTruthTable CalculateFunctionValues(AdderTruthTable table, bool[] fixedValues)
 {
     bool[] op1 = new bool[_inputDigits];
     bool[] op2 = new bool[_inputDigits];
     // for every line in truth table
     for (int i = 0; i < table.functionValue.Count; i++)
     {
         // calculate sum result
         if (fixedValues == null)
         {
             SetOperand(op1, i, op1.Length);
         }
         else
         {
             SetOperand(op1, i, op1.Length, fixedValues);
         }
         SetOperand(op2, i);
         AddOperands(table, op1, op2, i);
     }
     return(table);
 }
 public TruthTableView(AdderTruthTable truthTable)
 {
     _dataTable  = new DataTable();
     _truthTable = truthTable;
 }
Example #12
0
 public AdderTruthTable(AdderTruthTable table)
     : base(table.InputNumberOfDigits, table.OutputNumberOfDigits)
 {
     functionValue = table.functionValue;
 }