<reponame>marti-mcfly/nn-verification<filename>target_algorithms/venus/wrapper.py
#!/usr/bin/env python2.7
# encoding: utf-8

'''
emptyWrapper -- template for a wrapper based in genericWrapper.py

@author:	 <NAME>, <NAME>, <NAME>, <NAME>
@copyright:  2014 AClib. All rights reserved.
@license:	GPL
@contact:	<EMAIL>, <EMAIL>, <EMAIL>, <EMAIL>

'''

from genericWrapper import AbstractWrapper

class PipelineWrapper(AbstractWrapper):
	
	def get_command_line_args(self, runargs, config):
		'''
		Returns the command line call string to execute the target algorithm (here: Spear).
		Args:
			runargs: a map of several optional arguments for the execution of the target algorithm.
					{
					  "instance": <instance>,
					  "specifics" : <extra data associated with the instance>,
					  "cutoff" : <runtime cutoff>,
					  "runlength" : <runlength cutoff>,
					  "seed" : <seed>
					}
			config: a mapping from parameter name to parameter value
		Returns:
			A command call list to execute the target algorithm.
		'''
		binary_path = "/your/path/here/aclib2/target_algorithms/mip/venus/run_venus.py"
		cmd = "python3 %s --lrob_input %s" %(binary_path, runargs["instance"])
		for name, value in config.items():
			cmd += " -%s %s" %(name,  value)
		return cmd
	
	def process_results(self, filepointer, out_args):
		'''
		Parse a results file to extract the run's status (SUCCESS/CRASHED/etc) and other optional results.
	
		Args:
			filepointer: a pointer to the file containing the solver execution standard out.
			out_args : a map with {"exit_code" : exit code of target algorithm} 
		Returns:
			A map containing the standard AClib run results. The current standard result map as of AClib 2.06 is:
			{
				"status" : <"SUCCESS"/"SAT"/"UNSAT"/"TIMEOUT"/"CRASHED"/"ABORT">,
				"runtime" : <runtime of target algrithm>,
				"quality" : <a domain specific measure of the quality of the solution [optional]>,
				"misc" : <a (comma-less) string that will be associated with the run [optional]>
			}
			ATTENTION: The return values will overwrite the measured results of the runsolver (if runsolver was used). 
		'''
		import re
		data = filepointer.read().decode('utf-8')
		resultMap = {}

		print(data)

		if (re.search('Satisfied', data)):
			resultMap['status'] = 'SAT'
		elif (re.search('NOT Satis', data)):
			resultMap['status'] = 'UNSAT'
		# else:
		# 	resultMap['status'] = 'TIMEOUT'

		return resultMap

if __name__ == "__main__":
	wrapper = PipelineWrapper()
	wrapper.main()

#!/usr/bin/env python2.7
# encoding: utf-8

'''
emptyWrapper -- template for a wrapper based in genericWrapper.py

@author:	 <NAME>, <NAME>, <NAME>, <NAME>
@copyright:  2014 AClib. All rights reserved.
@license:	GPL
@contact:	<EMAIL>, <EMAIL>, <EMAIL>, <EMAIL>

'''

from genericWrapper import AbstractWrapper

class PipelineWrapper(AbstractWrapper):
	
	def get_command_line_args(self, runargs, config):
		'''
		Returns the command line call string to execute the target algorithm (here: Spear).
		Args:
			runargs: a map of several optional arguments for the execution of the target algorithm.
					{
					  "instance": <instance>,
					  "specifics" : <extra data associated with the instance>,
					  "cutoff" : <runtime cutoff>,
					  "runlength" : <runlength cutoff>,
					  "seed" : <seed>
					}
			config: a mapping from parameter name to parameter value
		Returns:
			A command call list to execute the target algorithm.
		'''
		binary_path = "/your/path/here/aclib2/target_algorithms/mip/venus/run_venus.py"
		cmd = "python3 %s --lrob_input %s" %(binary_path, runargs["instance"])
		for name, value in config.items():
			cmd += " -%s %s" %(name,  value)
		return cmd
	
	def process_results(self, filepointer, out_args):
		'''
		Parse a results file to extract the run's status (SUCCESS/CRASHED/etc) and other optional results.
	
		Args:
			filepointer: a pointer to the file containing the solver execution standard out.
			out_args : a map with {"exit_code" : exit code of target algorithm} 
		Returns:
			A map containing the standard AClib run results. The current standard result map as of AClib 2.06 is:
			{
				"status" : <"SUCCESS"/"SAT"/"UNSAT"/"TIMEOUT"/"CRASHED"/"ABORT">,
				"runtime" : <runtime of target algrithm>,
				"quality" : <a domain specific measure of the quality of the solution [optional]>,
				"misc" : <a (comma-less) string that will be associated with the run [optional]>
			}
			ATTENTION: The return values will overwrite the measured results of the runsolver (if runsolver was used). 
		'''
		import re
		data = filepointer.read().decode('utf-8')
		resultMap = {}

		print(data)

		if (re.search('Satisfied', data)):
			resultMap['status'] = 'SAT'
		elif (re.search('NOT Satis', data)):
			resultMap['status'] = 'UNSAT'
		# else:
		# 	resultMap['status'] = 'TIMEOUT'

		return resultMap

if __name__ == "__main__":
	wrapper = PipelineWrapper()
	wrapper.main()
#!/usr/bin/env python2.7 # encoding: utf-8 emptyWrapper -- template for a wrapper based in genericWrapper.py  @author:	 <NAME>, <NAME>, <NAME>, <NAME> @copyright:  2014 AClib. All rights reserved. @license:	GPL @contact:	<EMAIL>, <EMAIL>, <EMAIL>, <EMAIL> Returns the command line call string to execute the target algorithm (here: Spear). 		Args: 			runargs: a map of several optional arguments for the execution of the target algorithm. 					{ 					  "instance": <instance>, 					  "specifics" : <extra data associated with the instance>, 					  "cutoff" : <runtime cutoff>, 					  "runlength" : <runlength cutoff>, 					  "seed" : <seed> 					} 			config: a mapping from parameter name to parameter value 		Returns: 			A command call list to execute the target algorithm. Parse a results file to extract the run's status (SUCCESS/CRASHED/etc) and other optional results. 	 		Args: 			filepointer: a pointer to the file containing the solver execution standard out. 			out_args : a map with {"exit_code" : exit code of target algorithm}  		Returns: 			A map containing the standard AClib run results. The current standard result map as of AClib 2.06 is: 			{ 				"status" : <"SUCCESS"/"SAT"/"UNSAT"/"TIMEOUT"/"CRASHED"/"ABORT">, 				"runtime" : <runtime of target algrithm>, 				"quality" : <a domain specific measure of the quality of the solution [optional]>, 				"misc" : <a (comma-less) string that will be associated with the run [optional]> 			} 			ATTENTION: The return values will overwrite the measured results of the runsolver (if runsolver was used). # else: # 	resultMap['status'] = 'TIMEOUT'