Commits

Seonghoon Kang committed 4ff8c30

snapshot

  • Participants
  • Parent commits d8e59f2

Comments (0)

Files changed (10)

 split
 verifier
 *.pyc
+temp?.rle
 		// emit the individual input file
 		sprintf(buf, "data/input%d.txt", i);
 		fp = fopen(buf, "w");
+		if (fp == NULL) {
+			fprintf(stderr, "Fatal Error: failed to write to %s\n", buf);
+			return 2;
+		}
 		fprintf(fp, "%d %d %d %d %d %s\n", n, m, ip, cs, cn, get_rulestring(buf));
 		for (set<point>::const_iterator it = itable.begin(); it != itable.end(); ++it) {
 			fprintf(fp, "%d %d\n", it->first, it->second);
 		// emit the RLE file for further inspection
 		sprintf(buf, "data/input%d.rle", i);
 		fp = fopen(buf, "w");
+		if (fp == NULL) {
+			fprintf(stderr, "Fatal Error: failed to write to %s\n", buf);
+			return 2;
+		}
 		write_rle(fp, itable);
 		fclose(fp);
 	}

File elimcomps.py

 
 # (rulestring, patternstring): dict from (# of further nexts) to list of prior sets
 elimrules0 = {}
-currule = curpat = curnexts = curelims = None
+currules = curpat = curnexts = curelims = None
 with open('elimrules.txt', 'r') as f:
     for line in f:
         if not line.strip(): continue
         if line.startswith('#'): continue
         line = line.rstrip('\r\n')
         if line.startswith('B'): # rulestring
-            if currule:
-                assert curpat and curelims
-                elimrules0[currule, '\n'.join(curpat)] = \
-                        dict((k, '\n'.join(v)) for k,v in curelims.items())
-            currule = line
+            if currules:
+                if not curpat and not curelims:
+                    currules.append(line)
+                else:
+                    assert curpat and curelims
+                    for currule in currules:
+                        elimrules0[currule, '\n'.join(curpat)] = \
+                                dict((k, '\n'.join(v)) for k,v in curelims.items())
+            else:
+                currules = [line]
             curpat = []
             curnexts = None
             curelims = {}
             curelims[curnexts] = []
         else:
             assert False
-    if currule:
+    if currules:
         assert curpat and curelims
-        elimrules0[currule, '\n'.join(curpat)] = \
-                dict((k, '\n'.join(v)) for k,v in curelims.items())
+        for currule in currules:
+            elimrules0[currule, '\n'.join(curpat)] = \
+                    dict((k, '\n'.join(v)) for k,v in curelims.items())
 
 def rule_has_b2(rule):
     return (gol.parse_rulestring(rule)[0] >> 2) & 1
             patidx = int(patidx)
             patterncounts[patidx] = int(patcnt)
             continue
-        line = line.replace('[]','o').replace('  ','.')
         patterns.setdefault(patidx, []).append(line)
 
 # try to eliminate each components with the minimal cost

File elimrules.txt

 # horribly inefficient for many cases).
 #
 # the rule looks like this:
-# B3/S23        <- rulestring
+# B3/S23        <- one or more rulestrings
+# B368/S245
 # ..o           <- source pattern
 # o.o
 # .oo
 ###
 
 B3/S23
+B368/S245
 ooo
 
 1
 o.o
 ...
 
+2
+.o.
+o..
+.o.
+
 ###
 
 B3/S23
 .....o.
 oo.....
 
-###
+############################################################
+############################################################
+############################################################
 
 B2
 .oo.
 ...
 ..o
 
+############################################################
+############################################################
+############################################################
+
+B368/S245
+.o.
+ooo
+.o.
+
+1
+.o.
+o..
+.o.
+
+4
+.o.
+oo.
+.o.
+
+###
+
+B368/S245
+o.o
+.o.
+o.o
+
+1
+o.o
+...
+o.o
+
+###
+
+B368/S245
+ooo
+ooo
+
+1
+o.o
+o.o
+
+###
+
+B368/S245
+oooo
+
+1
+o.oo
+
+###
+
+B368/S245
+oo
+oo
+o.
+
+1
+oo
+oo
+..
+
+###
+
+B368/S245
+.oo
+.o.
+oo.
+
+2
+.oo
+...
+oo.
+
+###
+
+B368/S245
+oo
+oo
+oo
+oo
+
+2
+oo
+o.
+.o
+oo
+
+###
+
+B368/S245
+.o.
+ooo
+..o
+
+2
+.o.
+.oo
+..o
+
 ----
 
 v = map(int,'''
-4 216 2246815 8379090 3210515 826244 632298 76358 5006030
+4 216 2246815 8379090 3210515 826244 631108 41814 5006030
+''' '''
 4 204 2245528 12149490 701427 858694 966868 27486 5001495 
 4 316 2245528 12149490 701427 969414 1024548 86980 5001495
 4 232 3571938 168133350 1015963 858694 1232940 31622 10893045 

File patternize.py

     if line.startswith('pattern '):
         for i in xrange(10): lines.append('')
         continue
-    line = line.replace('[]','o').replace('  ','b').rstrip('b')
+    line = line.replace('.','b').rstrip('b')
     maxwidth = max(maxwidth, len(line))
     lines.append(line)
 print 'x = %d, y = %d, rule = %s' % (maxwidth, len(lines), rule)
 shouldrun 5 && cherrypick 5 5386 477501
 #shouldrun 6 && bruteforce 6 3025056
 shouldrun 6 && elimcomps 6 5120 2 4
-shouldrun 7 && cherrypick 7 282 43029
+#shouldrun 7 && cherrypick 7 282 43029
+shouldrun 7 && elimcomps 7 282 2 4
 shouldrun 8 && elimcomps 8
 exit 0
 
 	FILE *fp;
 	
 	fp = fopen(argv[1], "w");
+	if (fp == NULL) {
+		fprintf(stderr, "Fatal Error: failed to write to %s\n", argv[1]);
+		return 2;
+	}
 	char rulestr[32];
 	fprintf(fp, "cost %d %d\nrule %s\n\n", cs, cn, get_rulestring(rulestr));
 	vector<point> patoffs(patterns.size());
 		}
 		for (int x = minx; x <= maxx; ++x) {
 			for (int y = miny; y <= maxy; ++y) {
-				fprintf(fp, pat.find(xy(x,y)) != pat.end() ? "[]" : "  ");
+				fprintf(fp, pat.find(xy(x,y)) != pat.end() ? "o" : ".");
 			}
 			fprintf(fp, "\n");
 		}
 	fclose(fp);
 
 	fp = fopen(argv[2], "w");
+	if (fp == NULL) {
+		fprintf(stderr, "Fatal Error: failed to write to %s\n", argv[2]);
+		return 2;
+	}
 	for (vector<cluster>::const_iterator it = clusters.begin(); it != clusters.end(); ++it) {
 		if (it->patidx < 0) continue;
 		point minxy = patoffs[it->patidx];
             minx = min(x for x, y in pat); maxx = max(x for x, y in pat)
             miny = min(y for x, y in pat); maxy = max(y for x, y in pat)
             for x in xrange(minx, maxx+1):
-                print >>f, ''.join('[]' if (x,y) in pat else '  ' for y in xrange(miny, maxy+1))
+                print >>f, ''.join('o' if (x,y) in pat else '.' for y in xrange(miny, maxy+1))
             print >>f
             patoffs[patidx] = (minx, miny)
 

File verifier.cpp

 	fprintf(stderr, "evolving %d generations with Golly... (previous population %d)\n", ngens, p);
 
 	fp = fopen("temp1.rle", "w");
+	if (fp == NULL) {
+		fprintf(stderr, "Fatal Error: failed to write to temp1.rle\n");
+		exit(2);
+	}
 	write_rle(fp, table);
 	fclose(fp);
 
 	fprintf(stderr, "\n");
 
 	fp = fopen("temp2.rle", "r");
+	if (fp == NULL) {
+		fprintf(stderr, "Fatal Error: failed to read from temp2.rle\n");
+		exit(2);
+	}
 	p = read_rle(fp, table);
 	fclose(fp);
 
 	swap(p, ip);
 
 	FILE *fp = fopen(argv[1], "r");
+	if (fp == NULL) {
+		fprintf(stderr, "Fatal Error: failed to read from %s\n", argv[1]);
+		return 2;
+	}
 	int n;
 	fscanf(fp, "%d", &n);
 
 		fscanf(fp, "%d ", &n);
 
 		FILE *fout = fopen(argv[1], "w");
+		if (fout == NULL) {
+			fprintf(stderr, "Fatal Error: failed to write to %s\n", argv[1]);
+			return 2;
+		}
 		fprintf(fout, "%d\n", n + (int) table.size());
 
 		// copy the original data as is