public override void AddToConstraintSystem(ArrayList /*!*/ /*LinearConstraint*/ clist) { //Contract.Requires(clist != null); // make an unsatisfiable constraint LinearConstraint lc = new LinearConstraint(LinearConstraint.ConstraintRelation.EQ); lc.rhs = Rational.FromInt(1); clist.Add(lc); }
/// <summary> /// Applies the Pivot Operation on row "r" and column "c". /// /// This method can be called when !constructionDone, that is, at a time when not all basis /// columns have been set up (indicated by -1 in basisColumns). This method helps set up /// those basis columns. /// /// The return value is an undo record that can be used with UnPivot. /// </summary> /// <param name="r"></param> /// <param name="c"></param> public Rational[] /*!*/ Pivot(int r, int c) { Contract.Ensures(Contract.Result <Rational[]>() != null); Contract.Assert(0 <= r && r < rows); Contract.Assert(0 <= c && c < columns - 1); Contract.Assert(m[r, c].IsNonZero); Contract.Assert(inBasis[c] == -1); // follows from invariant and m[r,c] != 0 Contract.Assert(basisColumns[r] != rhsColumn); // follows from invariant and m[r,c] != 0 Rational[] undo = new Rational[rows + 1]; for (int i = 0; i < rows; i++) { undo[i] = m[i, c]; } // scale the pivot row Rational q = m[r, c]; if (q != Rational.ONE) { for (int j = 0; j < columns; j++) { m[r, j] /= q; } } // subtract a multiple of the pivot row from all other rows for (int i = 0; i < rows; i++) { if (i != r) { q = m[i, c]; if (q.IsNonZero) { for (int j = 0; j < columns; j++) { m[i, j] -= q * m[r, j]; } } } } // update basis information int prevCol = basisColumns[r]; undo[rows] = Rational.FromInt(prevCol); basisColumns[r] = c; if (prevCol != -1) { inBasis[prevCol] = -1; } inBasis[c] = r; return(undo); }