jmarkov.jmdp.solvers

## Class Solver<S extends State,A extends Action>

- java.lang.Object
- - jmarkov.jmdp.solvers.Solver<S,A>

- Type Parameters:
    `S` - States class.
    `A` - Actions class.
  All Implemented Interfaces:
    JMarkovElement
  Direct Known Subclasses:
    AbstractFiniteSolver, AbstractInfiniteSolver

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

  Structural class for every solver. Any solver that a user implements must extend this class.
  Author:
    Andres Sarmiento, Germán Riaño - Universidad de Los Andes

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `description()` This method return a complete verbal describtion of this element.
    `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.
    `abstract java.lang.String` | `label()` The sub classes must return the Solver name.
    `void` | `printSolution()` Prints the solution in the default PrintWriter (System.out)
    `void` | `printSolution(java.io.PrintWriter pw)` Prints the solution on a given PrintWriter.
    `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.
    `java.lang.String` | `toString()` This calls label().

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface jmarkov.basic.JMarkovElement

      `equals`

- - ### 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()
                                                                    throws SolverException

      Called to solve the problem. This method MUST write the local variable policy and valueFunction.
      Returns:
        The solution Object taht contains the plicy and value fuenction.
      Throws:
        `SolverException` - This exception is thrown if the solver cannot find a solution for some reason.

    - #### getOptimalPolicy

          public final Policy<S,A> getOptimalPolicy()
                                                                          throws SolverException

      Gets the optimal policy. It solves the problem if it has not been solved.
      Returns:
        the optimal Policy.
      Throws:
        `SolverException`
      See Also:
        `Policy`

    - #### getValueFunction

          public final ValueFunction<S> getValueFunction()

      If the problem is solved, it will return the optimal value function. Otherwise it returns the current valueFunction
      Returns:
        the value function in the solver.

    - #### getOptimalValueFunction

          public final ValueFunction<S> getOptimalValueFunction()
                                                                       throws SolverException

      Gets the optimal ValueFunction.
      Returns:
        the optimal ValueFunction.
      Throws:
        `SolverException`
      See Also:
        `ValueFunction`

    - #### isSolved

          public final boolean isSolved()

      Tells whether the problem has been solved.
      Returns:
        true if the problem has been solved

    - #### label

          public abstract java.lang.String label()

      The sub classes must return the Solver name.
      Specified by:
        `label` in interface `JMarkovElement`
      Returns:
        A String label.
      See Also:
        `toString()`

    - #### description

          public java.lang.String description()

      Description copied from interface: `JMarkovElement`
      This method return a complete verbal describtion of this element. This description may contain multiple text rows.
      Specified by:
        `description` in interface `JMarkovElement`
      Returns:
        A String describing this element.
      See Also:
        `JMarkovElement.label()`

    - #### toString

          public final java.lang.String toString()

      This calls label().
      Specified by:
        `toString` in interface `JMarkovElement`
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        A String label.
      See Also:
        `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.
      Parameters:
        `val` - True if the Process tiem is to be reported, false otherwise.

    - #### setPrintValueFunction

          public void setPrintValueFunction(boolean val)

      Option to print the final value function for each state. It is set to false by default.
      Parameters:
        `val` - True if the value function is to be reported.

    - #### printSolution

          public void printSolution(java.io.PrintWriter pw)

      Prints the solution on a given PrintWriter.
      Parameters:
        `pw` -
      See Also:
        `PrintWriter`

    - #### printSolution

          public void printSolution()
                             throws java.lang.Exception

      Prints the solution in the default PrintWriter (System.out)
      Throws:
        `java.lang.Exception`