void unitTester() {
	testParensConverter(); 
	testConstraints();
	testPatternPrevention();
	//testNSTheta();
}
Example #2
0
void
RangeConvex::simplify() {

  if(sign_ == zERO) {
    simplify0();	// treat zERO convexes separately
    return;
  }

  size_t i,j;
  size_t clen;
  bool redundancy = true;

  while(redundancy) {
    redundancy = false;
    clen = constraints_.size();

    for(i = 0; i < clen; i++) {
      for(j = 0; j < i; j++) {
	int test;

      // don't bother with two zero constraints
      if( constraints_[i].sign_ == zERO && constraints_[j].sign_ == zERO)
		continue;

      // both pos or zero
      if( ( constraints_[i].sign_ == pOS || constraints_[i].sign_ == zERO ) &&
	  ( constraints_[j].sign_ == pOS || constraints_[j].sign_ == zERO ) ) {
		if ( (test = testConstraints(i,j)) == 0 ) continue; // intersection
		if ( test < 0 ) {					// disjoint ! convex is empty
			constraints_.clear();
			return;
		}
	  // one is redundant
	  if(test == 1)		constraints_.erase(constraints_.end()-i-1);
	  else if(test==2)	constraints_.erase(constraints_.end()-j-1);
	  else continue;     // intersection
	  redundancy = true; // we did cut out a constraint -> do the loop again
	  break;
      }

      // both neg or zero
      if( ( constraints_[i].sign_ == nEG ) &&
	    ( constraints_[j].sign_ == nEG ) ) {
		if ( (test = testConstraints(i,j)) <= 0 ) continue; // ok
		// one is redundant
		if(test == 1)    constraints_.erase(constraints_.end()-1-j);
		else if(test==2) constraints_.erase(constraints_.end()-1-i);
		else continue; // intersection
		redundancy = true; // we did cut out a constraint -> do the loop again
		break;
      }

      // one neg, one pos/zero
      if( (test = testConstraints(i,j)) == 0) continue; // ok: intersect
      if( test < 0 ) { // neg is redundant
	  if ( constraints_[i].sign_ == nEG ) constraints_.erase(constraints_.end()-1-i);
	  else    constraints_.erase(constraints_.end()-1-j);
	  redundancy = true; // we did cut out a constraint -> do the loop again
	  break;
      }
      // if the negative constraint is inside the positive: continue
      if ( (constraints_[i].sign_ == nEG && test == 2) ||
	   (constraints_[j].sign_ == nEG && test == 1) ) continue;
      // positive constraint in negative: convex is empty!
	  constraints_.clear();
      return;
    }
    if(redundancy) break;
  }

  }

  // reset the sign of the convex
  sign_ = constraints_[0].sign_;
  for(i = 1; i < constraints_.size(); i++) {
    switch (sign_) {
    case nEG:
      if(constraints_[i].sign_ == pOS) sign_ = mIXED;
      break;
    case pOS:
      if(constraints_[i].sign_ == nEG) sign_ = mIXED;
      break;
    case zERO:
      sign_ = constraints_[i].sign_;
      break;
    case mIXED:
      break;
    }
  }

  if (constraints_.size() == 1) // for one constraint, it is itself the BC
    boundingCircle_ = constraints_[0];
  else if (sign_ == pOS)
    boundingCircle_ = constraints_[0];

}