javax.constraints.impl.search.goal.GoalCheckTimeLimit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsr331 Show documentation
Show all versions of jsr331 Show documentation
JCP Standard JSR331 “Java Constraint Programming API”. It is used for Modeling and Solving Constraint Satisfaction and Optimization Problems using Java and off-the-shelf Constraint/Linear Solvers
The newest version!
//=============================================
// J A V A C O M M U N I T Y P R O C E S S
//
// J S R 3 3 1
//
// Common Implementation
//
//=============================================
package javax.constraints.impl.search.goal;
import javax.constraints.Problem;
import javax.constraints.Solver;
/**
* This goal checks if time limit exceeded and if yes it forces solver to
* backtrack.
*/
public class GoalCheckTimeLimit extends Goal {
GoalCheckTimeLimit(Solver solver) {
super(solver, "CheckTimeLimit");
}
public Goal execute() throws Exception {
trace();
SolverWithGoals solver = getSolver();
Problem problem = solver.getProblem();
if (solver.checkTimeLimit()) {
if (solver.isTimeLimitExceeded() == false) {
solver.setTimeLimitExceeded(true);
String msg = "Time limit " + solver.getTimeLimit() + " has been exceeded";
solver.addExplanation(msg);
problem.log(msg);
}
solver.backtrack();
}
return null;
}
}