예제 #1
0
파일: fill_db.py 프로젝트: vbo/icfp2013
def generate_sql_for_problem(problem, index, inputs, inputs_hash, use_parser=True):
    for formula in index.generate_formulas(problem["size"], allowed_ops=problem["operators"]):
        if use_parser:
            outputs = fast_solver.solve(formula["s"], inputs)
        else:
            outputs = solver.solve_formula(formula["formula"], inputs)


        db_outputs = get_int64_array_hash(outputs)
        if problem['operators'] is None:
            operators = '*'
        else:
            operators = list(problem['operators'])
            operators.sort()
            operators = "_".join(operators)
        assert len(db_outputs)

        query = (
            "INSERT INTO program"
            "(size, operators, code, inputs, outputs)"
            "VALUES (%s, '%s', '%s', '%s', '%s');\n" %
            (problem["size"], operators, formula["s"], inputs_hash, db_outputs)
        )

        yield query
예제 #2
0
파일: fill_db.py 프로젝트: vbo/icfp2013
        ops_to_filter = None

    if os.path.abspath(args.assert_dir) == os.path.abspath(args.outdir):
        print "ASSERT DIR CANNOT BE SAME AS OUTDIR"
        sys.exit(1)

    offset = args.offset
    limit = args.limit
    problems_getter = None

    if args.assert_only:
        args.force = True

    # We use GLOBALLY equal inputs to get inputs->outputs mapping for all problems which we can query GLOBALLY. i.e. if we don't know SIZE and OPERATORS (for bonus problems) we could just use our existing database to query only by INPUTS and OUTPUTS.
    inputs = list(generate_inputs(args.ninputs, seed=42))
    inputs_hash = get_int64_array_hash(inputs)
    inputs_readable = '|'.join('%016x' % x for x in inputs)

    inputs_query = (
        "INSERT INTO inputs"
        "(inputs_hash, inputs)"
        "VALUES ('%s', '%s');\n" %
        (inputs_hash, inputs_readable)
    )

    if args.size is not None:
        problems_to_solve = [{
            'id': -args.size,
            'operators': None,
            'size': args.size,
        }]