コード例 #1
0
def test_every_thing_should_be_ok_on_petit_probleme_lp():
    """Testing the problem_generator function"""
    prob_list = [os.path.join('..', 'data', 'petit_probleme.lp')]
    cons_to_vary = ['demand_0', 'demand_7', 'demand_8']
    vars_to_vary = None
    Number = 10
    Deviation = 0.1

    data = problem_generator(prob_list, Number, Deviation, cons_to_vary,
                             vars_to_vary, Xpress_Problem_Factory())
    rhs_list = data.get_RHS()
    solutions = data.get_solutions()
    assert len(rhs_list) == len(solutions) == Number and len(rhs_list[0]) == len(cons_to_vary), "" \
        "Error in problem generator function."
コード例 #2
0
def extract_cases_to_db(contest_dirs, cursor, origin, start_from='1'):
    problems = problem_generator(contest_dirs)
    contests_len = cursor.execute('SELECT COUNT(id) FROM Contests').fetchone()
    if contests_len is None or contests_len[0] == 0:
        logging.info('Database is empty')
        return

    for problem in problems:
        if problem.problem_id[0].rjust(6, '0') < start_from.rjust(6, '0'):
            continue

        logging.info('Filling in cases for problem #{0} from contest #{1}'.format(problem.problem_id[1],
                                                                                  problem.problem_id[0]))
        contest_response = cursor.execute('SELECT id FROM Contests WHERE origin = ? AND contest_id = ?',
                                          (origin, problem.problem_id[0].rjust(6, '0'))).fetchone()
        if contest_response is None:
            logging.warning('Contest #{} not found'.format(problem.problem_id[0]))
            continue

        for contest_ref in contest_response:
            problem_in_db = len(cursor.execute('SELECT id FROM Problems WHERE contest_ref = ? AND problem_id = ?',
                                               (contest_ref, problem.problem_id[1])).fetchall())
            if problem_in_db:
                cursor.execute('UPDATE Problems SET name = ?, polygon_id = ? WHERE contest_ref = ? AND problem_id = ?',
                               (problem.name, problem.polygon_id, contest_ref, problem.problem_id[1]))
            else:
                cursor.execute('INSERT INTO Problems (id, contest_ref, polygon_id, problem_id, name) VALUES (NULL, ?, ?, ?, ?)',
                               (contest_ref, problem.polygon_id, problem.problem_id[1], problem.name))
            problem_response = cursor.execute('SELECT id FROM Problems WHERE contest_ref = ? AND problem_id = ?',
                                              (contest_ref, problem.problem_id[1])).fetchone()
            if problem_response is None:
                logging.warning('Problem {} not found'.format(problem.problem_id))
                continue

            for problem_ref in problem_response:
                for case_num in range(len(problem.cases)):
                    cursor.execute('UPDATE Cases SET io_hash = ? WHERE problem_ref = ? AND case_id = ?',
                                   (problem.cases[case_num], problem_ref, case_num + 1))
                    if case_num % 50 == 0 and case_num != 0:
                        logging.info('Filled in {0} cases of problem # {1} from contest #{2}'.format(case_num,
                                                                                                     problem.problem_id[
                                                                                                         1],
                                                                                                     problem.problem_id[
                                                                                                         0]))

                logging.info('Filled in {0} cases of problem #{1} from contest #{2}'.format(case_num,
                                                                                            problem.problem_id[1],
                                                                                            problem.problem_id[0]))
コード例 #3
0
 def test_common(self, ec):
     ejudge_contest_object = Mock()
     ejudge_contest_object.get_contest_id = Mock(return_value='42')
     ejudge_contest_object.get_problem_ids = Mock(return_value=[('42', '1'), ('42', '2')])
     ejudge_contest_object.get_short_name_by_problem_id = Mock(return_value='a-plus-b')
     ejudge_contest_object.get_test_paths_by_problem_id = Mock(return_value=[('a', 'b'), ('c', 'd')])
     ec.return_value = ejudge_contest_object
     contest_dirs = [('000001', '000001'), ('000179', '000179')]
     result = [x for x in problem_generator(contest_dirs)]
     self.assertEqual(len(result), 4)
     self.assertEqual(result[0].problem_id, ('42', '1'))
     self.assertEqual(result[1].problem_id, ('42', '2'))
     self.assertEqual(result[2].problem_id, ('42', '1'))
     self.assertEqual(result[3].problem_id, ('42', '2'))
     for problem in result:
         self.assertEqual(problem.name, 'a-plus-b')
         self.assertEqual(problem.cases, ['hash', 'hash'])
     self.assertEqual(md5_hasher.get_hash.call_args_list, [(('a', 'b'),), (('c', 'd'),)] * 4)
コード例 #4
0
def test_generation():
    """
    Test generation on petit_probleme.lp, varying constraints demand_0, demand_7 and demand_8
    one by one.
    """
    cons_list = ["demand_0", "demand_7", "demand_8"]
    Number = 10000
    Deviation = 1.5
    prob_list = ["petit_probleme.lp"]
    vars_to_vary = None
    for elem in cons_list:
        cons_to_vary = [elem]
        data = problem_generator(prob_list,
                                 Number,
                                 Deviation,
                                 cons_to_vary,
                                 vars_to_vary,
                                 Xpress_Problem_Factory(),
                                 save=True,
                                 single_file=True)
    assert True
コード例 #5
0
def test_preprocessing_postprocessing_linearmax():
    prob_list = ["petit_probleme.lp"]
    cons_to_vary = ["demand_0"]
    vars_to_vary = None
    number = 100
    deviation = 0.1

    data = problem_generator(prob_list,
                             number,
                             deviation,
                             cons_to_vary,
                             vars_to_vary,
                             Xpress_Problem_Factory(),
                             save=False)
    test_data = data.copy()

    processor = SolutionProcessorLinearMax()
    processor.compute_parameters(test_data)

    processor.pre_process(test_data)

    processed_solutions = test_data.get_solutions().copy()
    output_test = OutputData(processed_solutions, processed_solutions)

    processor.post_process(output_test)

    solutions = data.get_solutions()
    test_solutions = output_test.get_solutions()

    size = test_data.size()

    for i in range(size):
        assert np.isclose(test_solutions[i],
                          solutions[i],
                          atol=1e-06,
                          rtol=1e-06)
コード例 #6
0
            vars_to_vary = None
        else:
            vars_to_vary = sys.argv[5 + nb_prob + nb_cons:]

        Deviation = 0

        for N in number_list:
            Number = N

            mode = GenerationModeMasterClassic(prob_list, cons_to_vary,
                                               vars_to_vary,
                                               determine_cons_to_vary)
            data = problem_generator(Number,
                                     Deviation,
                                     mode=mode,
                                     factory=XpressProblemFactory(),
                                     save=True,
                                     single_file=True,
                                     find_path=path)

            #DatasetAnalyser(data).plot2D_sol_fct_of_RHS()

    if True:

        number_list = [300]
        Deviation = 0

        path = sys.argv[1]
        prob_list = sys.argv[2:5]
        problem = prob_list[0]
        master = prob_list[1]