Class SolutionSerializer<S extends Solution<S,I>,I extends Instance>

java.lang.Object
es.urjc.etsii.grafo.io.serializers.SolutionSerializer<S,I>
Type Parameters:
S - Solution class
I - Instance class
Direct Known Subclasses:
DefaultJSONSolutionSerializer

public abstract class SolutionSerializer<S extends Solution<S,I>,I extends Instance> extends Object
Subclass to provide a custom implementation to export solutions to file.
  • Field Details

  • Constructor Details

    • SolutionSerializer

      protected SolutionSerializer(AbstractSolutionSerializerConfig config)
      Create a new solution serializer with the given config
      Parameters:
      config - Common solution serializer configuration
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Check if this serializer is enabled
      Returns:
      true if enabled and ready to export, false otherwise.
    • exportSolution

      public final void exportSolution(WorkUnitResult<S,I> r)
      Write a solution to disk.
      Parameters:
      r - result of execution
    • getFilename

      protected String getFilename(String experimentName, String instanceName, String shortAlgName, String iterationId)
      Get filename
      Parameters:
      experimentName - experiment name
      Returns:
      the file name
    • export

      public void export(String folder, String suggestedFilename, WorkUnitResult<S,I> result)
      Custom export implementation. Exports the given solution to the provided file.
      Parameters:
      folder - Folder where solutions should be stored according to the configuration
      suggestedFilename - Suggested filename, can be ignored by the implementation
      result - result to export, contains solution and extra data
    • export

      public abstract void export(BufferedWriter writer, WorkUnitResult<S,I> result) throws IOException
      Custom export implementation. Exports the given solution to disk. You do not need to handle IOExceptions. If an IOException occurs, the given solution export is skipped.
      Parameters:
      writer - Output, write data here
      result - Solution to export
      Throws:
      IOException - exception thrown in case something goes wrong
    • getConfig

    • toString

      public String toString()
      Overrides:
      toString in class Object