bool SplitEquation( CoeffVec& cur, const SymbolicVal& cut, const BoundVec& bounds, BoundOp& boundop, CoeffVec& split) { int dim = cur.size()-1; SymbolicVal leftval = cur[dim]; // obtain the last coefficient, which is right side terms without using loop index variable if (leftval != 0) { CompareRel r1 = CompareVal(leftval,-cut, &boundop); CompareRel r2 = CompareVal(leftval,cut, &boundop); bool lt = ((r1 & REL_GT) && (r2 & REL_LT)) || ((r1 & REL_LT) && (r2 & REL_GT)); if (!lt) { // relation of r1 and r2 must be reversed pair, or error if (DebugDep()) std::cerr << "unable to split because " << leftval.toString() << " ? " << cut.toString() << std::endl; return false; } } bool succ = false; split.clear(); int j =0; for (; j < dim; ++j) { SymbolicVal left = cur[j] / cut; if (HasFraction(left)) split.push_back(0); else { split.push_back(left); succ = true; } } split.push_back(0); // right-hand side value if (succ) { SymbolicVal left = 0; for (j = 0; j < dim; ++j) { if (split[j]== 0) switch (CompareVal(cur[j],0,&boundop)) { case REL_LE: left = left + cur[j] * bounds[j].lb; break; case REL_GE: left = left + cur[j] * bounds[j].ub; break; default: break; } } if (j == dim && (left == 0 || (CompareVal(left,cut) & REL_LT))) { for (j = 0; j < dim; ++j) { if (split[j] != 0) cur[j] = 0; // clear some coefficency values } return true; } else if (DebugDep()) { if (j == dim) std::cerr << "unable to decide left " << left.toString() << " ? " << cut.toString() << std::endl; else std::cerr << "unable to decide cur[" << j << "] ? 0\n"; } } split.clear(); return false; }
SymbolicVal Min( const SymbolicVal &v1, const SymbolicVal &v2, MapObject<SymbolicVal, SymbolicBound>* f) { if (v1.IsNIL()) return v2; if (v2.IsNIL()) return v1; switch (CompareVal(v1,v2,f)) { case REL_NONE: case REL_UNKNOWN: case REL_NE: { SelectApplicator minOp(-1); return ApplyBinOP(minOp,v1,v2); } case REL_EQ: case REL_LT: case REL_LE: return v1; case REL_GT: case REL_GE: return v2; default: assert(0); } }
bool operator > (const SymbolicVal &v1, const SymbolicVal& v2) { return CompareVal(v1,v2) == REL_GT; }