@@ -62,6 +62,114 @@ bool Verifier::VerifyList()
62
62
return true ;
63
63
}
64
64
65
- // bool VerifyInputCover();
65
+ bool forAllAssignments (Set<BVar>& fixed,
66
+ Set<BVar>& remaining,
67
+ function<bool (const Set<BVar>&) callback)
68
+ {
69
+ if (remaining.empty ())
70
+ {
71
+ return callback (fixed);
72
+ }
73
+ else
74
+ {
75
+ BVar pivot = *remaining.begin ();
76
+
77
+ remaining.erase (remaining.begin ());
78
+
79
+ bool result = forAllAssignments (fixed, remaining, callback);
80
+
81
+ if (result)
82
+ {
83
+ fixed.insert (pivot);
84
+
85
+ result = forAllAssignments (fixed, remaining, callback);
86
+
87
+ fixed.erase (fixed.find (pivot));
88
+ }
89
+
90
+ remaining.insert (pivot);
91
+
92
+ return result;
93
+ }
94
+ }
95
+
96
+ bool VerifyInputCover () const
97
+ {
98
+ Set<BVar> inputVars = f.inputVars ();
99
+ Set<BVar> potentialAssignment;
100
+
101
+ forAllAssignments (inputVars, potentialAssignment,
102
+ [&f1] (const Set<BVar>& assignment) {
103
+
104
+ }
105
+
106
+ /* *
107
+ * Uses the given RNG to select a random subset of the given set of variables.
108
+ */
109
+ Set<BVar> randomSubset (const Set<BVar>& vars,
110
+ const mt19937& rng)
111
+ {
112
+ /* Generates booleans with equal probability */
113
+ bernoulli_distribution dist (0.5 );
114
+
115
+ Set<BVar> subset;
116
+
117
+ for (BVar var : vars)
118
+ {
119
+ if (dist (rng))
120
+ subset.insert (var);
121
+ }
66
122
67
- // bool RandomVerifyInputCover();
123
+ return subset;
124
+ }
125
+
126
+
127
+
128
+ bool RandomVerifyInputCover () const
129
+ {
130
+ cout << " === Verifying coverage ===" << endl;
131
+
132
+ /* Initialize random generation */
133
+ random_device rd;
134
+ mt19937 rng (rd ());
135
+
136
+ size_t sampleSize = 100 ; // number of sample assignments taken
137
+ bool ok = true ; // is set to false when verification fails
138
+
139
+ for (size_t i = 0 ; i < sampleSize; i++)
140
+ {
141
+ /* Generates random assignment to the x variables */
142
+ Set<BVar> inputAssignment = randomSubset (f.inputVars (), rng);
143
+
144
+ cout << " Random input: " ;
145
+ print (inputAssignment, " x" );
146
+ cout << endl;
147
+
148
+ /* Set of z variables activated by the given input */
149
+ Set<BVar> outputAssignment = f1.eval (inputAssignment);
150
+
151
+ cout << " Activated variables: " ;
152
+ print (outputAssignment, " z" );
153
+ cout << endl;
154
+
155
+ bool inputIsCovered = false ;
156
+
157
+ /* Look for an MSS that covers the assignment */
158
+ for (const Set<BVar>& mss : mssList)
159
+ {
160
+ if (isSubset (outputAssignment, mss))
161
+ {
162
+ cout << " MSS covering this input: " ;
163
+ print (setDifference (mss, spec.outputVars ()), " z" ); // remove y variables from MSS for printing
164
+ cout << endl;
165
+
166
+ inputIsCovered = true ;
167
+ break ;
168
+ }
169
+ }
170
+
171
+ ok &= inputIsCovered;
172
+ }
173
+
174
+ return ok;
175
+ }
0 commit comments