# Path: opentuner/search/technique.py
# class SearchTechniqueBase(with_metaclass(abc.ABCMeta, object)):
# class SearchTechnique(SearchPlugin, SearchTechniqueBase):
# class PureRandom(SearchTechnique):
# class AsyncProceduralSearchTechnique(SearchTechnique):
# class SequentialSearchTechnique(AsyncProceduralSearchTechnique):
#     def __init__(self, name=None):
#     def is_ready(self):
#     def default_name(self):
#     def handle_requested_result(self, result):
#     def set_driver(self, driver):
#     def desired_result(self):
#     def __init__(self, *pargs, **kwargs):
#     def set_driver(self, driver):
#     def desired_result(self):
#     def desired_configuration(self):
#     def handle_requested_result(self, result):
#     def default_generated_name(self):
#     def use_default_generated_name(self):
#     def base_name(self):
#     def get_hyper_parameters(cls):
#     def generate_technique(cls, manipulator=None, *args, **kwargs):
#     def desired_configuration(self):
#     def __init__(self, *pargs, **kwargs):
#     def call_main_generator(self):
#     def desired_configuration(self):
#     def main_generator(self):
#     def is_ready(self):
#     def __init__(self, novelty_threshold=50, reset_threshold=500, *pargs, **kwargs):
#     def yield_nonblocking(self, cfg):
#     def call_main_generator(self):
# def register(t):
# def register_generator(cls, generator_weight=1.0, *args, **kwargs):
# def get_random_generator_technique(generators=None, manipulator=None):
# def weighted_choice(choices):
# def all_techniques():
# def get_enabled(args):
# def get_root(args):


import math
import random
from builtins import range
from past.utils import old_div
from opentuner.search import technique
                # repeat and cycle to get state p-dist resembling this
                sel = 0
                while AcceptanceFunction(0, 1, temp, 1) > random.random():
                    sel += 1
                state = points[sel % len(points)]

                # switch to the global best if temperature is low (i.e. we aren't moving much)
                if AcceptanceFunction(0, 1, temp, 1) < .0001 and objective.lt(driver.best_result.configuration, state):
                    state = driver.best_result.configuration

            # update counter
            counter += 1
            if counter > max_time and self.loop:
                counter = counter - max_time


# Acceptance probability function for annealing
def AcceptanceFunction(e, e_new, temp, scaling):
    # Standard acceptance probability function using relative "goodness"
    if e >= e_new:
        return 1
    if temp == 0:
        return 0
    if scaling * (e_new - e) / temp > 10:
        # for practical purposes, probability is too low.
        return 0
    return math.exp(scaling * (e - e_new) / temp)


# register technique

# Path: opentuner/search/technique.py
# class SearchTechniqueBase(with_metaclass(abc.ABCMeta, object)):
# class SearchTechnique(SearchPlugin, SearchTechniqueBase):
# class PureRandom(SearchTechnique):
# class AsyncProceduralSearchTechnique(SearchTechnique):
# class SequentialSearchTechnique(AsyncProceduralSearchTechnique):
#     def __init__(self, name=None):
#     def is_ready(self):
#     def default_name(self):
#     def handle_requested_result(self, result):
#     def set_driver(self, driver):
#     def desired_result(self):
#     def __init__(self, *pargs, **kwargs):
#     def set_driver(self, driver):
#     def desired_result(self):
#     def desired_configuration(self):
#     def handle_requested_result(self, result):
#     def default_generated_name(self):
#     def use_default_generated_name(self):
#     def base_name(self):
#     def get_hyper_parameters(cls):
#     def generate_technique(cls, manipulator=None, *args, **kwargs):
#     def desired_configuration(self):
#     def __init__(self, *pargs, **kwargs):
#     def call_main_generator(self):
#     def desired_configuration(self):
#     def main_generator(self):
#     def is_ready(self):
#     def __init__(self, novelty_threshold=50, reset_threshold=500, *pargs, **kwargs):
#     def yield_nonblocking(self, cfg):
#     def call_main_generator(self):
# def register(t):
# def register_generator(cls, generator_weight=1.0, *args, **kwargs):
# def get_random_generator_technique(generators=None, manipulator=None):
# def weighted_choice(choices):
# def all_techniques():
# def get_enabled(args):
# def get_root(args):


# Path: opentuner/search/simulatedannealing.py
import math
import random
from builtins import range
from past.utils import old_div
from opentuner.search import technique

                # repeat and cycle to get state p-dist resembling this
                sel = 0
                while AcceptanceFunction(0, 1, temp, 1) > random.random():
                    sel += 1
                state = points[sel % len(points)]

                # switch to the global best if temperature is low (i.e. we aren't moving much)
                if AcceptanceFunction(0, 1, temp, 1) < .0001 and objective.lt(driver.best_result.configuration, state):
                    state = driver.best_result.configuration

            # update counter
            counter += 1
            if counter > max_time and self.loop:
                counter = counter - max_time


# Acceptance probability function for annealing
def AcceptanceFunction(e, e_new, temp, scaling):
    # Standard acceptance probability function using relative "goodness"
    if e >= e_new:
        return 1
    if temp == 0:
        return 0
    if scaling * (e_new - e) / temp > 10:
        # for practical purposes, probability is too low.
        return 0
    return math.exp(scaling * (e - e_new) / temp)


# register technique

technique.register(PseudoAnnealingSearch())