/**
  * Replace all interval terms that are variables by unique ground terms. Used to assure that
  * intervals added by resolvers do not exist in the constraint database they are added to.
  */
 public void makeUniqueGroundKeys() {
   long ID = UniqueID.getID();
   Substitution sub = new Substitution();
   for (Statement s : this.getCondition().get(Statement.class)) {
     if (s.getKey().isVariable()) {
       sub.add(s.getKey(), Term.createConstant(s.getKey().toString().replace("?", "") + "#" + ID));
     }
   }
   for (OpenGoal s : this.getCondition().get(OpenGoal.class)) {
     if (s.getStatement().getKey().isVariable()) {
       sub.add(
           s.getStatement().getKey(),
           Term.createConstant(s.getStatement().getKey().toString().replace("?", "") + "#" + ID));
     }
   }
   for (ConstraintDatabase resolver : this.getResolvers()) {
     for (Statement s : resolver.get(Statement.class)) {
       if (s.getKey().isVariable()) {
         sub.add(
             s.getKey(), Term.createConstant(s.getKey().toString().replace("?", "") + "#" + ID));
       }
     }
     for (OpenGoal s : resolver.get(OpenGoal.class)) {
       if (s.getStatement().getKey().isVariable()) {
         sub.add(
             s.getStatement().getKey(),
             Term.createConstant(
                 s.getStatement().getKey().toString().replace("?", "") + "#" + ID));
       }
     }
   }
   this.substitute(sub);
 }
 @Override
 public Collection<Term> getGroundTerms() {
   ArrayList<Term> r = new ArrayList<Term>();
   r.addAll(this.Condition.getGroundTerms());
   for (ConstraintDatabase res : this.Resolvers) {
     r.addAll(res.getGroundTerms());
   }
   r.addAll(this.name.getGroundTerms());
   return r;
 }
  @Override
  public Expression substitute(Substitution theta) {
    //		Profiler.probe(0);
    this.name = this.name.substitute(theta);
    this.Condition.substitute(theta);
    for (ConstraintDatabase r : Resolvers) {
      r.substitute(theta);
    }

    return this;
  }
  @Override
  public InteractionConstraint copy() {
    //		Profiler.probe(3);
    InteractionConstraint c = new InteractionConstraint(this.name);

    c.Condition = this.Condition.copy();

    for (ConstraintDatabase con : this.Resolvers) {
      c.addResolver(con.copy());
    }
    c.pickedResolver = this.pickedResolver;
    c.setAsserted(this.isAsserted());
    return c;
  }
  @Override
  public String toString() {
    StringBuilder r = new StringBuilder();
    r.append("(conditional\n\t" + this.name + "\n");
    r.append("\t(condition\n");
    String s = "\t\t" + this.Condition.toString().toString().replace("\n", "\n\t\t");
    r.append(s.substring(0, s.length() - 2));
    r.append("\t)");

    for (ConstraintDatabase c : this.Resolvers) {
      r.append("\n\t(resolver\n");
      s = "\t\t" + c.toString().replace("\n", "\n\t\t");

      r.append(s.substring(0, s.length() - 2));
      r.append("\t)");
    }
    r.append("\n)");
    return r.toString();
  }