jmdp.solvers
Class Solver<S extends State,A extends Action>

java.lang.Object
  extended by jmdp.solvers.Solver<S,A>
Direct Known Subclasses:
AbstractFiniteSolver, AbstractInfiniteSolver

public abstract class Solver<S extends State,A extends Action>
extends java.lang.Object

Structural class for every solver. Any solver that a user implements must extend this class.

Author:
Andres Sarmiento, German Riano - Universidad de Los Andes

Field Summary
protected  Policy<S,A> policy
           
protected  boolean printProcessTime
           
protected  boolean printValueFunction
           
protected  MDP<S,A> problem
           
protected  boolean solved
           
protected  ValueFunction<S> valueFunction
           
 
Constructor Summary
Solver(MDP<S,A> problem)
          Default constructor.
 
Method Summary
 Policy<S,A> getOptimalPolicy()
          Gets the optimal policy.
 ValueFunction<S> getOptimalValueFunction()
          Gets the optimal ValueFunction.
 MDP<S,A> getProblem()
          Returns the problem associated wit this solver.
abstract  long getProcessTime()
           
 ValueFunction<S> getValueFunction()
          If the problem is solved, it will return the optimal value function.
 boolean isSolved()
          Tells whether the problem has been solved.
 void printSolution()
          Prints the solution in the default print writer (System.out)
 void printSolution(java.io.PrintWriter pw)
          Prints the solution on a given print writer.
 void setPrintProcessTime(boolean val)
          Option to print the time spent solving the problem.
 void setPrintValueFunction(boolean val)
          Option to print the final value function for each state.
abstract  Solution<S,A> solve()
          Called to solve the problem.
abstract  java.lang.String toString()
          The sub classes must return the Solver name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

policy

protected Policy<S extends State,A extends Action> policy

valueFunction

protected ValueFunction<S extends State> valueFunction

solved

protected boolean solved

problem

protected MDP<S extends State,A extends Action> problem

printProcessTime

protected boolean printProcessTime

printValueFunction

protected boolean printValueFunction
Constructor Detail

Solver

public Solver(MDP<S,A> problem)
Default constructor. Receives the problem to solve. All sub classes MUS call this constructor.

Parameters:
problem - to be solved.
Method Detail

getProblem

public MDP<S,A> getProblem()
Returns the problem associated wit this solver.

Returns:
the problem associated with this solver.

solve

public abstract Solution<S,A> solve()
Called to solve the problem. This method MUST write the local variable policy and valueFunction.


getOptimalPolicy

public final Policy<S,A> getOptimalPolicy()
Gets the optimal policy. It solves the problem if it has not been solved.

Returns:
the optimal Policy.
See Also:
Policy

getValueFunction

public final ValueFunction<S> getValueFunction()
If the problem is solved, it will return the optimal value function.

Returns:
the value function in the solver.

getOptimalValueFunction

public final ValueFunction<S> getOptimalValueFunction()
Gets the optimal ValueFunction.

Returns:
the optimal ValueFunction.
See Also:
ValueFunction

isSolved

public final boolean isSolved()
Tells whether the problem has been solved.

Returns:
true if the problem has been solved

toString

public abstract java.lang.String toString()
The sub classes must return the Solver name.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getProcessTime

public abstract long getProcessTime()
Returns:
Returns the processTime of the last solve. Use System.currentTimeMillis() to get the current time.

setPrintProcessTime

public void setPrintProcessTime(boolean val)
Option to print the time spent solving the problem. It is set to false by default.


setPrintValueFunction

public void setPrintValueFunction(boolean val)
Option to print the final value function for each state. It is set to false by default.


printSolution

public void printSolution(java.io.PrintWriter pw)
Prints the solution on a given print writer.

Parameters:
pw -

printSolution

public void printSolution()
                   throws java.lang.Exception
Prints the solution in the default print writer (System.out)

Throws:
java.lang.Exception