예제 #1
0
def executeSystematicSearchAlgorithm(options):
    """
    Execute the specified algorthim and prints the result
    """

    try:
        num_vars, clauses = datautil.parseCNF(options.file)
        comments = ''
        res = None
        
        if DAVIS_PUTNAM == options.algorithm.lower():
            comments += 'Using DP algorithm (The orignal DP not DPLL)\n'
            comments += 'The DP algorithm do not give a prove of satisfiablity\n'
            comments += 'If the formula is unsatisfiable, the algorithm gives ' \
                        'you a core'

            res = dp.solve(num_vars, clauses,
                           var_selection_heuristics[options.vselection])
             
                
        elif DPLL == options.algorithm.lower():
            comments += 'Using DPLL algorithm\n'
            res = dpll.solve(num_vars, clauses,
                             var_selection_heuristics[options.vselection])
                           
        printComments(comments)
        print formatSystematicSearchResult(res)
                    
    except Exception, e:
        traceback.print_exc()
        print '%s: %s' % (e.__class__.__name__, str(e))
예제 #2
0
def executeLocalSearchAlgorithm(options):
    """
    Execute the specified algorithm and prints the result
    """

    try:
        num_vars, clauses = datautil.parseCNF(options.file)
        comments = ''

        # Chose and run algorithm
        res = None
        if GSAT == options.algorithm.lower():

            if options.weighted:
                comments += 'Solved With: Weighted GSAT'
                res = wgsat.solve(num_vars, clauses, len(clauses)//2)
            else:
                comments += 'Solved With: GSAT'
                res = gsat.solve(num_vars, clauses, len(clauses)//2)

        elif GWSAT == options.algorithm.lower():

            if options.weighted:
                comments += 'Solved With: Weighted GWSAT'
                res = wgwsat.solve(num_vars, clauses, len(clauses)//2, 0.4)
            else:
                comments += 'Solved With: GWSAT'
                res = gwsat.solve(num_vars, clauses, len(clauses)//2, 0.35)
        else:
            raise Exception('Unspecified algorithm')

        # If the formula it is not satisfiable this lines are never executed
        del res[0]
        printComments(comments)
        print formatLocalSearchResult(res)

    except Exception, e:
        traceback.print_exc()
        print '%s: %s' % (e.__class__.__name__, str(e))
예제 #3
0
def main(options):
    global state_list
    state_list = []

    n_restarts = 30
    for restart in range(n_restarts):
        np.random.seed(restart)

        global replay_buf
        global q_l_agent
        global epsilon
        replay_buf = ReplayBuf(30000, 13, n_actions=4)
        q_l_agent = Estimator(replay_buf)
        run_stats = RunStats()

        n_episodes = 100
        epsilon = 1
        for i in range(n_episodes):

            epsilon = epsilon * 0.97
            q_l_agent.train(discount_factor=0.999, replay_buf=replay_buf)

            num_vars, clauses = datautil.parseCNF(options.file)
            res = None
            res = dpll.solve(num_vars, clauses, automatic_heuristic, run_stats)

            print("Ep {}  done in {} splits".format(i, run_stats.n_splits))

            replay_buf.game_over()

            run_stats.finish_episode()

        np.save("run_stats/run_stats" + str(restart),
                np.asarray(run_stats.episode_stats),
                allow_pickle=True,
                fix_imports=True)