diff --git a/cadbiom_cmd.py b/cadbiom_cmd.py index 1369bf789c5502f53fd47ccf80b251376f78b6f4..40a2d0016b0adb2fd2347011e435fa09eb6e0b67 100644 --- a/cadbiom_cmd.py +++ b/cadbiom_cmd.py @@ -15,9 +15,13 @@ def launch_researchs(args): """Parse arguments and launch Cadbiom search of MACs (Minimal Activation Conditions). - - If there is no input file, there will be only on process. + - If there is no input file, there will be only one process. - If an input file is given, there will be 1 process per line (per logical formula on each line). + - all_macs: Solver will try to search all macs with 0 to + the maximum of steps allowed. + - continue: If there is a mac file from a previous work, last frontier + places will be reloaded. """ # Module import @@ -142,6 +146,8 @@ if __name__ == "__main__": # https://docs.python.org/dev/library/argparse.html#action # all_macs to False by default parser_input_file.add_argument('--all_macs', action='store_true') + # continue to False by default + parser_input_file.add_argument('--continue', action='store_true') parser_input_file.add_argument('--start_prop', nargs='?', default=None) parser_input_file.add_argument('--inv_prop', nargs='?', default=None) parser_input_file.add_argument('--output', action=ReadableDir, nargs='?', diff --git a/solution_search.py b/solution_search.py index c91fd13eed72ddc4adc5f71a30b8753de7549de4..870009f9348a4dea991e8e4c981b9a6b844d143d 100644 --- a/solution_search.py +++ b/solution_search.py @@ -105,7 +105,7 @@ def make_logical_formula(previous_frontier_places, start_prop): def main2(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_file, - steps, final_prop, start_prop, inv_prop, all_macs): + steps, final_prop, start_prop, inv_prop, all_macs, continue_run): """ :param arg1: Model file (bcx, xml, cal). @@ -119,6 +119,8 @@ def main2(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_fil :param arg9: Formula: ??? :param arg10: If set to True (not default), search all macs with less or equal steps than previous, by limiting steps. + :param arg11: If set to True (not default), previous macs from a previous + run, will be reloaded. :type arg1: <str> :type arg2: <str> :type arg3: <str> @@ -129,6 +131,7 @@ def main2(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_fil :type arg8: <str> :type arg9: <str> :type arg10: <boolean> + :type arg11: <boolean> .. todo: handle these QUERY PARAMETERS... from GUI program @@ -147,14 +150,31 @@ def main2(chart_file, cam_file, cam_step_file, cam_complete_file, cam_strong_fil error_reporter = ErrorRep() mcla = MCLAnalyser(error_reporter) - # Load file + # Load model file detect_model_type(mcla, chart_file)(chart_file) if error_reporter.error: raise "Error during loading of file" + # Frontier places asked - previous_frontier_places = set() - current_start_prop = start_prop + if continue_run: + # Reload previous working files + try: + previous_frontier_places = read_cam_file(cam_file) + current_start_prop = make_logical_formula(previous_frontier_places, + start_prop) + LOGGER.info(final_prop + \ + ":: Reload previous frontier places: " + \ + len(previous_frontier_places)) + except IOError: + previous_frontier_places = set() + current_start_prop = start_prop + else: + # New run + previous_frontier_places = set() + current_start_prop = start_prop + + # i = 0 # with PyCallGraph(output=GraphvizOutput()): while True: @@ -494,9 +514,9 @@ def launch_researchs(params): if params['final_prop']: compute_macs(params) - # Multiple properties in input file - # => multiprocessing: 1 process for each property else: + # Multiple properties in input file + # => multiprocessing: 1 process for each property with open(params['input_file'], 'r') as fd: g = (line.rstrip('\n') for line in fd) @@ -607,10 +627,13 @@ def compute_macs(params): except: pass - remove_file(cam_file) - remove_file(cam_step_file) - remove_file(cam_complete_file) - remove_file(cam_strong_file) + if not params['continue']: + # Reset previous working files + # PS: the reload is done in main2() function + remove_file(cam_file) + remove_file(cam_step_file) + remove_file(cam_complete_file) + remove_file(cam_strong_file) # MAC research main2( @@ -621,5 +644,21 @@ def compute_macs(params): cam_strong_file, # cam_strong_file params['steps'], params['final_prop'], params['start_prop'], params['inv_prop'], - params['all_macs'], + params['all_macs'], params['continue'], ) + +def read_cam_file(file): + """Return a list a fontier places already found in cam file + + .. note:: use make_logical_formula() to get the new start_prop of the run. + + :param: Mac file of a previous run + :type: <str> + :return: A set a frontier places. + :rtype: <set> + """ + + with open(file, 'r') as fd: + return {tuple(line.rstrip('\n').split(' ')) for line in fd} + +