<commit_before># We need to put ancenstor directory in sys.path to let us import utils and algorithm
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

# start to import what we want.
import random
import utils
from pyopencl import array as clarray
from ocl_ga import OpenCLGA
from shuffler_chromosome import ShufflerChromosome
from simple_gene import SimpleGene

def run(num_chromosomes, generations):
    num_cities = 20
    random.seed(119)
    city_ids = list(range(0, num_cities))
    city_info = {city_id: (random.random() * 100, random.random() * 100) for city_id in city_ids}

    sample = ShufflerChromosome([SimpleGene(v, city_ids) for v in city_ids])

    f = open(os.path.join("cl", "simple_tsp.c"), "r")
    fstr = "".join(f.readlines())
    f.close()

    pointX = [str(city_info[v][0]) for v in city_info];
    pointY = [str(city_info[v][1]) for v in city_info]

    tsp_ga_cl = OpenCLGA(sample, generations, num_chromosomes, fstr, "simple_tsp_fitness",\
                         [{"t": "float", "v": pointX, "n": "x"},\
                          {"t": "float", "v": pointY, "n": "y"}]\
                         , ["../../kernel"])

    prob_mutate = 0.2
    prob_cross = 0.8
    tsp_ga_cl.run(prob_mutate, prob_cross)

    print("run took", tsp_ga_cl.elapsed_time, "seconds")
    best = tsp_ga_cl.best
    print("Shortest Path: " + " => ".join(str(g) for g in best))
<commit_msg>update syntax for backslash<commit_after># We need to put ancenstor directory in sys.path to let us import utils and algorithm
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

# start to import what we want.
import random
import utils
from pyopencl import array as clarray
from ocl_ga import OpenCLGA
from shuffler_chromosome import ShufflerChromosome
from simple_gene import SimpleGene

def run(num_chromosomes, generations):
    num_cities = 20
    random.seed(119)
    city_ids = list(range(0, num_cities))
    city_info = {city_id: (random.random() * 100, random.random() * 100) for city_id in city_ids}

    sample = ShufflerChromosome([SimpleGene(v, city_ids) for v in city_ids])

    f = open(os.path.join("cl", "simple_tsp.c"), "r")
    fstr = "".join(f.readlines())
    f.close()

    pointX = [str(city_info[v][0]) for v in city_info];
    pointY = [str(city_info[v][1]) for v in city_info]

    tsp_ga_cl = OpenCLGA(sample, generations, num_chromosomes, fstr, "simple_tsp_fitness",
                         [{"t": "float", "v": pointX, "n": "x"},
                          {"t": "float", "v": pointY, "n": "y"}],
                         ["../../kernel"])

    prob_mutate = 0.2
    prob_cross = 0.8
    tsp_ga_cl.run(prob_mutate, prob_cross)

    print("run took", tsp_ga_cl.elapsed_time, "seconds")
    best = tsp_ga_cl.best
    print("Shortest Path: " + " => ".join(str(g) for g in best))

{'fraction_non_alphanumeric': 0.13959044368600682, 'fraction_numerical': 0.012286689419795221, 'mean_word_length': 3.3102941176470586, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714267', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1027, 'n_words': 267}