omnics
Class AbstractSolver

java.lang.Object
  extended by omnics.AbstractSolver
All Implemented Interfaces:
java.io.Serializable, Solver
Direct Known Subclasses:
SystematicSolver

public abstract class AbstractSolver
extends java.lang.Object
implements Solver, java.io.Serializable

Represents the abstract implementation of the Solver interface.

Author:
Cristian Frasinaru
See Also:
Serialized Form

Field Summary
protected  Analyzer analyzer
           
protected  long endTime
           
protected  int optimum
           
protected  boolean paused
           
protected  Problem problem
           
protected  boolean running
           
protected  Tuple solution
           
protected  TupleSet solutions
           
protected  int solutionsLimit
           
protected  long startTime
           
protected  int timeLimit
           
 
Fields inherited from interface omnics.Solver
BENCHMARK_FORMAT, DETAILED_FORMAT
 
Constructor Summary
AbstractSolver(Problem problem)
          Creates a new instance of AbstractSolver
 
Method Summary
 int eval(Tuple tuple)
          Evaluates a tuple.
 Analyzer getAnalyzer()
           
 long getEndTime()
           
 Problem getProblem()
          Returns a reference to the problem beeing solved.
 int getSolutionsLimit()
          Returns the maximum number of solutions to be found.
 long getStartTime()
           
 int getTimeLimit()
          Returns the time limit (in seconds) imposed for the solver.
 boolean isPaused()
          Returns true if the solver is paused.
 boolean isRunning()
          Returns true if the solver is running.
 void logResult(java.lang.String filename, int format)
          Writes the result to a log file.
 int optimum()
          Returns the optimum found so far.
 void printResult(java.io.PrintStream out)
           
 void printResult(java.io.PrintStream out, int format)
          Prints the result of the algorithm.
 void save(java.lang.String filename)
          Performs serialization and writes the solver object to a filename in binary form.
 void setAnalyzer(Analyzer analyzer)
           
 void setEndTime(long endTime)
           
 void setPaused(boolean paused)
          Causes the solver to pause or to resume execution.
 void setProblem(Problem problem)
          Sets a problem to be solved.
protected  void setRunning(boolean running)
           
 void setSolutionsLimit(int solutionsLimit)
          Impose a limit for the number of solutions to be found.
 void setStartTime(long startTime)
           
 void setTimeLimit(int timeLimit)
          Impose a time limit (in seconds) for the solver.
 Tuple solution()
          Returns the current partial solution
 TupleSet solutions()
          Returns the solutions found so far.
 Tuple solve()
          Solves the problem and returns a single solution or null if a solution cannot be found.
 TupleSet solve(int solutionsLimit)
          Solves the problem and returns a specified number of solutions or null if no solution can be found
abstract  TupleSet solveAll()
          Solves the problem and returns all solutions or null if no solution can be found
 void stop()
          Stops permanently the solver.
 long time()
          Returns the time in miliseconds
 java.lang.String timeToString()
          Returns the time in miliseconds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

problem

protected Problem problem

analyzer

protected Analyzer analyzer

solution

protected Tuple solution

solutions

protected TupleSet solutions

optimum

protected int optimum

running

protected boolean running

paused

protected boolean paused

timeLimit

protected int timeLimit

startTime

protected long startTime

endTime

protected long endTime

solutionsLimit

protected int solutionsLimit
Constructor Detail

AbstractSolver

public AbstractSolver(Problem problem)
Creates a new instance of AbstractSolver

Method Detail

getProblem

public Problem getProblem()
Description copied from interface: Solver
Returns a reference to the problem beeing solved.

Specified by:
getProblem in interface Solver
Returns:
the problem beeing solved or null if no problem was specified yet.

setProblem

public void setProblem(Problem problem)
Description copied from interface: Solver
Sets a problem to be solved.

Specified by:
setProblem in interface Solver
Parameters:
problem - the problem to be solved
See Also:
Problem

getAnalyzer

public Analyzer getAnalyzer()
Specified by:
getAnalyzer in interface Solver

setAnalyzer

public void setAnalyzer(Analyzer analyzer)
Specified by:
setAnalyzer in interface Solver

solution

public Tuple solution()
Returns the current partial solution

Specified by:
solution in interface Solver
Returns:
the current partial solution

solutions

public TupleSet solutions()
Returns the solutions found so far.

Specified by:
solutions in interface Solver
Returns:
the solutions found

optimum

public int optimum()
Returns the optimum found so far.

Specified by:
optimum in interface Solver
Returns:
the current optimum

getStartTime

public long getStartTime()

setStartTime

public void setStartTime(long startTime)

getEndTime

public long getEndTime()

setEndTime

public void setEndTime(long endTime)

time

public long time()
Returns the time in miliseconds


timeToString

public java.lang.String timeToString()
Returns the time in miliseconds


eval

public int eval(Tuple tuple)
Evaluates a tuple.

Specified by:
eval in interface Solver
Returns:
a value between ValuationStructure.MIN and ValuationStructure.MAX
See Also:
ValuationStructure

logResult

public void logResult(java.lang.String filename,
                      int format)
Writes the result to a log file.

Specified by:
logResult in interface Solver
Parameters:
filename - a filename
format - DETAILED_FORMAT or BENCHMARK_FORMAT;

printResult

public void printResult(java.io.PrintStream out,
                        int format)
Description copied from interface: Solver
Prints the result of the algorithm.

Specified by:
printResult in interface Solver
Parameters:
out - a PrintStream
format - DETAILED_FORMAT or BENCHMARK_FORMAT;

printResult

public void printResult(java.io.PrintStream out)

isRunning

public boolean isRunning()
Description copied from interface: Solver
Returns true if the solver is running.

Specified by:
isRunning in interface Solver

setRunning

protected void setRunning(boolean running)

getTimeLimit

public int getTimeLimit()
Returns the time limit (in seconds) imposed for the solver.

Specified by:
getTimeLimit in interface Solver

setTimeLimit

public void setTimeLimit(int timeLimit)
Impose a time limit (in seconds) for the solver.

Specified by:
setTimeLimit in interface Solver

getSolutionsLimit

public int getSolutionsLimit()
Returns the maximum number of solutions to be found. Zero or a negative value means find all solutions.


setSolutionsLimit

public void setSolutionsLimit(int solutionsLimit)
Impose a limit for the number of solutions to be found. Zero or a negative value means find all solutions.


solve

public TupleSet solve(int solutionsLimit)
Description copied from interface: Solver
Solves the problem and returns a specified number of solutions or null if no solution can be found

Specified by:
solve in interface Solver

solve

public Tuple solve()
Description copied from interface: Solver
Solves the problem and returns a single solution or null if a solution cannot be found.

Specified by:
solve in interface Solver
Returns:
a solution or null if the problem is inconsistent

save

public void save(java.lang.String filename)
Performs serialization and writes the solver object to a filename in binary form.


stop

public void stop()
Description copied from interface: Solver
Stops permanently the solver.

Specified by:
stop in interface Solver

isPaused

public boolean isPaused()
Description copied from interface: Solver
Returns true if the solver is paused. Use setPaused(false) to resume the execution.

Specified by:
isPaused in interface Solver
Returns:
true if the solver is pause, false if the solver is running

setPaused

public void setPaused(boolean paused)
Description copied from interface: Solver
Causes the solver to pause or to resume execution.

Specified by:
setPaused in interface Solver
Parameters:
paused - if true, the solver will pause, otherwise it will resume execution

solveAll

public abstract TupleSet solveAll()
Description copied from interface: Solver
Solves the problem and returns all solutions or null if no solution can be found

Specified by:
solveAll in interface Solver
Returns:
all solutions of the problem or null if the problem is inconsistent