Class Instance

java.lang.Object
es.urjc.etsii.grafo.io.Instance
All Implemented Interfaces:
Comparable<Instance>
Direct Known Subclasses:
__RNAME__Instance, ACInstance, TestInstance, TSPInstance

public abstract class Instance extends Object implements Comparable<Instance>
Base instance class. All instance subclasses must be immutable after construction Order defaults to instance name, can be changed by user (for example, to order by instance size or any other instance property)
  • Field Details

  • Constructor Details

    • Instance

      protected Instance(String id)
      Creates a new instance
      Parameters:
      id - instance id or instance name
  • Method Details

    • compareTo

      public int compareTo(Instance o)
      Sort order will determine in which order the instances will be solved Sort defaults to instance name
      Specified by:
      compareTo in interface Comparable<Instance>
    • getId

      public String getId()
      Returns the Instance name
      Returns:
      instance name
    • setPath

      protected void setPath(String path)
      Set instance path, used by the framework
      Parameters:
      path - instance absolute path where it was loaded from
    • getPath

      public String getPath()
      Get instance absolute path
      Returns:
      instance path where it was first loaded from
    • getProperty

      public Object getProperty(String key)
      Get custom instance property. For instance, if instance is a graph: number of nodes, number of edges, etc. Properties in this map will be used by the framework to provide additional context in some operations, for example when serializing results.
      Parameters:
      key - Property name. Must be the same for all instances
      Returns:
      Value if property name exists
      Throws:
      IllegalArgumentException - if key/property name is not defined for the current instance
    • getPropertyOrDefault

      public Object getPropertyOrDefault(String key, Object defaultValue)
      Get custom instance property. For instance, if instance is a graph: number of nodes, number of edges, etc. Properties in this map will be used by the framework to provide additional context in some operations, for example when serializing results.
      Parameters:
      key - Property name. Must be the same for all instances
      defaultValue - Value to return if key does not exist
      Returns:
      Value if property name exists, default value if not
    • setProperty

      public void setProperty(String key, Object property)
      Set custom instance property. For instance, if instance is a graph: number of nodes, number of edges, etc.
      Parameters:
      key - Property name, must be common for all instances.
      property - Property value.
    • getUniquePropertiesKeys

      public static Set<String> getUniquePropertiesKeys()
      Get all property keys used so far for all instances
      Returns:
      Set of all known property keys
    • resetProperties

      public static void resetProperties()
      Destroy global memorized property names
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • customProperties

      public Map<String,Object> customProperties()
      Define custom properties for the instance
      Returns:
      Map of properties, with each entry containing the property name and its value