コード例 #1
0
ファイル: do_mining.py プロジェクト: lucionardelli/PacH
def run_pach(filename, **arguments):
	pach = PacH(filename, **arguments)
	complexity = pach.pach()
	initial = pach.initial_complexity
	print " Done, complexity is:",initial,'to -->',complexity
	pach.generate_pnml()
	return (complexity, initial)
コード例 #2
0
class ComparatorPnml(object):

    def __init__(self, filename, nfilename=None,
            max_coef=10, smt_timeout_iter=0, smt_timeout_matrix=0,
            positive_log=None):
        self.filename = filename
        parser = PnmlParser(filename)
        parser.parse()
        self.net = parser.petrinet
        self.dim = parser.dim
        self.event_dictionary = parser.event_dictionary
        self.positive_log = positive_log

        # Helper pach. Doesn't actually compute hull
        self.pach = PacH(filename, nfilename=nfilename)
        self.pach.event_dictionary = parser.event_dictionary
        self.pach.dim = self.dim
        self.pach.reversed_dictionary = rotate_dict(parser.event_dictionary)
        if nfilename:
            self.pach.parse_negatives()

        #qhull = self.net.get_qhull()
# TODO WTF!?
        qhull = self.net.get_qhull(neg_points=self.pach.npv_set)
        qhull.prepare_negatives()
        # Hull for NO SMT
        qhull_no_smt = copy.deepcopy(qhull)
        # Hull for SMT iterative simp
        qhull_smt_iter = copy.deepcopy(qhull)
        # Hull for SMT matrix simp
        qhull_smt_matrix = qhull

        self.comparator = Comparator(qhull_no_smt, qhull_smt_iter, qhull_smt_matrix,
                max_coef, smt_timeout_iter, smt_timeout_matrix)

    def generate_pnml(self):
        output_pnml = self.filename
        output_pnml = (output_pnml.endswith('.pnml') and output_pnml[:-5])\
                or output_pnml or ''
        return self.comparator.generate_pnml(filename=output_pnml,
                reversed_dictionary=self.pach.reversed_dictionary)

    def compare(self):
        return self.comparator.compare()

    def generate_outputs(self):
        # For every benchmark, generate the output
        return self.comparator.generate_outputs(pach=self.pach)

    def check_hull(self):
        if self.positive_log:
            return self.comparator.check_hull(log_file=self.positive_log,
                    event_dictionary=self.event_dictionary)
コード例 #3
0
ファイル: comparator_pnml.py プロジェクト: Macuyiko/PacH
    def __init__(self, filename, nfilename=None,
            max_coef=10, smt_timeout_iter=0, smt_timeout_matrix=0,
            positive_log=None):
        self.filename = filename
        parser = PnmlParser(filename)
        parser.parse()
        self.net = parser.petrinet
        self.dim = parser.dim
        self.event_dictionary = parser.event_dictionary
        self.positive_log = positive_log

        # Helper pach. Doesn't actually compute hull
        self.pach = PacH(filename,nfilename=nfilename)
        self.pach.event_dictionary = parser.event_dictionary
        self.pach.reversed_dictionary = rotate_dict(parser.event_dictionary)
        self.pach.parse_negatives()

        qhull = self.net.get_qhull()
        # Hull for NO SMT
        qhull_no_smt = copy.deepcopy(qhull)
        # Hull for SMT iterative simp
        qhull_smt_iter = copy.deepcopy(qhull)
        # Hull for SMT matrix simp
        qhull_smt_matrix = copy.deepcopy(qhull)

        self.comparator = Comparator(qhull_no_smt, qhull_smt_iter, qhull_smt_matrix,
                max_coef, smt_timeout_iter, smt_timeout_matrix)
コード例 #4
0
ファイル: pach_script.py プロジェクト: lucionardelli/PacH
def main(*args, **kwargs):
    usage = """
        Usage: ./pach_script.py <.ini config filename>
    """
    if not check_argv(sys.argv, minimum=1, maximum=4):
        print usage
        ret = -1
    else:
        ret = 0
        try:
            config_file = sys.argv[1]
            if not config_file.endswith('.ini'):
                print config_file, ' does not end in .ini. It should...'
                raise Exception('Filename has wrong extension')
            if not isfile(config_file):
                raise Exception("No such file")
            if '--debug' in sys.argv:
                pdb.set_trace()
            for filename, arguments in parse_config(config_file):
                pach = PacH(filename, **arguments)
                complexity = pach.pach()
                pach.generate_pnml()
                if '--verbose' in sys.argv:
                    print complexity
            pnml_folder,out_folder = parse_config_output(config_file)
            pwd= os.getcwd()
            for basename in os.listdir(pwd):
                if basename.endswith('.pnml'):
                    pnml_file = os.path.join(pwd, basename)
                    if os.path.isfile(pnml_file):
                        shutil.copy2(pnml_file, pnml_folder)
                        os.remove(pnml_file)
                elif basename.endswith('.out'):
                    out_file = os.path.join(pwd, basename)
                    if os.path.isfile(out_file):
                        shutil.copy2(out_file, out_folder)
                        os.remove(out_file)
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            logger.error('Error: %s' % err, exc_info=True)
            raise err
        return ret
コード例 #5
0
ファイル: comparator.py プロジェクト: lucionardelli/PacH
 def generate_pnml(self, filename='', reversed_dictionary={}):
     filename = filename or 'Generated automagically comparator.py'
     pach = PacH(filename)
     pach.reversed_dictionary = reversed_dictionary
     pach.dim = self.dim
     def_name = pach.get_def_pnml_name()
     if def_name.endswith('.pnml'):
         def_name = def_name[:-5]
     # For every benchmark, generate a PNML
     for benchmark in ['no_smt', 'smt_iter', 'smt_matrix']:
         qhull = getattr(self,'qhull_'+benchmark)
         pach.qhull = qhull
         filename = def_name + '_' + benchmark + '.pnml'
         pach.generate_pnml(filename=filename)
         logger.info('Generated the PNML %s for %s', filename, benchmark)
     return True
コード例 #6
0
ファイル: comparator.py プロジェクト: Macuyiko/PacH
 def generate_pnml(self, filename="", reversed_dictionary={}):
     filename = filename or "Generated automagically comparator.py"
     pach = PacH(filename)
     pach.reversed_dictionary = reversed_dictionary
     pach.dim = self.dim
     def_name = pach.get_def_pnml_name()
     if def_name.endswith(".pnml"):
         def_name = def_name[:-5]
     # For every benchmark, generate a PNML
     for benchmark in ["no_smt", "smt_iter", "smt_matrix"]:
         qhull = getattr(self, "qhull_" + benchmark)
         pach.qhull = qhull
         filename = def_name + "_" + benchmark + ".pnml"
         pach.generate_pnml(filename=filename)
         logger.info("Generated the PNML %s for %s", filename, benchmark)
     return True
コード例 #7
0
ファイル: comparator_xes.py プロジェクト: lucionardelli/PacH
    def __init__(self, filename,
            samp_num=1, samp_size=None,
            proj_size=None, proj_connected=True,
            nfilename=None, max_coef=10,
            smt_timeout_iter=0,
            smt_timeout_matrix=0,
            sanity_check=False):
        self.pach = PacH(filename,
            samp_num=samp_num, samp_size=samp_size,
            proj_size=proj_size, proj_connected=proj_connected,
            nfilename=nfilename, max_coef=max_coef,
            sanity_check=sanity_check)
        self.pach.parse()

        qhull = self.pach.qhull
        # Hull for NO SMT
        qhull_no_smt = copy.deepcopy(qhull)
        # Hull for SMT iterative simp
        qhull_smt_iter = copy.deepcopy(qhull)
        # Hull for SMT matrix simp
        qhull_smt_matrix = copy.deepcopy(qhull)

        self.comparator = Comparator(qhull_no_smt, qhull_smt_iter, qhull_smt_matrix,
                max_coef, smt_timeout_iter, smt_timeout_matrix)
コード例 #8
0
ファイル: comparator.py プロジェクト: lucionardelli/PacH
 def generate_outputs(self, filename=''):
     filename = filename or 'Generated automagically'
     pach = PacH(filename)
     pach.dim = self.dim
     # For every benchmark, generate the output
     qhull = self.qhull_no_smt
     pach.output.get('times',{}).update(qhull.output.get('times',{}))
     pach.qhull = qhull
     pach.smt_matrix = False
     pach.smt_iter = False
     # Force initial complexity for effectiveness calculation
     pach.initial_complexity = self.no_smt_initial_complexity
     pach.generate_output_file()
     logger.info('Generated output for NO SMT simplification')
     qhull = self.qhull_smt_iter
     pach.output.get('times',{}).update(qhull.output.get('times',{}))
     pach.qhull = qhull
     pach.smt_matrix = False
     pach.smt_iter = True
     # Force initial complexity for effectiveness calculation
     pach.initial_complexity = self.iter_initial_complexity
     pach.generate_output_file()
     logger.info('Generated output for Iterative SMT simplification')
     qhull = self.qhull_smt_matrix
     pach.output.get('times',{}).update(qhull.output.get('times',{}))
     pach.qhull = qhull
     pach.smt_matrix = True
     pach.smt_iter = False
     # Force initial complexity for effectiveness calculation
     pach.initial_complexity = self.matrix_initial_complexity
     pach.generate_output_file()
     logger.info('Generated output for Matrix SMT simplification')
     return True
コード例 #9
0
ファイル: mains.py プロジェクト: Macuyiko/PacH
def pach_main():
    usage = 'Usage: ./pach.py <LOG filename> [--debug][--verbose]'\
        '\n\t[--negative <Negative points filename>] [max_coeficient]]'\
        '\n\t[--sampling [<number of samplings>] [<sampling size>]]'\
        '\n\t[--projection [<max group size>] [<connected model>]]'\
        '\n\t[--smt-matrix [<timeout>]]'\
        '\n\t[--smt-iter [<timeout>]]'\
        '\n\t[--sanity-check]'
    if not check_argv(sys.argv, minimum=1, maximum=17):
        print usage
        ret = -1
    else:
        ret = 0
        args = {}
        try:
            filename = sys.argv[1]
            if not (filename.endswith('.xes') or filename.endswith('.txt')):
                print filename, ' does not end in .xes not .txt. It should...'
                raise Exception('Filename does not end in .xes')
            if not isfile(filename):
                raise Exception("El archivo especificado no existe")
            if '--sampling' in sys.argv or '-s' in sys.argv:
                samp_idx = '-s' in sys.argv and sys.argv.index('-s') or\
                    sys.argv.index('--sampling')
                try:
                    args['samp_num'] = int(sys.argv[samp_idx+1])
                except:
                    pass
                try:
                    args['samp_size'] = int(sys.argv[samp_idx+2])
                except:
                    pass
            if '--projection' in sys.argv or '-p' in sys.argv:
                # None indicates not to do projection.
                # False indicates no limit
                args['proj_size'] = False
                proj_idx = '-p' in sys.argv and sys.argv.index('-p') or\
                    sys.argv.index('--projection')
                try:
                    args['proj_size'] = int(sys.argv[proj_idx+1])
                except:
                    pass
                try:
                    args['proj_connected'] = int(sys.argv[proj_idx+2])
                except:
                    pass
            if '--negative' in sys.argv or '-n' in sys.argv:
                nidx = '-n' in sys.argv and sys.argv.index('-n') or\
                    sys.argv.index('--negative')
                nfilename = sys.argv[nidx+1]
                if not (nfilename.endswith('.xes') or nfilename.endswith('.txt')):
                    print nfilename, ' does not end in .xes not .txt. It should...'
                    raise Exception('Filename does not end in .xes')
                if not isfile(nfilename):
                    raise Exception("El archivo especificado no existe")
                args['nfilename'] = nfilename
                try:
                    args['max_coef'] = int(sys.argv[nidx+2])
                except:
                    pass
            if '--smt-matrix' in sys.argv or '-smt-m' in sys.argv:
                smt_idx = '-smt-m' in sys.argv and sys.argv.index('-smt-m') or\
                    sys.argv.index('--smt-matrix')
                args['smt_matrix'] = True
                try:
                    args['smt_timeout'] = int(sys.argv[smt_idx+1])
                except:
                    pass
            elif '--smt-iter' in sys.argv or '-smt-i' in sys.argv:
                smt_idx = '-smt-i' in sys.argv and sys.argv.index('-smt-i') or\
                    sys.argv.index('--smt-iter')
                args['smt_iter'] = True
                try:
                    args['smt_timeout'] = int(sys.argv[smt_idx+1])
                except:
                    pass
            if '--sanity-check' in sys.argv:
                args['sanity_check'] = True
            if '--verbose' in sys.argv:
                args['verbose'] = True
            if '--debug' in sys.argv:
                pdb.set_trace()
            pach = PacH(filename, **args)
            complexity = pach.pach()
            filename = None
            if '--output' in sys.argv or '-o' in sys.argv:
                file_idx = '-o' in sys.argv and sys.argv.index('-o') or\
                    sys.argv.index('--output')
                try:
                    filename = sys.argv[file_idx+1]
                except:
                    pass
            pach.generate_pnml(filename=filename)
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            raise err
        return ret
コード例 #10
0
ファイル: comparator.py プロジェクト: Macuyiko/PacH
 def generate_outputs(self, filename=""):
     filename = filename or "Generated automagically"
     pach = PacH(filename)
     pach.dim = self.dim
     # For every benchmark, generate the output
     qhull = self.qhull_no_smt
     pach.output.get("times", {}).update(qhull.output.get("times", {}))
     pach.qhull = qhull
     pach.smt_matrix = False
     pach.smt_iter = False
     pach.generate_output_file()
     logger.info("Generated output for NO SMT simplification")
     qhull = self.qhull_smt_iter
     pach.output.get("times", {}).update(qhull.output.get("times", {}))
     pach.qhull = qhull
     pach.smt_matrix = False
     pach.smt_iter = True
     pach.generate_output_file()
     logger.info("Generated output for Iterative SMT simplification")
     qhull = self.qhull_smt_matrix
     pach.output.get("times", {}).update(qhull.output.get("times", {}))
     pach.qhull = qhull
     pach.smt_matrix = True
     pach.smt_iter = False
     pach.generate_output_file()
     logger.info("Generated output for Matrix SMT simplification")
     return True
コード例 #11
0
ファイル: comparator_xes.py プロジェクト: lucionardelli/PacH
class ComparatorXes(object):

    def __init__(self, filename,
            samp_num=1, samp_size=None,
            proj_size=None, proj_connected=True,
            nfilename=None, max_coef=10,
            smt_timeout_iter=0,
            smt_timeout_matrix=0,
            sanity_check=False):
        self.pach = PacH(filename,
            samp_num=samp_num, samp_size=samp_size,
            proj_size=proj_size, proj_connected=proj_connected,
            nfilename=nfilename, max_coef=max_coef,
            sanity_check=sanity_check)
        self.pach.parse()

        qhull = self.pach.qhull
        # Hull for NO SMT
        qhull_no_smt = copy.deepcopy(qhull)
        # Hull for SMT iterative simp
        qhull_smt_iter = copy.deepcopy(qhull)
        # Hull for SMT matrix simp
        qhull_smt_matrix = copy.deepcopy(qhull)

        self.comparator = Comparator(qhull_no_smt, qhull_smt_iter, qhull_smt_matrix,
                max_coef, smt_timeout_iter, smt_timeout_matrix)

    def generate_pnml(self):
        return self.comparator.generate_pnml(filename=self.pach.filename,
                reversed_dictionary=self.pach.reversed_dictionary)

    def compare(self,log_file='', event_dictionary={}):
        return self.comparator.compare(log_file=log_file, event_dictionary=event_dictionary)

    def generate_outputs(self):
        # For every benchmark, generate the output
        qhull = self.comparator.qhull_no_smt
        self.pach.output.get('times',{}).update(qhull.output.get('times',{}))
        self.pach.qhull = qhull
        self.pach.smt_matrix = False
        self.pach.smt_iter = False
        # Force initial complexity for effectiveness calculation
        self.pach.initial_complexity = self.comparator.no_smt_initial_complexity
        self.pach.generate_output_file()
        logger.info('Generated output for NO SMT simplification')
        qhull = self.comparator.qhull_smt_iter
        self.pach.output.get('times',{}).update(qhull.output.get('times',{}))
        self.pach.qhull = qhull
        self.pach.smt_matrix = False
        self.pach.smt_iter = True
        # Force initial complexity for effectiveness calculation
        self.pach.initial_complexity = self.comparator.iter_initial_complexity
        self.pach.generate_output_file()
        logger.info('Generated output for Iterative SMT simplification')
        qhull = self.comparator.qhull_smt_matrix
        self.pach.output.get('times',{}).update(qhull.output.get('times',{}))
        self.pach.qhull = qhull
        self.pach.smt_matrix = True
        self.pach.smt_iter = False
        # Force initial complexity for effectiveness calculation
        self.pach.initial_complexity = self.comparator.matrix_initial_complexity
        self.pach.generate_output_file()
        logger.info('Generated output for Matrix SMT simplification')
        return True