public static bool Satisfiable(LPSConstraint ct, Vector<double> image_plus_eps) { // Native inner product more efficient double lhs = image_plus_eps * ct.Term.GetCoefficients(); // ct.Term.GetCoefficients().SubVector(0, image.Count); double rhs = 0.0; bool sat = false; rhs = -ct.Term.Intercept; switch (ct.Inequality) { case InequalityType.EQ: sat = (lhs == rhs); break; case InequalityType.GE: sat = (lhs >= rhs); break; case InequalityType.GT: sat = (lhs > rhs); break; case InequalityType.LE: sat = (lhs <= rhs); break; case InequalityType.LT: sat = (lhs < rhs); break; } return sat; }
public void AddConstraint(LPSConstraint ct) { int ctid = ct_cnt; solver_.AddRow("constraint" + ct_cnt, out ctid); Vector <double> coefficients = ct.Term.GetCoefficients(); int totalvars = LPSTerm.TotalVarCount(); for (int j = 0; j < totalvars; j++) { // Due to the way MSF works, if we are adding a 0 coefficient // this amounts to actually removing it. However, the coefficient // is not there to start with, hence let's not add it, at all! if (coefficients[j] != 0) { solver_.SetCoefficient(ctid, vars_[j], coefficients[j]); } } switch (ct.Inequality) { case InequalityType.LT: solver_.SetUpperBound(ctid, -ct.Term.Intercept); // - RobustnessOptions.StrictInequalityLambda * Math.Abs(ct.Term.Intercept)); break; case InequalityType.LE: solver_.SetUpperBound(ctid, -ct.Term.Intercept); break; case InequalityType.GT: solver_.SetLowerBound(ctid, -ct.Term.Intercept); // + RobustnessOptions.StrictInequalityLambda * Math.Abs(ct.Term.Intercept)); break; case InequalityType.GE: solver_.SetLowerBound(ctid, -ct.Term.Intercept); break; case InequalityType.EQ: // solver_.SetValue(ctid, -ct.Term.Intercept); WRONG solver_.SetBounds(ctid, -ct.Term.Intercept, -ct.Term.Intercept); break; default: break; } ct_cnt++; }