示例#1
0
from exchanger import SimpleRandomExchanger


def update_progress(progress: int):
    """
    Shows progress bar. Progress is passed in percent.
    """
    print('\r[{0}] {1}%'.format('#' * (progress // 10), progress), end='')


if __name__ == "__main__":
    number_of_lymphocytes = 100
    max_height = 4

    DataFileStorageHelper.save_to_file(
        'test_x_y.txt', ['x', 'y'],
        lambda x, y: x * x + x * y * math.sin(x * y), 100)

    variables, values = DataFileStorageHelper.load_from_file('test_x_y.txt')

    f = FitnessFunction(values)
    exchanger = SimpleRandomExchanger(lambda: [
        Expression.generate_random(max_height=max_height, variables=variables)
        for i in range(0, number_of_lymphocytes // 2)
    ])

    config = ExpressionsImmuneSystemConfig()

    results = []
    iterations = 5
    start = time.clock()
__author__ = 'Stanislav Ushakov'

from immune import ExpressionsImmuneSystem, DataFileStorageHelper, ExpressionsImmuneSystemConfig
from exchanger import PeerToPeerExchanger, LocalhostNodesManager
import sys

#start as "python node_main.py node_num number_of_nodes"
if __name__ == '__main__':
    number = int(sys.argv[1])
    number_of_nodes = int(sys.argv[2])

    nodes_manager = LocalhostNodesManager(number, number_of_nodes)

    config = ExpressionsImmuneSystemConfig()
    config.number_of_lymphocytes = 200
    config.number_of_iterations = 200
    config.number_of_iterations_to_exchange = 30
    config.maximal_height = 5

    variables, values = DataFileStorageHelper.load_from_file('test_x_y.txt')

    exchanger = PeerToPeerExchanger(nodes_manager)

    results = []
    immuneSystem = ExpressionsImmuneSystem(exact_values=values,
                                           variables=variables,
                                           exchanger=exchanger,
                                           config=config)
    best = immuneSystem.solve()
    print(best)
__author__ = 'Stanislav Ushakov'

from immune import ExpressionsImmuneSystem, DataFileStorageHelper, ExpressionsImmuneSystemConfig
from exchanger import PeerToPeerExchanger, LocalhostNodesManager
import sys

#start as "python node_main.py node_num number_of_nodes"
if __name__ == '__main__':
    number = int(sys.argv[1])
    number_of_nodes = int(sys.argv[2])

    nodes_manager = LocalhostNodesManager(number, number_of_nodes)

    config = ExpressionsImmuneSystemConfig()
    config.number_of_lymphocytes = 200
    config.number_of_iterations = 200
    config.number_of_iterations_to_exchange = 30
    config.maximal_height = 5

    variables, values = DataFileStorageHelper.load_from_file('test_x_y.txt')

    exchanger = PeerToPeerExchanger(nodes_manager)

    results = []
    immuneSystem = ExpressionsImmuneSystem(exact_values=values,
            variables=variables,
            exchanger=exchanger,
            config=config)
    best = immuneSystem.solve()
    print(best)
from immune import ExpressionsImmuneSystem, FitnessFunction, DataFileStorageHelper, ExpressionsImmuneSystemConfig
from exchanger import SimpleRandomExchanger


def update_progress(progress):
    """
    Shows progress bar. Progress is passed in percent.
    """
    print '\r[{0}] {1}%'.format('#' * (progress // 10), progress)


if __name__ == "__main__":
    number_of_lymphocytes = 100
    max_height = 4

    DataFileStorageHelper.save_to_file('test_x_y.txt', ['x', 'y'], lambda x, y: x * x + x * y * math.sin(x * y), 100)

    variables, values = DataFileStorageHelper.load_from_file('test_x_y.txt')

    f = FitnessFunction(values)
    exchanger = SimpleRandomExchanger(
        lambda: [Expression.generate_random(max_height=max_height, variables=variables)
                 for i in range(0, number_of_lymphocytes // 2)])

    config = ExpressionsImmuneSystemConfig()

    results = []
    iterations = 5
    start = time.clock()
    for i in range(0, iterations):
        immuneSystem = ExpressionsImmuneSystem(exact_values=values,