from random import choice
from pygraphc.evaluation.InternalEvaluation import InternalEvaluation


class SimulatedAnnealing(object):
    def __init__(self, method, tmin, tmax, parameter, energy_type):
        """The constructor of Simulated Annealing method.

        Parameters
        ----------
        method      : str
            The method to run with simulated annealing.
        tmin        : float
            Minimum temperature.
        tmax        : float
            Maximum temperature.
        parameter   : dict
            Dictionary of parameter. Key: parameter, value: list.
        energy_type      : str
            Objective function of simulated annealing. We use internal evaluation for graph clustering.
        """
        self.method = method
        self.Tmin = tmin
        self.Tmax = tmax
        self.parameter = parameter
        self.energy_type = energy_type

    def __get_parameter(self):
        chosen_parameter = {}
        for param, value in self.parameter.iteritems():
            chosen_parameter[param] = choice(value)

        return chosen_parameter

    def __run_method(self):
        if self.method == 'max_clique':
            pass

    def __get_energy(self, graph, clusters):
        energy = 0.
        if self.energy_type == 'silhoutte':
            energy = InternalEvaluation.get_silhoutte_index(graph, clusters)

        return energy

from random import choice
from pygraphc.evaluation.InternalEvaluation import InternalEvaluation


class SimulatedAnnealing(object):
    def __init__(self, tmin, tmax, alpha, parameters, energy_type, max_iteration):
        """The constructor of Simulated Annealing method.

        Parameters
        ----------
        tmin            : float
            Minimum temperature.
        tmax            : float
            Maximum temperature.
        alpha           : float
            Cooling factor. Tnew = alpha * Tcurrent
        parameters      : dict
            Dictionary of parameters. Key: parameters, value: list.
        energy_type     : str
            Objective function of simulated annealing. We use internal evaluation for graph clustering.
        max_iteration   : int
            Maximum iteration for simulated annealing.
        """
        self.Tmin = tmin
        self.Tmax = tmax
        self.alpha = alpha
        self.parameters = parameters
        self.energy_type = energy_type
        self.max_iteration = max_iteration

    def get_parameter(self):
        """Get random parameter based on given range.

        Returns
        -------
        random_parameter    : dict[str, float]
            Dictionary of random parameters.
        """
        random_parameter = {}
        for param, value in self.parameters.iteritems():
            random_parameter[param] = choice(value)

        return random_parameter

    def get_temperature(self, current_temperature):
        new_temperature = self.alpha * current_temperature
        return new_temperature

    def get_energy(self, graph, clusters):
        energy = 0.
        if self.energy_type == 'silhoutte':
            energy = InternalEvaluation.get_silhoutte_index(graph, clusters)

        return energy

Edit the parameters. Not fix yet
Edit the parameters. Not fix yet

  from random import choice
  from pygraphc.evaluation.InternalEvaluation import InternalEvaluation
  
  
  class SimulatedAnnealing(object):
-     def __init__(self, method, tmin, tmax, parameter, energy_type):
+     def __init__(self, tmin, tmax, alpha, parameters, energy_type, max_iteration):
          """The constructor of Simulated Annealing method.
  
          Parameters
          ----------
-         method      : str
-             The method to run with simulated annealing.
-         tmin        : float
+         tmin            : float
              Minimum temperature.
-         tmax        : float
+         tmax            : float
              Maximum temperature.
+         alpha           : float
+             Cooling factor. Tnew = alpha * Tcurrent
-         parameter   : dict
+         parameters      : dict
-             Dictionary of parameter. Key: parameter, value: list.
+             Dictionary of parameters. Key: parameters, value: list.
-         energy_type      : str
+         energy_type     : str
              Objective function of simulated annealing. We use internal evaluation for graph clustering.
+         max_iteration   : int
+             Maximum iteration for simulated annealing.
          """
-         self.method = method
          self.Tmin = tmin
          self.Tmax = tmax
+         self.alpha = alpha
-         self.parameter = parameter
+         self.parameters = parameters
          self.energy_type = energy_type
+         self.max_iteration = max_iteration
  
-     def __get_parameter(self):
+     def get_parameter(self):
+         """Get random parameter based on given range.
-         chosen_parameter = {}
-         for param, value in self.parameter.iteritems():
-             chosen_parameter[param] = choice(value)
  
-         return chosen_parameter
+         Returns
+         -------
+         random_parameter    : dict[str, float]
+             Dictionary of random parameters.
+         """
+         random_parameter = {}
+         for param, value in self.parameters.iteritems():
+             random_parameter[param] = choice(value)
  
+         return random_parameter
-     def __run_method(self):
-         if self.method == 'max_clique':
-             pass
  
+     def get_temperature(self, current_temperature):
+         new_temperature = self.alpha * current_temperature
+         return new_temperature
+ 
-     def __get_energy(self, graph, clusters):
+     def get_energy(self, graph, clusters):
          energy = 0.
          if self.energy_type == 'silhoutte':
              energy = InternalEvaluation.get_silhoutte_index(graph, clusters)
  
          return energy
  
Edit the parameters. Not fix yet
## Code Before:
from random import choice
from pygraphc.evaluation.InternalEvaluation import InternalEvaluation


class SimulatedAnnealing(object):
    def __init__(self, method, tmin, tmax, parameter, energy_type):
        """The constructor of Simulated Annealing method.

        Parameters
        ----------
        method      : str
            The method to run with simulated annealing.
        tmin        : float
            Minimum temperature.
        tmax        : float
            Maximum temperature.
        parameter   : dict
            Dictionary of parameter. Key: parameter, value: list.
        energy_type      : str
            Objective function of simulated annealing. We use internal evaluation for graph clustering.
        """
        self.method = method
        self.Tmin = tmin
        self.Tmax = tmax
        self.parameter = parameter
        self.energy_type = energy_type

    def __get_parameter(self):
        chosen_parameter = {}
        for param, value in self.parameter.iteritems():
            chosen_parameter[param] = choice(value)

        return chosen_parameter

    def __run_method(self):
        if self.method == 'max_clique':
            pass

    def __get_energy(self, graph, clusters):
        energy = 0.
        if self.energy_type == 'silhoutte':
            energy = InternalEvaluation.get_silhoutte_index(graph, clusters)

        return energy

## Instruction:
Edit the parameters. Not fix yet
## Code After:
from random import choice
from pygraphc.evaluation.InternalEvaluation import InternalEvaluation


class SimulatedAnnealing(object):
    def __init__(self, tmin, tmax, alpha, parameters, energy_type, max_iteration):
        """The constructor of Simulated Annealing method.

        Parameters
        ----------
        tmin            : float
            Minimum temperature.
        tmax            : float
            Maximum temperature.
        alpha           : float
            Cooling factor. Tnew = alpha * Tcurrent
        parameters      : dict
            Dictionary of parameters. Key: parameters, value: list.
        energy_type     : str
            Objective function of simulated annealing. We use internal evaluation for graph clustering.
        max_iteration   : int
            Maximum iteration for simulated annealing.
        """
        self.Tmin = tmin
        self.Tmax = tmax
        self.alpha = alpha
        self.parameters = parameters
        self.energy_type = energy_type
        self.max_iteration = max_iteration

    def get_parameter(self):
        """Get random parameter based on given range.

        Returns
        -------
        random_parameter    : dict[str, float]
            Dictionary of random parameters.
        """
        random_parameter = {}
        for param, value in self.parameters.iteritems():
            random_parameter[param] = choice(value)

        return random_parameter

    def get_temperature(self, current_temperature):
        new_temperature = self.alpha * current_temperature
        return new_temperature

    def get_energy(self, graph, clusters):
        energy = 0.
        if self.energy_type == 'silhoutte':
            energy = InternalEvaluation.get_silhoutte_index(graph, clusters)

        return energy
