Beispiel #1
0
        gtm_fname = arg
    elif os.path.splitext(arg)[1] in ['png', 'pdf', 'ps', 'dot']:
        out_fnames.append(arg)
    else:
        color_fnames.append(arg)
if len(color_fnames) == 0:
    parser.error("Specify a color file")

guess = gtm_fname is None
for input_index, color_fname in enumerate(color_fnames):
    if input_index < len(out_fnames):
        out_fname = out_fnames[input_index]
    else:
        out_fname = strip_ext(color_fname) + "." + options.out_type
    if guess: gtm_fname = guess_gtmfile2(color_fname, False)
    gtm = GtmFile(gtm_fname)
    try:
        gtm.map = GtmMap(gtm_fname)
    except IOError:
        gtm.map = None
    if gtm.map is None or gtm.map.fname is None:
        if show_ind_label == "map" or show_ind_label == "index":
            ind_label = lambda i, t: "%d" % (i)
            time_label = lambda t: "%d" % (t)
        elif show_ind_label == "both":
            # both index
            ind_label = lambda i, t: "%d" % (i)
            time_label = lambda t: "T%d" % (t)
        else:
            raise Exception("ERROR")
    else:
Beispiel #2
0
            gtm_fname = arg
        # If arg is a path-cover filename (i.e. the output of a previous run).
        elif arg.endswith('.out'):
            pc_fname = arg
        else:
            print 'Unknown file extension:', arg
            exit(1)

# If no GTM file is given, try to guess it.
if gtm_fname is None:
    gtm_fname = guess_gtmfile()
if gtm_fname is None:
    print "Cannot guess a GTM file"
    exit(1)
# Reads the GTM file.
gtm = GtmFile(gtm_fname)

# Creates mapping: group ID -> members.
for g, s in gtm.group.iteritems():
    gtm.group[g] = set(s)

# Creates a group graph from the GTM.
group_graph = GroupGraph(gtm)
group = group_graph.group
group_time = group_graph.group_time

# Generates unique tmp filenames.
bname = os.path.splitext(os.path.basename(gtm_fname))[0]
pid = os.getpid()
prefix = os.path.dirname(gtm_fname)
if prefix != "": prefix += os.path.sep
Beispiel #3
0
#			exit(1)
#		else:
#			for i in range(1, len(out_fname)):
#				gtm_fname = "%s.gtm"%(out_fname[:-i])
#				try:
#					g = open(gtm_fname, 'r')
#					g.close()
#				except IOError:
#					gtm_fname = None
#				if gtm_fname is not None: break
#			if gtm_fname is None:
#				sys.stderr.write("Specify a gtm file\n")
#				exit(1)
#			sys.stderr.write("using " + gtm_fname + "\n")

gtm = GtmFile(gtm_fname)
group_count = len(gtm.groups)

# find connected components which have to be paths
# wanna check if they are paths?
uf = UnionFind()
for line in f.readlines():
	line = line.strip()
	if line.startswith("# y"): break
	if line=="" or line.startswith("#"): continue
	if line.find(',')>=0: line = line.split(',')
	elif line.find(' ')>=0: line = line.split(' ')
	else: raise Exception("Invalid line: "+line)
	if len(line)>=2:
		u,v = int(line[0]), int(line[1])
	else:
Beispiel #4
0
        gtm_fname = arg
    elif os.path.splitext(arg)[1] in ['png', 'pdf', 'ps', 'dot']:
        out_fnames.append(arg)
    else:
        color_fnames.append(arg)
if len(color_fnames)==0:
    parser.error("Specify a color file")

guess = gtm_fname is None
for input_index,color_fname in enumerate(color_fnames):
    if input_index<len(out_fnames):
        out_fname = out_fnames[input_index]
    else:
        out_fname = strip_ext(color_fname) + "." + options.out_type
    if guess: gtm_fname = guess_gtmfile2(color_fname, False)
    gtm = GtmFile(gtm_fname)
    try:
        gtm.map = GtmMap(gtm_fname)
    except IOError:
        gtm.map = None
    if gtm.map is None or gtm.map.fname is None:
        if show_ind_label == "map" or show_ind_label == "index":
            ind_label = lambda i,t: "%d"%(i)
            time_label = lambda t: "%d"%(t)
        elif show_ind_label == "both":
            # both index
            ind_label = lambda i,t: "%d"%(i)
            time_label = lambda t: "T%d"%(t)
        else:
            raise Exception("ERROR")
    else:
Beispiel #5
0
    def __init__(self, color2_fname, gtmdata=None, typesep=None):

        if gtmdata is None:
            gtmdata = GtmFile(color2_fname)
            assert gtmdata is not None

        self.gtm = gtmdata
        if color2_fname == '-':
            f = sys.stdin
        else:
            f = open(color2_fname, 'r')

        num = len(gtmdata.group) + len(gtmdata.inds) * len(gtmdata.times)

        line = f.readline()
        assert line != "", "First line in %s is empty" % color2_fname
        tmp = line.split()

        if typesep is None:
            try:
                x = int(tmp[0])
                typesep = (x == 1)
            except ValueError:
                typesep = False

        #print "typesep", typesep
        if not typesep:  # convert 1char to sep
            tmp2 = []
            for field in tmp:
                for c in field:
                    try:
                        x = int(c)
                    except ValueError:
                        raise Exception("Invalid color '%s'" % c)
                        x = ord(c) - ord('A')
                        if (x < 0):
                            x = ord(c) - ord('a')
                        assert x >= 0
                        x += 10
                    tmp2.append(x)
            tmp = tmp2

        if len(tmp) == 0:
            self.group_color = None
            self.ind_color = None
            #self.max_exist_color = None
        else:
            if len(tmp) < num:
                raise Exception, "coloring %s is shorter than gtm file. " \
                    "%d colors while %d objects" %(color2_fname, len(tmp), num)

            tmp = map(int, tmp)
            self.max_exist_color = max(tmp)

            assert len(tmp) == gtmdata.group_count + \
                gtmdata.ind_count*gtmdata.time_count, \
                "len in color file %d != len in gtm file %d" %\
                    (len(tmp), gtmdata.group_count + \
                    gtmdata.ind_count*gtmdata.time_count)

            offset = len(gtmdata.group)
            time_count = len(gtmdata.times)
            self.group_color = tmp[0:offset]
            self.ind_color = {}
            for i in gtmdata.inds:
                self.ind_color[i - 1] = tmp[offset:offset + time_count]
                offset += time_count

            if offset != len(tmp):
                raise Exception, "coloring is longer than gtm file. " \
                    "len(tmp)==%d while offset==%d" %(len(tmp), offset)
Beispiel #6
0
			quiet=True
		else:
			print "Unknown option", arg
			exit(1)
	else:
		if arg.endswith('.gtm') or arg.endswith('.gtm2'):
			gtm_fname = arg
		elif arg.endswith('.out'):
			pc_fname = arg
		else:
			print 'Unknown file extension:', arg
			exit(1)

if gtm_fname is None:
	gtm_fname = guess_gtmfile()
gtm = GtmFile(gtm_fname)

for g,s in gtm.group.iteritems():
	gtm.group[g] = set(s)

group_graph = GroupGraph(gtm)
group = group_graph.group
group_time = group_graph.group_time

if gtm_fname[-4:] != ".gtm" and gtm_fname[-5:] != ".gtm2":
	raise
bname = os.path.splitext(os.path.basename(gtm_fname))[0]
pid=os.getpid()
prefix = os.path.dirname(gtm_fname)
if prefix!="": prefix += os.path.sep
out_fname = prefix + "%s-ipc.glpk.%d.out" %(bname,pid)