org.licas.module.h_module

## Class HM_Cluster

- java.lang.Object
- - java.lang.Thread
  - - org.licas.module.LicasModule
    - - org.licas.module.FrameworkModule
      - - org.licas.module.ServiceModule
        - - org.licas.module.HeuristicModule
          - - org.licas.module.h_module.HM_Cluster

- All Implemented Interfaces:
    java.lang.Runnable, ServiceDef
  Direct Known Subclasses:
    HM_CompleteLink, HM_ContainsLink, HM_SingleLink

      public abstract class HM_Cluster
      extends HeuristicModule

  Base class for the clustering heuristics. These receive values from distributed services and cluster them with the module's service value.
  Author:
    Kieran Greer

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.HashMap<java.lang.String,org.ai_heuristic.eval.metric.MetricDataset>` | `allData` Datasets from all available services.
    `protected java.util.ArrayList<java.lang.String>` | `clusterURIs` List of service IDs/URIs that are clustered with this service.
    `protected org.ai_heuristic.functs.Function` | `evalMetric` The evaluation metric
    `protected int` | `numberOfIterations` Number of test run iterations, if specified
    `protected java.util.Random` | `rnd` Random number generator

    - ### Fields inherited from class org.licas.module.HeuristicModule

      `configXml`

    - ### Fields inherited from class org.licas.module.ServiceModule

      `shutDown`

    - ### Fields inherited from class org.licas.module.FrameworkModule

      `passwordHandler, service, serviceType`

    - ### Fields inherited from class org.licas.module.LicasModule

      `jarFile, syncOn, uuid`

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HM_Cluster()` Create a new instance of HM_Cluster.
    `HM_Cluster(org.licas_xml.abs.Element adminXml)` Create a new instance of HM_Cluster.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected int` | `alreadyLinkedTo(java.lang.String linkTo)` Check for existing links to the selected service, as part of a cluster.
    `protected java.lang.String` | `getMetricType()` Get the evaluation metric type, if initialised with the info in the admin `Meta` element.
    `protected boolean` | `iterationsOK(int maxIterations)` Return true if the current iterations value is OK with respect to a maximum value.
    `void` | `resetValues()` Reset variables for another test run.

    - ### Methods inherited from class org.licas.module.HeuristicModule

      `evaluate`

    - ### Methods inherited from class org.licas.module.ServiceModule

      `getShutDown, interrupt, setShutDown, setShutDown`

    - ### Methods inherited from class org.licas.module.FrameworkModule

      `canAccess, canAccessTemp, getPasswordHandler, getPasswordHandler, getServerPassword, getServicePassword, getServiceType, isAdminKey, setServiceDetails, setServiceType`

    - ### Methods inherited from class org.licas.module.LicasModule

      `getJarFile, getUUID, loadObject, setJarFile, setUUID, threadAliveState`

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

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

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

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

    - ### Methods inherited from interface org.licas.def.ServiceDef

      `getUUID, setJarFile, setUUID`

- - ### Field Detail

    - #### numberOfIterations

          protected int numberOfIterations

      Number of test run iterations, if specified

    - #### allData

          protected java.util.HashMap<java.lang.String,org.ai_heuristic.eval.metric.MetricDataset> allData

      Datasets from all available services. Key is service ID, value is data object.

    - #### clusterURIs

          protected java.util.ArrayList<java.lang.String> clusterURIs

      List of service IDs/URIs that are clustered with this service.

    - #### evalMetric

          protected org.ai_heuristic.functs.Function evalMetric

      The evaluation metric

    - #### rnd

          protected java.util.Random rnd

      Random number generator

  - ### Constructor Detail

    - #### HM_Cluster

          public HM_Cluster()
                     throws java.lang.Exception

      Create a new instance of HM_Cluster.
      Throws:
        `java.lang.Exception` - any error.

    - #### HM_Cluster

          public HM_Cluster(org.licas_xml.abs.Element adminXml)
                     throws java.lang.Exception

      Create a new instance of HM_Cluster.
      Parameters:
        `adminXml` - configuration parameters, including metric type and setup.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### resetValues

          public void resetValues()

      Reset variables for another test run.
      Specified by:
        `resetValues` in class `HeuristicModule`

    - #### iterationsOK

          protected boolean iterationsOK(int maxIterations)

      Return true if the current iterations value is OK with respect to a maximum value. This also updates the iterations value.
      Parameters:
        `maxIterations` - the maximum value to compare with.
      Returns:
        true if the current value is OK.

    - #### alreadyLinkedTo

          protected int alreadyLinkedTo(java.lang.String linkTo)
                                 throws java.lang.Exception

      Check for existing links to the selected service, as part of a cluster.
      Parameters:
        `linkTo` - the uuid of the service to check for.
      Returns:
        an integer of -1 if the service does not yet exist, 0 if there is no link to the service or its cluster, or 1 if there is a link to the service or its cluster.
      Throws:
        `java.lang.Exception` - any error.

    - #### getMetricType

          protected java.lang.String getMetricType()
                                            throws java.lang.Exception

      Get the evaluation metric type, if initialised with the info in the admin `Meta` element. This check can be performed automatically, but the metric info might not be added, when a default metric (`Euclidean`) can be used instead.
      Returns:
        the evaluation metric type, if added to the admin document Meta element, or null otherwise.
      Throws:
        `java.lang.Exception` - any error.