Skip to content
Snippets Groups Projects
  • Etienne Kneuss's avatar
    a6724892
    Flatten & Simplify Solver API · a6724892
    Etienne Kneuss authored
    Solvers are no longer distinguished in 20 traits depending on what they
    implement. It turns out that most leon solvers already implemented
    everything:
    
    1) Being interrupted
    2) Push / Pop
    3) checkAssertions/getUnsatCore (a naive implementation of these
       can be added by mixing NaiveAssumptionSolver in)
    a6724892
    History
    Flatten & Simplify Solver API
    Etienne Kneuss authored
    Solvers are no longer distinguished in 20 traits depending on what they
    implement. It turns out that most leon solvers already implemented
    everything:
    
    1) Being interrupted
    2) Push / Pop
    3) checkAssertions/getUnsatCore (a naive implementation of these
       can be added by mixing NaiveAssumptionSolver in)
TimeoutSolver.scala 972 B
/* Copyright 2009-2015 EPFL, Lausanne */

package leon
package solvers

import utils._
import purescala.Expressions.Expr

import scala.concurrent.duration._

trait TimeoutSolver extends Solver {

  val ti = new TimeoutFor(this)

  var optTimeout: Option[Long] = None

  def setTimeout(timeout: Long): this.type = {
    optTimeout = Some(timeout)
    this
  }

  def setTimeout(timeout: Duration): this.type = {
    optTimeout = Some(timeout.toMillis)
    this
  }

  abstract override def check: Option[Boolean] = {
    optTimeout match {
      case Some(to) =>
        ti.interruptAfter(to) {
          super.check
        }
      case None =>
        super.check
    }
  }

  abstract override def checkAssumptions(assumptions: Set[Expr]): Option[Boolean] = {
    optTimeout match {
      case Some(to) =>
        ti.interruptAfter(to) {
          super.checkAssumptions(assumptions)
        }
      case None =>
        super.checkAssumptions(assumptions)
    }
  }

}