#!/usr/bin/env python2.7 # # Usage: new_auto.py # # Read a list of problem names and (integer, real, or symbolic) # features for problems, as well as a number of protocols containing # results for different heuristics of E, and try to find a good # assigment of heuristics to problem classes. # # Copyright 2002-2003 Stephan Schulz, schulz@informatik.tu-muenchen.de # # This program is part of the support structure for the equational # theorem prover E. Visit # # http://www4.informatik.tu-muenchen.de/~schulz/WORK/eprover.html # # for more information. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program ; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # # The original copyright holder can be contacted as # # Stephan Schulz # Technische Universitaet Muenchen # Institut fuer Informatik # Boltzmannstrasse 3 # Garching bei Muenchen # Germany # # or via email (address above). # For older Python versions from __future__ import nested_scopes import sys import re import string import math white_space = re.compile('\s+') trail_space = re.compile('\s*$') arg_term = re.compile('\s|$') full_comment = re.compile('^#') dash = re.compile('-') slash = re.compile('/') match_heuristic = re.compile("-H'\(.*\)'") match_class = re.compile('CLASS_[A-Z-0-9]*$') eval_f_sep = re.compile('\),') problem_ext = re.compile('\.[a-z]*$') feature_sep = re.compile('[ :(),\n]+') type_int = type(1) type_float = type(1.5) type_string = type("abc") log_nat_2 = math.log(2) SetEmptyException = "SetEmptyException" NoSuchPartitionException = "NoSuchPartitionException" def comment_p(line): """Is a line a comment line?""" return line[0] == "#" def uniq_list(l): """Return a list containing one copy of each different value in l. l is assumed to be sorted.""" i = 0 res = [] limit = len(l) while i e2[0]: return -1 if e1[0] < e2[0]: return 1 if e1[1] > e2[1]: return 1 if e1[1] < e2[1]: return -1 return 0 class protocol: """Store a single result file""" def __init__(self): self.name = "" self.desc = "" self.probs = {} self.eval = None def parse(self, name): f = open(name, "r") lines = f.readlines() f.close() self.name = name self.desc = reduce(add, filter(comment_p, lines), "") lines = filter(lambda x: not comment_p(x), lines) lines = map(lambda x: string.split(x), lines) for i in lines: self.probs[i[0]] = i[1],string.atof(i[2]) return self # For the future, Consider if it makes sense to allow incomplete # protocols and return failure for non-existent names! def result(self, prob): return self.probs[prob] def compute_eval(self): return reduce(result_add, map(self.result, self.probs.keys()), (0,0)) def evaluate(self): if(not self.eval): self.eval=self.compute_eval() return self.eval def eval_set(self, set): return reduce(result_add, map(self.result, set), (0,0)) def __cmp__(self, other): e1 = self.evaluate() e2 = other.evaluate() return eval_cmp(e1,e2) class protocolset: """Store a set of protocols (i.e. heuristics with results)""" def __init__(self): self.set = {} self.sorted = None def insert(self, prot): self.set[prot.name] = prot self.sorted = None def __repr__(self): return repr(self.set) def result(self,prot, prob): return self.set[prot].probs[prob] def success(self,prot,prob): return self.result(prot,prob)[0]!="F" def time(self,prot,prob): if self.success(prot,prob): return self.result(prot,prob)[1] return None def sort(self): if not self.sorted: prots = self.set.values() prots.sort() self.sorted = prots return self.sorted #return map(lambda x:x.name, prots) def optimal_prob(self, prob): """Find the optimal heuristic for a problem""" res = None t = 0 for i in self.sort(): tmp = i.result(prob) # print tmp if tmp[0]!="F" and (not res or tmp[1] " features = featurelist(sys.argv[1]) set = features.features.keys() part = partition(features) #part.make_equicard(1,set,2) part.make_equidist(1,set,100) print part print part.give_sets() print compute_entropy(part.give_sets(), rel_frequency) print compute_entropy(part.give_sets(), rule_of_succession) # print features.featuretypes protocols = protocolset(); for i in sys.argv[2:]: print i; tmp=protocol().parse(i) protocols.insert(tmp)