You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
918 B

4 years ago
  1. #!python3
  2. import sys
  3. from pysat.formula import CNF
  4. import argparse
  5. import pathlib as pl
  6. import bz2
  7. def main():
  8. f_ext= CNF(from_fp=sys.stdin)
  9. instance_dir = pl.Path(parse_args())
  10. instance, core_nr = parse_header(f_ext.comments[0])
  11. ipath = instance_dir / (instance + ".cnf.bz2")
  12. f = CNF(ipath)
  13. f.extend(f_ext)
  14. f.comments = []
  15. f.to_fp(sys.stdout,
  16. comments=["c extension_of:{} nr:{}".format(instance, core_nr)])
  17. def parse_args():
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument("-i", "--instance_dir",
  20. type=str,
  21. help="path to the directoy containing all instances")
  22. args = parser.parse_args()
  23. return args.instance_dir
  24. def parse_header(header):
  25. tokens = header.split(' ')[1:]
  26. return tokens[0].split(':')[1], int(tokens[1].split(':')[1])
  27. if __name__ == "__main__":
  28. main()