## cool / src / lib / GMLMIP-0.1 / rand.pl @ 7c4d2eb4

History | View | Annotate | Download (2.02 KB)

1 |
#!/usr/bin/perl |
---|---|

2 |
use Switch; |

3 | |

4 |
$size = 25; |

5 |
$prefix = "test"; |

6 |
$num_formulas = 1000; |

7 |
$num_propvars = 5; |

8 |
$max_index = 100; |

9 | |

10 |
for ($i = 0; $i < $num_formulas; $i++) { |

11 |
$factfilename = "size" . $size . $prefix . $i . ".fact"; |

12 |
$willfilename = "size" . $size . $prefix . $i . ".will"; |

13 |
open FACT, ">", $factfilename; |

14 |
# satisfy fact syntax |

15 |
print FACT "(equal_c SAT "; |

16 |
open WILL, ">", $willfilename; |

17 |
# satisfy will syntax |

18 |
print WILL "Logic: GML\n"; |

19 |
random_formula($size); |

20 |
print FACT ")\n"; |

21 |
close FACT; |

22 |
close WILL; |

23 |
} |

24 | |

25 |
sub random_formula { |

26 |
local ($size) = $_[0]; |

27 | |

28 |
# terminate on size 1 and return prop variable |

29 |
if ($size == 1) { |

30 |
$num = int(rand($num_propvars)); |

31 |
print FACT "p" . $num . " "; |

32 |
print WILL "p" . $num . " ";; |

33 |
} |

34 |
if ($size == 2) { |

35 |
# guess unary connective |

36 |
$conn = int(rand(2)); |

37 |
switch ($conn) { |

38 |
case 0 { |

39 |
print WILL "(~"; |

40 |
print FACT "(not "; |

41 |
random_formula(1); |

42 |
print WILL ")"; |

43 |
print FACT ")"; |

44 |
} |

45 |
case 1 { |

46 |
$n = int(rand($max_index)); |

47 |
print WILL "(<" . $n . ">"; |

48 |
print FACT "(min " . ($n+1) . " r "; |

49 |
random_formula(1); |

50 |
print WILL ")"; |

51 |
print FACT ")"; |

52 |
} |

53 |
} |

54 |
} |

55 |
if ($size > 2) { |

56 |
# guess a connective |

57 |
$conn = int(rand(4)); |

58 |
switch ($conn) { |

59 |
case 0 { |

60 |
$split = 1 + int(rand($size - 2)); |

61 |
print WILL "("; |

62 |
print FACT "(and "; |

63 |
random_formula($split); |

64 |
print WILL " & "; |

65 |
random_formula ($size - $split - 1); |

66 |
print WILL ")"; |

67 |
print FACT ")"; |

68 |
} |

69 |
case 1 { |

70 |
$split = 1 + int(rand($size - 2)); |

71 |
print WILL "("; |

72 |
print FACT "(or "; |

73 |
random_formula($split); |

74 |
print WILL " v "; |

75 |
random_formula ($size - $split - 1); |

76 |
print WILL ")"; |

77 |
print FACT ")"; |

78 |
} |

79 |
case 2 { |

80 |
print WILL "(~"; |

81 |
print FACT "(not "; |

82 |
random_formula ($size -1); |

83 |
print WILL ")"; |

84 |
print FACT ")"; |

85 |
} |

86 |
case 3 { |

87 |
$n = int(rand($max_index)); |

88 |
print WILL "(<" . $n . ">"; |

89 |
print FACT "(min " . ($n+1) . " r "; |

90 |
random_formula($size-1); |

91 |
print WILL ")"; |

92 |
print FACT ")"; |

93 |
} |

94 |
} |

95 |
} |

96 |
} |

97 | |

98 |