Exemple #1
0
        static public void multiply(ref dense_matrix result, sparse_matrix left, dense_matrix right)
        {
            int right_height = right.rows, right_width = right.columns;

            if (left._width != right_height)
            {
                throw new ArgumentException("Operand size mismatch");
            }

            Dictionary <int, double> left_row_ref;

            double[] result_row_ref, right_row_ref;
            double   cur_element;

            result.clear(left._height, right_width);
            int left_height = left._height;

            Dictionary <int, double>[] left_contents = left._contents;
            for (int cur_row = 0; cur_row < left_height; ++cur_row)
            {
                left_row_ref   = left_contents[cur_row];
                result_row_ref = result[cur_row];
                foreach (KeyValuePair <int, double> cur_diagonal in left_row_ref)
                {
                    cur_element   = cur_diagonal.Value;
                    right_row_ref = right[cur_diagonal.Key];
                    for (int cur_column = 0; cur_column < right_width; ++cur_column)
                    {
                        result_row_ref[cur_column] += cur_element * right_row_ref[cur_column];
                    }
                }
            }
        }
Exemple #2
0
        static public void multiply(ref dense_matrix result, dense_matrix left, sparse_matrix right)
        {
            int left_height = left.rows, left_width = left.columns;

            if (left_width != right._height)
            {
                throw new ArgumentException("Operand size mismatch");
            }

            Dictionary <int, double> right_row_ref;

            double[] left_row_ref, result_row_ref;
            double   cur_element;

            result.clear(left_height, right._width);
            Dictionary <int, double>[] right_contents = right._contents;
            for (int cur_row = 0; cur_row < left_height; ++cur_row)
            {
                left_row_ref   = left[cur_row];
                result_row_ref = result[cur_row];
                for (int sum_index = 0; sum_index < left_width; ++sum_index)
                {
                    cur_element   = left_row_ref[sum_index];
                    right_row_ref = right_contents[sum_index];
                    foreach (KeyValuePair <int, double> cur_horizontal in right_row_ref)
                    {
                        result_row_ref[cur_horizontal.Key] += cur_element * cur_horizontal.Value;
                    }
                }
            }
        }
Exemple #3
0
        private void fill_matrices(int item_count)
        {
            int num_vars = item_count + 2;

            if (item_count != _last_item_count)
            {
                _vB = new int[num_vars];
                _vN = new int[item_count];
                _last_item_count = item_count;
            }

            int[] vB = _vB, vN = _vN;
            List <solver_entry> items = this.items;

            _E.set_to_identity(num_vars);
            _cB.clear(1, num_vars);
            _cN.clear(1, item_count);
            _B.set_to_identity(num_vars);
            _B_inv.clear(num_vars);
            _N.clear(num_vars, item_count);
            _b.clear(num_vars, 1);
            //_B_inv.set_to_identity(num_vars);
            _z.clear(1, num_vars);
            _z_c.clear(1, item_count);

            _result.clear(num_vars, 1);
            _entering_column.clear(num_vars, 1);
            _dividers.clear(num_vars, 1);

            sparse_row_ref B0_ref = _B[0], B1_ref = _B[1];
            int            cur_index;

            for (int cur_item = 0; cur_item < item_count; ++cur_item)
            {
                cur_index               = cur_item + 2;
                vB    [cur_index]       = cur_item;
                vN    [cur_item]        = cur_item + num_vars;
                B0_ref[cur_index]       = items[cur_item].x;
                B1_ref[cur_index]       = items[cur_item].y;
                _N[cur_index][cur_item] = 1.0;
                _b[cur_index][0]        = items[cur_item].max_value;
            }
            vB[0] = item_count;
            vB[1] = item_count + 1;
        }