Ejemplo n.º 1
0
Archivo: mess.py Proyecto: nekobon/mess
def readquipsim(filename):
	"""
	Read QUIPSIM output file using L{parser} module.
	This creates a list of logical L{Qubit}s and a list of L{Operation}s,
	replaces 'Ent' operations and returns them.

	@type filename: string
	@param filename: QUIPSIM output filename, for the format, check L{parser}.
	@rtype:	(list of L{Qubit}, list of L{Operation})
	@return: The tuple of the list of the logical L{Qubit}s and the list of the logical L{Operation}s.
	"""
	qubits,operations = parser.read_file(filename)
	printwell(operations,'operations before encoding')
	parser.replace_ent(operations)
#	printwell(operations,'operations after replacing ent')
	return qubits,operations
Ejemplo n.º 2
0
def main():
    graph = parser.read_file('Instances/instance1.txt')
    objective_function, m = model.solve(graph)
    model.print_used_vars(m)
    print("Objective Function: " + str(objective_function))
Ejemplo n.º 3
0
def process_task(n):
    base = f"../solutions_gold/prob-{n:03}.meta.yaml"
    base_yaml = read_yaml(base)

    best_time = base_yaml["time"]

    result = {}
    result["gold"] = base_yaml["time"]
    result["task"] = n

    # read buy db and find the best result for each buy
    best = {}
    folder = f"../buy_db/task{n}/"
    files = os.listdir(folder)
    max_score = None
    for f in sorted(files):
        s = re.match("(\d+).meta.yaml", f)
        if s:
            current_yaml = read_yaml(folder + f)
            if not current_yaml:
                continue

            buy = current_yaml["buy"]
            if buy not in ALLOWED_BUYS:
                continue

            if max_score is None:
                max_score = current_yaml["max_score"]

            if buy in BEST_TIME_BUYS:
                best_time = min(best_time, current_yaml["time"])

            take = False
            if buy not in best:
                take = True
            else:
                prev = best[buy]
                if prev["time"] > current_yaml["time"]:
                    take = True

            if take:
                item = {}
                item["time"] = current_yaml["time"]
                item["spent"] = current_yaml["spent"]
                best[buy] = item

    result["buys"] = best
    result["max_score"] = max_score
    result["best_time_for_roi"] = best_time

    # read submissions and fill what was submitted
    sent_buy_file = f"../best_buy/prob-{n:03}.buy"
    selected_buy = ""
    if os.path.isfile(sent_buy_file):
        selected_buy = read_file(sent_buy_file).strip('\n')

    if selected_buy == "":
        if result["gold"] < result["buys"][""]["time"]:
            selected_buy = "gold"

    result["selected"] = selected_buy

    # update ROI for each buy
    for _, item in result["buys"].items():
        update_roi(result["gold"], max_score, best_time, item)

    return result
Ejemplo n.º 4
0
def main():
    n, p, h, f, d = parser.read_file('Instances/instance1.txt')
    objective_function, m = model.solve(n, p, h, f, d)
    print("Objective Function: " + str(objective_function))
Ejemplo n.º 5
0
def main():
    n, m, c, a, b, f = parser.read_file('Instances/instance1.txt')
    objective_function, model_created = model.solve(n, m, c, a, b, f)
    model.print_used_vars(model_created)
    print("Objective Function: " + str(objective_function))
Ejemplo n.º 6
0
def verify_solution_file(problem_file, solution_file):
    problem = read_file(problem_file)
    solution = read_file(solution_file)

    return verify_solution(problem, solution)
Ejemplo n.º 7
0

if __name__ == '__main__':
    in_dir_path = os.path.abspath(
        os.path.join(
            os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
            'input'))
    out_dir_path = os.path.abspath(
        os.path.join(
            os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
            'TourfileA'))
    inputFiles = parser.get_input_files('input')
    for file in inputFiles:
        input_url = os.path.join(in_dir_path, file)
        output_url = os.path.join(out_dir_path, "tour" + file)
        queue = parser.read_file(input_url)
        citiesNo = parser.next_number(queue)
        matrix = [[0 for x in range(citiesNo)] for y in range(citiesNo)]
        parser.populate_matrix(citiesNo, queue, matrix)
        tour, length = iterated_sa(matrix, 100)
        if sorted(tour) != list(range(len(tour))):
            raise Exception("Misformed tour")
        f = open(output_url, "w")
        f.write("NAME = " + file[:-4] + ",\n")
        f.write("TOURSIZE = " + str(len(tour)) + ",\n")
        f.write("LENGTH = " + str(length) + ",\n")
        f.write(", ".join(map(str, [x + 1 for x in tour])))
        f.close()
        print(input_url)
        # print(tour)
        # print(length)
Ejemplo n.º 8
0
def main():
  # returns: duration, intersections, streets, score, streets_dict, cars_arr
  files = ["a", "b", "c", "d", "e", "f"]
  for file in files:

    duration, num_intersections, num_streets, num_cars, score, streets_dict, cars_arr = read_file(file)

    #intersections(streets_dict, num_intersections)  
    # car starts at end of first street
    # needs to cover the rest of the streets
    cars_arr = priority_routes(cars_arr, streets_dict)
    #print(f"cars are {cars_arr}")

    # write to the result file
    write_file(file, schedule(intersections(streets_dict, num_intersections)))
Ejemplo n.º 9
0
import asyncio
from random import choice
from slugify import slugify
import config

from parser import WorkUaParser, HHRUParser, RabotaUAParser, read_file

__author__ = 'bzdvdn'

Bot = telebot.TeleBot(config.token)

Bot.remove_webhook()

print(Bot.get_me())

useragent = {'User-Agent': choice(read_file('useragent.txt'))}


def delete_file(filename):
    os.remove(filename)


@Bot.message_handler(commands=['help'])
def handle_text(message):
    Bot.send_message(
        message.chat.id, """
		Этот бот парсит сайты(work.ua, rabota.ua, hh.ru):
		на предмет поиска работы и выводит вам doc файл.
	команды /work_ua, /hh_ru, /rabota_ua
		после нажатия команд нееобходимо выбрать город/страну из предложенных на клавиатуре и дальше выбрать критерий поиска:
		Например 'Python'
Ejemplo n.º 10
0
def main():
    n = parser.read_file("Instances/instance1.txt")
    objective_function, m = model.solve(n)
    print("Objective Function: " + str(objective_function))
Ejemplo n.º 11
0
        if task_spec:
            for b in task_spec.boosters:
                img.putpixel((b[1][0], self.size - 1 -
                              b[1][1]), (255, 255, 255))
        # img = img.resize((1000, 1000), Image.BILINEAR)
        scale = int(500 / self.size)
        img = img.resize((scale * self.size, scale * self.size))
        img.show()
        img.save(f"images/{self.counter}.png")
        self.counter += 1
        # input("waiting >")


draw = len(sys.argv) > 3
file = sys.argv[1]
fout = sys.argv[2]
s = read_file(file)

spec = PuzzleSpec(s)

solver = PuzzleSolver(spec, draw)
task_spec = solver.solve()

write_problem(fout, task_spec)
world = parse_problem(read_file(sys.argv[2]))
valid = puzzle_valid(spec, world)
print("valid", valid)
if not valid:
    sys.exit(1)