def classify_run(path_run, single_classification=False, constraints=CLASSIFICATIONS): import common_metric import wfutil classifications = [] def __nonzero(field): value = wfutil.get_parameter(path_run, field) return float(value) != 0 def __not(field, notvalue): value = wfutil.get_parameter(path_run, field) return value != notvalue def __true(field): value = wfutil.get_parameter(path_run, field) return value == "True" # # Fitness # if __nonzero("ComplexityFitnessWeight") or __nonzero("HeuristicFitnessWeight"): classifications.append("Fitness") # # Driven/Passive # if __true("PassiveLockstep"): classifications.append("Passive") else: classifications.append("Driven") # # Random # classifications += map(lambda x: "Random_" + x, common_metric.get_random_classifications(path_run)) # # Apply Constraints # if constraints != None: classifications_constrained = list_intersection(classifications, constraints) else: classifications_constrained = classifications # # Apply Preemptions # for c in classifications_constrained: try: preempted = CLASSIFICATION_PREEMPTION[c] classifications_constrained = list_difference(classifications_constrained, preempted) except KeyError: pass # # Validate Result # if len(classifications_constrained) == 0: if len(classifications) == 0: raise ClassificationError("notfound", path_run + " cannot be classified") else: raise ClassificationError("notfound", path_run + " classification not in {" + ",".join(constraints) + "}") if single_classification and len(classifications_constrained) > 1: raise ClassificationError( "ambiguous", path_run + " classification ambiguous (" + ",".join(classifications_constrained) + ")" ) if single_classification: return classifications_constrained[0] else: return classifications_constrained
def classify_run(path_run, single_classification = False, constraints = CLASSIFICATIONS): import common_metric import wfutil classifications = [] def __nonzero(field): value = wfutil.get_parameter(path_run, field) return float(value) != 0 def __not(field, notvalue): value = wfutil.get_parameter(path_run, field) return value != notvalue def __true(field): value = wfutil.get_parameter(path_run, field) return value == 'True' # # Fitness # if __nonzero("ComplexityFitnessWeight") or __nonzero("HeuristicFitnessWeight"): classifications.append('Fitness') # # Driven/Passive # if __true("PassiveLockstep"): classifications.append('Passive') else: classifications.append('Driven') # # Random # classifications += map( lambda x: 'Random_' + x, common_metric.get_random_classifications(path_run) ) # # Apply Constraints # if constraints != None: classifications_constrained = list_intersection( classifications, constraints ) else: classifications_constrained = classifications # # Apply Preemptions # for c in classifications_constrained: try: preempted = CLASSIFICATION_PREEMPTION[c] classifications_constrained = list_difference(classifications_constrained, preempted) except KeyError: pass # # Validate Result # if len(classifications_constrained) == 0: if len(classifications) == 0: raise ClassificationError( 'notfound', path_run + ' cannot be classified' ) else: raise ClassificationError( 'notfound', path_run + ' classification not in {' + ','.join(constraints) + '}' ) if single_classification and len(classifications_constrained) > 1: raise ClassificationError( 'ambiguous', path_run + ' classification ambiguous (' + ','.join(classifications_constrained) + ')' ) if single_classification: return classifications_constrained[0] else: return classifications_constrained
def classify_run(path_run, single_classification = False, constraints = CLASSIFICATIONS, dependents = None): classifications = [] def __nonzero(field): value = read_worldfile_parameter(path_run, field) return value != None and float(value) != 0 def __not(field, notvalue, default = None): value = read_worldfile_parameter(path_run, field) if value == None: if default == None: value = notvalue else: value = default return value != notvalue # # Fitness # if __nonzero("complexityFitnessWeight") or __nonzero("heuristicFitnessWeight") or __not("useComplexityAsFitness", "O"): classifications.append('Fitness') # # Driven/Passive # if __nonzero("LockStepWithBirthsDeathsLog"): classifications.append('Passive') else: classifications.append('Driven') # # Random # classifications += map( lambda x: 'Random_' + x, common_metric.get_random_classifications(path_run) ) # # Apply Constraints # if constraints != None: classifications_constrained = list_intersection( classifications, constraints ) else: classifications_constrained = classifications # # Apply Preemptions # for c in classifications_constrained: try: preempted = CLASSIFICATION_PREEMPTION[c] classifications_constrained = list_difference(classifications_constrained, preempted) except KeyError: pass # # Apply Dependents # if dependents != None: nondependents = list_difference(classifications_constrained, dependents) if len(nondependents) == 0: classifications_constrained = [] # # Validate Result # if len(classifications_constrained) == 0: if len(classifications) == 0: raise ClassificationError( 'notfound', path_run + ' cannot be classified' ) else: raise ClassificationError( 'notfound', path_run + ' classification not in {' + ','.join(constraints) + '}' ) if single_classification and len(classifications_constrained) > 1: raise ClassificationError( 'ambiguous', path_run + ' classification ambiguous (' + ','.join(classifications_constrained) + ')' ) return classifications_constrained
def classify_run(path_run, single_classification=False, constraints=CLASSIFICATIONS, dependents=None): classifications = [] def __nonzero(field): value = read_worldfile_parameter(path_run, field) return value != None and float(value) != 0 def __not(field, notvalue, default=None): value = read_worldfile_parameter(path_run, field) if value == None: if default == None: value = notvalue else: value = default return value != notvalue # # Fitness # if __nonzero("complexityFitnessWeight") or __nonzero( "heuristicFitnessWeight") or __not("useComplexityAsFitness", "O"): classifications.append('Fitness') # # Driven/Passive # if __nonzero("LockStepWithBirthsDeathsLog"): classifications.append('Passive') else: classifications.append('Driven') # # Random # classifications += map(lambda x: 'Random_' + x, common_metric.get_random_classifications(path_run)) # # Apply Constraints # if constraints != None: classifications_constrained = list_intersection( classifications, constraints) else: classifications_constrained = classifications # # Apply Preemptions # for c in classifications_constrained: try: preempted = CLASSIFICATION_PREEMPTION[c] classifications_constrained = list_difference( classifications_constrained, preempted) except KeyError: pass # # Apply Dependents # if dependents != None: nondependents = list_difference(classifications_constrained, dependents) if len(nondependents) == 0: classifications_constrained = [] # # Validate Result # if len(classifications_constrained) == 0: if len(classifications) == 0: raise ClassificationError('notfound', path_run + ' cannot be classified') else: raise ClassificationError( 'notfound', path_run + ' classification not in {' + ','.join(constraints) + '}') if single_classification and len(classifications_constrained) > 1: raise ClassificationError( 'ambiguous', path_run + ' classification ambiguous (' + ','.join(classifications_constrained) + ')') return classifications_constrained
def classify_run(path_run, single_classification = False, constraints = CLASSIFICATIONS, dependents = None): import common_metric import wfutil classifications = [] def __nonzero(field): value = wfutil.get_parameter(path_run, field) return float(value) != 0 def __not(field, notvalue): value = wfutil.get_parameter(path_run, field) return value != notvalue def __true(field): value = wfutil.get_parameter(path_run, field) return value == 'True' # # Fitness # if __nonzero("ComplexityFitnessWeight") or __nonzero("HeuristicFitnessWeight"): classifications.append('Fitness') # # Driven/Passive # if __true("PassiveLockstep"): classifications.append('Passive') else: classifications.append('Driven') # # Random # classifications += map( lambda x: 'Random_' + x, common_metric.get_random_classifications(path_run) ) # # Apply Constraints # if constraints != None: classifications_constrained = list_intersection( classifications, constraints ) else: classifications_constrained = classifications # # Apply Preemptions # for c in classifications_constrained: try: preempted = CLASSIFICATION_PREEMPTION[c] classifications_constrained = list_difference(classifications_constrained, preempted) except KeyError: pass # # Apply Dependents # if dependents != None: nondependents = list_difference(classifications_constrained, dependents) if len(nondependents) == 0: classifications_constrained = [] # # Validate Result # if len(classifications_constrained) == 0: if len(classifications) == 0: raise ClassificationError( 'notfound', path_run + ' cannot be classified' ) else: raise ClassificationError( 'notfound', path_run + ' classification not in {' + ','.join(constraints) + '}' ) if single_classification and len(classifications_constrained) > 1: raise ClassificationError( 'ambiguous', path_run + ' classification ambiguous (' + ','.join(classifications_constrained) + ')' ) return classifications_constrained