from __future__ import print_function, division

from sympy.logic.utilities import load_file
from sympy.logic import satisfiable
import time
import os
import sys

input_path = os.getcwd() + '/' + '/'.join(sys.argv[0].split('/')[:-1])

INPUT = [5 * i for i in range(2, 16)]
ALGORITHMS = ['dpll', 'dpll2']
results = {}

for test in INPUT:
    results[test] = {}

for test in INPUT:
    for alg in ALGORITHMS:
        file_name = "%s/input/%d.cnf" % (input_path, test)
        theory = load_file(file_name)
        start = time.time()
        if not satisfiable(theory, algorithm=alg):
            raise ValueError("Function returned false")
        end = time.time()
        results[test][alg] = end - start
        print("Test %d in time %.2f seconds for algorithm %s." %
            (test, end - start, alg))

print("problem," + ','.join(ALGORITHMS))

for test in INPUT:
    line = "%d" % test
    for alg in ALGORITHMS:
        line += ",%f" % results[test][alg]
    print(line)

from __future__ import print_function, division

from sympy.logic.utilities import load_file
from sympy.logic import satisfiable
import time
import os
import sys

input_path = os.path.dirname(__file__)

INPUT = [5 * i for i in range(2, 16)]
ALGORITHMS = ['dpll', 'dpll2']
results = {}

if __name__ == '__main__':
    for test in INPUT:
        results[test] = {}

    for test in INPUT:
        for alg in ALGORITHMS:
            file_name = os.path.join(input_path, 'input', '%s.cnf' % test)
            theory = load_file(file_name)
            start = time.time()
            if not satisfiable(theory, algorithm=alg):
                raise ValueError("Function returned false")
            end = time.time()
            results[test][alg] = end - start
            print("Test %d in time %.2f seconds for algorithm %s." %
                (test, end - start, alg))

    print("problem," + ','.join(ALGORITHMS))

    for test in INPUT:
        line = "%d" % test
        for alg in ALGORITHMS:
            line += ",%f" % results[test][alg]
        print(line)

Make logic benchmarks runner more portable
Make logic benchmarks runner more portable

  from __future__ import print_function, division
  
  from sympy.logic.utilities import load_file
  from sympy.logic import satisfiable
  import time
  import os
  import sys
  
- input_path = os.getcwd() + '/' + '/'.join(sys.argv[0].split('/')[:-1])
+ input_path = os.path.dirname(__file__)
  
  INPUT = [5 * i for i in range(2, 16)]
  ALGORITHMS = ['dpll', 'dpll2']
  results = {}
  
+ if __name__ == '__main__':
- for test in INPUT:
+     for test in INPUT:
-     results[test] = {}
+         results[test] = {}
  
- for test in INPUT:
+     for test in INPUT:
-     for alg in ALGORITHMS:
+         for alg in ALGORITHMS:
-         file_name = "%s/input/%d.cnf" % (input_path, test)
+             file_name = os.path.join(input_path, 'input', '%s.cnf' % test)
-         theory = load_file(file_name)
+             theory = load_file(file_name)
-         start = time.time()
+             start = time.time()
-         if not satisfiable(theory, algorithm=alg):
+             if not satisfiable(theory, algorithm=alg):
-             raise ValueError("Function returned false")
+                 raise ValueError("Function returned false")
-         end = time.time()
+             end = time.time()
-         results[test][alg] = end - start
+             results[test][alg] = end - start
-         print("Test %d in time %.2f seconds for algorithm %s." %
+             print("Test %d in time %.2f seconds for algorithm %s." %
-             (test, end - start, alg))
+                 (test, end - start, alg))
  
- print("problem," + ','.join(ALGORITHMS))
+     print("problem," + ','.join(ALGORITHMS))
  
- for test in INPUT:
+     for test in INPUT:
-     line = "%d" % test
+         line = "%d" % test
-     for alg in ALGORITHMS:
+         for alg in ALGORITHMS:
-         line += ",%f" % results[test][alg]
+             line += ",%f" % results[test][alg]
-     print(line)
+         print(line)
  
Make logic benchmarks runner more portable
## Code Before:
from __future__ import print_function, division

from sympy.logic.utilities import load_file
from sympy.logic import satisfiable
import time
import os
import sys

input_path = os.getcwd() + '/' + '/'.join(sys.argv[0].split('/')[:-1])

INPUT = [5 * i for i in range(2, 16)]
ALGORITHMS = ['dpll', 'dpll2']
results = {}

for test in INPUT:
    results[test] = {}

for test in INPUT:
    for alg in ALGORITHMS:
        file_name = "%s/input/%d.cnf" % (input_path, test)
        theory = load_file(file_name)
        start = time.time()
        if not satisfiable(theory, algorithm=alg):
            raise ValueError("Function returned false")
        end = time.time()
        results[test][alg] = end - start
        print("Test %d in time %.2f seconds for algorithm %s." %
            (test, end - start, alg))

print("problem," + ','.join(ALGORITHMS))

for test in INPUT:
    line = "%d" % test
    for alg in ALGORITHMS:
        line += ",%f" % results[test][alg]
    print(line)

## Instruction:
Make logic benchmarks runner more portable
## Code After:
from __future__ import print_function, division

from sympy.logic.utilities import load_file
from sympy.logic import satisfiable
import time
import os
import sys

input_path = os.path.dirname(__file__)

INPUT = [5 * i for i in range(2, 16)]
ALGORITHMS = ['dpll', 'dpll2']
results = {}

if __name__ == '__main__':
    for test in INPUT:
        results[test] = {}

    for test in INPUT:
        for alg in ALGORITHMS:
            file_name = os.path.join(input_path, 'input', '%s.cnf' % test)
            theory = load_file(file_name)
            start = time.time()
            if not satisfiable(theory, algorithm=alg):
                raise ValueError("Function returned false")
            end = time.time()
            results[test][alg] = end - start
            print("Test %d in time %.2f seconds for algorithm %s." %
                (test, end - start, alg))

    print("problem," + ','.join(ALGORITHMS))

    for test in INPUT:
        line = "%d" % test
        for alg in ALGORITHMS:
            line += ",%f" % results[test][alg]
        print(line)
