示例#1
0
 def _set_y_loc(self, y):
     while True:
         self.win_y_loc = self.source.win_y_loc
         invisible = self.win_y_loc*self.lr
         block = self.mem.get_data(invisible, self.rows*self.lr)
         self.creator = Creator(block, self.lr, self.win_y_loc)
         if len(self.creator.lines) > self.rows-2 or not self.win_y_loc:
             break
         y += 1
         self.source.win_y_loc -= 1
     return y
示例#2
0
    def _simulate_population(cls, i, seed_offset, population_size,
                             string_size):
        seed(19520624 + 10 * i + seed_offset)
        creator = Creator(population_size=population_size,
                          string_size=string_size)

        population = creator.create_population()
        evolved_population, evaluations = creator.evolve_population(population)

        success = False
        if cls._found_global_optimum(creator, evolved_population, string_size):
            success = True

        return success, evaluations
示例#3
0
def main(input_path, output_path):
    with open(input_path, 'r') as f:
        input_data = json.load(f)

    creator = Creator(input_data['style'])

    if not os.path.exists(output_path):
        os.makedirs(output_path)

    for card_name, card_data in input_data['cards'].items():
        creator.create_card(
            os.path.join(output_path, card_name + '.png'),
            card_data,
        )
    def find_minimum_population_size(cls,
                                     string_size,
                                     initial_population_size=5,
                                     num_runs=5) -> int:
        population_size = initial_population_size
        lower_bound = 0
        upper_bound = 81920
        found_upper_bound = False
        found_global_optimum_count = 0
        while lower_bound != upper_bound or found_global_optimum_count != num_runs:
            found_global_optimum_count = 0
            creator = Creator(population_size=population_size,
                              string_size=string_size)
            population = creator.create_population()

            for _ in range(num_runs):
                evolved_population = creator.evolve_population(population)
                if cls._found_global_optimum(creator, evolved_population,
                                             string_size):
                    found_global_optimum_count += 1

            if found_global_optimum_count > 0:  # Found global optimum.
                upper_bound = population_size
                if not found_upper_bound:
                    lower_bound = int(population_size / 2)
                population_size = cls._midpoint(lower_bound, upper_bound)
                found_upper_bound = True
            else:  # Failed to find global optimum 5/5 times
                if lower_bound == upper_bound:  # Lower and upper bound converged
                    # Increment population size until it succeeds 5/5 times
                    population_size += 2
                    lower_bound = population_size
                    upper_bound = population_size
                elif found_upper_bound:  # Found upper bound and failed.
                    # Increase lower bound and population size.
                    population_size = cls._midpoint(lower_bound, upper_bound)
                    lower_bound = population_size
                    if upper_bound - lower_bound == 2:
                        lower_bound += 2
                else:  # Failed without finding upper bound.
                    population_size *= 2  # Double population size

        return upper_bound
示例#5
0
    def run(s):

        s.log.info('Started host node {0} on {1}'.format(s.nodename, s.address))

        # Make some count of creator
        for i in range(0, s.creators):

            # Create instance
            creator = Creator(s.nodename)

            # Run thread
            creator.start()

            # Logging
            s.log.info('Started creator thread: {0}'.format(creator.name))

        # Make connector
        connector = Connector(s.nodename)

        # Run connector thread
        connector.start()

        # Logging
        s.log.info('Started connector thread: {0}'.format(connector.name))
示例#6
0
    def __init__(self, root, **kwargs):
        super().__init__(root, **kwargs)
        self.content = ttk.Frame(root, padding=(5, 5, 5, 5))
        self.content.grid(column=0, row=0, sticky=(N, W, E, S))
        self.content.grid_columnconfigure(0, weight=1)
        self.content.grid_columnconfigure(1, weight=1)
        self.content.grid_columnconfigure(2, weight=1)
        self.content.grid_columnconfigure(3, weight=1)
        self.content.grid_rowconfigure(0, weight=1)
        self.content.grid_rowconfigure(1, weight=100)
        self.content.grid_rowconfigure(2, weight=1)
        self.content.grid_rowconfigure(3, weight=1)

        self.logic = Creator()
        ######
        # NAME
        #
        # LABEL FRAME
        self.names_lframe = ttk.Labelframe(self.content,
                                           text='Name',
                                           padding=(10, 10, 10, 10))
        self.names_lframe.grid_columnconfigure(0, weight=1)
        # ENTRY
        self.pack_name = StringVar()
        self_pack_name_entry = ttk.Entry(self.names_lframe,
                                         textvariable=self.pack_name)
        self.pack_name.trace_add("write", self.name_has_been_written)
        # NAME GRID
        self_pack_name_entry.grid(column=0,
                                  row=0,
                                  columnspan=1,
                                  sticky=(N, W, E))

        # TODO: Make tab list items bigger in every way
        ######
        # TABS
        #
        # LABEL FRAME
        self.tabs_lframe = ttk.Labelframe(self.content,
                                          text='Tabs & Codes',
                                          padding=(10, 10, 10, 10))
        self.tabs_lframe.grid_rowconfigure(0, weight=1)
        self.tabs_lframe.grid_columnconfigure(0, weight=1)
        # ADD BUTTON
        self.add_tabs_btn = ttk.Button(self.tabs_lframe,
                                       text="Add",
                                       command=self.on_add_tabs_btn_click)
        # REMOVE BUTTON
        self.remove_tabs_btn = ttk.Button(self.tabs_lframe,
                                          text="Remove",
                                          command=self.on_remove_tab_btn_click)
        # TABS LISTBOX
        self.tab_list = StringVar(value=self.logic.tabs)
        self.tabs_lbox = Listbox(self.tabs_lframe,
                                 listvariable=self.tab_list,
                                 selectmode='extended')
        # TABS GRID
        self.tabs_lbox.grid(column=0,
                            columnspan=2,
                            row=0,
                            rowspan=2,
                            sticky=(N, S, W, E))
        self.add_tabs_btn.grid(column=0, columnspan=1, row=2, sticky=(S, W))
        self.remove_tabs_btn.grid(column=1, columnspan=1, row=2, sticky=(S, E))

        ######
        # BANNER
        #
        # LABEL FRAME
        self.banner_lframe = ttk.Labelframe(self.content,
                                            text='Banner (optional)',
                                            padding=(10, 10, 10, 10))
        # ADD BUTTON
        self.choose_banner_btn = ttk.Button(
            self.banner_lframe,
            text='Choose Banner',
            command=self.on_choose_banner_click)
        # REMOVE BUTTON
        self.remove_banner_btn = ttk.Button(
            self.banner_lframe,
            text='Remove Banner',
            command=self.on_remove_banner_click)
        # IMAGE
        self.banner_image = ImageTk.PhotoImage(Image.open(EMPTY_BANNER))
        self.banner_image_label = ttk.Label(self.banner_lframe,
                                            image=self.banner_image)
        # BANNER GRID
        self.banner_image_label.grid(column=0, row=1)
        self.choose_banner_btn.grid(column=0, row=0, sticky=W)
        self.banner_image_label.lower(self.choose_banner_btn)
        self.remove_banner_btn.grid(column=0, row=0, sticky=E)

        ######
        # ATTRACT
        #
        # LABEL FRAME
        self.attract_lframe = ttk.Labelframe(self.content,
                                             text='Attract (optional)',
                                             padding=(10, 10, 10, 10))
        # ENTRY
        self.attract_location = StringVar()
        self.attract_entry = ttk.Entry(self.attract_lframe,
                                       textvariable=self.attract_location)
        # CHOOSE ATTRACT BUTTON
        self.choose_attract_button = ttk.Button(
            self.attract_lframe,
            text='Choose',
            command=self.on_choose_attract_click)
        # ATTRACT GRID
        self.choose_attract_button.grid(column=1, row=0)
        self.attract_entry.grid(column=0, row=0)

        ######
        # NPROFILE
        #
        # LABEL FRAME
        self.nprofile_lframe = ttk.Labelframe(self.content,
                                              text='nprofile (optional)',
                                              padding=(10, 10, 10, 10))
        self.nprofile_location = StringVar()
        self.nprofile_entry = ttk.Entry(self.nprofile_lframe,
                                        textvariable=self.nprofile_location)
        # CHOOSE ATTRACT BUTTON
        self.choose_nprofile_button = ttk.Button(
            self.nprofile_lframe,
            text='Choose',
            command=self.on_choose_nprofile_click)
        # ATTRACT GRID
        self.choose_nprofile_button.grid(column=1, row=0)
        self.nprofile_entry.grid(column=0, row=0)

        ######
        # SEPARATOR
        #
        # self.separator = ttk.Separator(self.content, orient=HORIZONTAL)
        ######
        # CREATE PACK BUTTON
        self.create_pack_btn = ttk.Button(self.content,
                                          text='Save pack',
                                          command=self.on_create_pack_click)

        # ROOT GRID
        self.names_lframe.grid(column=0,
                               columnspan=2,
                               row=0,
                               rowspan=1,
                               padx=5,
                               pady=5,
                               sticky=(N, E, W))
        self.tabs_lframe.grid(column=0,
                              columnspan=2,
                              row=1,
                              rowspan=2,
                              padx=5,
                              pady=5,
                              sticky=(N, S, E, W))
        self.banner_lframe.grid(column=2,
                                columnspan=2,
                                row=0,
                                rowspan=3,
                                padx=5,
                                pady=5,
                                sticky=(N, S, E, W))
        self.attract_lframe.grid(column=0,
                                 columnspan=2,
                                 row=3,
                                 rowspan=1,
                                 padx=5,
                                 pady=5,
                                 sticky=(N, E, W))
        self.nprofile_lframe.grid(column=2,
                                  columnspan=2,
                                  row=3,
                                  rowspan=1,
                                  padx=5,
                                  pady=5,
                                  sticky=(N, E, W))
        # self.separator.grid(column=0, columnspan=4, row=4, rowspan=1, padx=5, pady=5)
        self.create_pack_btn.grid(column=3,
                                  columnspan=1,
                                  row=5,
                                  rowspan=1,
                                  padx=5,
                                  pady=5,
                                  sticky=E)
示例#7
0
import numpy as np
from creator import Creator
from viewer import Viewer
from advertiser import Advertiser
from operator import itemgetter

#np.random.seed(0)

# creating players
num_creators = 15
num_advertisers = 10
num_viewers = 40

creators = [Creator(i, 5, 1000) for i in range(num_creators)]
creators[0].max_p = 30
creators[1].max_p = 20
creators[2].max_p = 8
advertisers = [
    Advertiser(i, 1000, num_creators) for i in range(num_advertisers)
]
viewers = [Viewer(i, 100, num_creators) for i in range(num_viewers)]

rounds = 20
prev_bids = None
prev_prices = [None] * num_creators

creator_values = [[i] for i in range(num_creators)]
advertiser_values = [[i] for i in range(num_advertisers)]
viewer_values = [[i] for i in range(num_viewers)]

for c in creators:
示例#8
0
 def update_quiz(self, type, size=10):
     creator = Creator(type, size)
     self.quiz = creator.get_quiz()
     """
示例#9
0
from creator import Creator

c = Creator("dewiki")
dataset = c.create(10000, batch_size=100, fname="dewiki_10000.json.bz2")
 def setUpClass(cls):
     seed(1)
     cls._creator = Creator(population_size=6, string_size=5)
    def test_create_population(self):
        seed(1)
        population_size = 3
        creator = Creator(population_size=population_size, string_size=5)
        population = creator.create_population()
        expected_population = [
            Individual('00101'),
            Individual('11100'),
            Individual('10110')
        ]

        self.assertEqual(population_size, len(population))
        self.assertEqual(expected_population, population)