@@ -31,11 +31,13 @@ import {
3131 writeJsonFile
3232} from './util.js' ;
3333import { fuzzing } from './fuzzing.js' ;
34- import { writeBddTemplate } from '../bdd/write-bdd-template.js' ;
34+ import { BDD_OPTIMIZE_STATE_LOCATION , writeBddTemplate } from '../bdd/write-bdd-template.js' ;
3535import {
3636 measurePerformanceOfStateFunctions ,
3737 getBetterBdd ,
38- getQualityOfBdd
38+ getQualityOfBdd ,
39+ PerformanceMeasurement ,
40+ QUALITY_BY_BDD_CACHE
3941} from './calculate-bdd-quality.js' ;
4042import { orderedStateList } from '../states/index.js' ;
4143
@@ -59,6 +61,17 @@ function loadTruthTable() {
5961 ) ;
6062 return truthTable ;
6163}
64+ function getQuality (
65+ bdd : RootNode ,
66+ perfMeasurement : PerformanceMeasurement
67+ ) {
68+ return getQualityOfBdd (
69+ bdd ,
70+ perfMeasurement ,
71+ getQueryVariations ( ) ,
72+ getTestProcedures ( )
73+ ) ;
74+ }
6275
6376
6477const unknownValueActionId : number = 42 ;
@@ -239,10 +252,14 @@ async function run() {
239252 bdd . removeIrrelevantLeafNodes ( unknownValueActionId ) ;
240253
241254 bdd . log ( ) ;
255+ const performanceMeasurement = await measurePerformanceOfStateFunctions ( 2000 )
256+ const quality = getQuality ( bdd , performanceMeasurement ) ;
242257
243258 const bddMinimalString = bddToMinimalString ( bdd ) ;
244259 writeBddTemplate (
245- bddMinimalString
260+ bddMinimalString ,
261+ performanceMeasurement ,
262+ quality
246263 ) ;
247264
248265 console . log ( 'nodes after minify: ' + bdd . countNodes ( ) ) ;
@@ -265,28 +282,16 @@ async function run() {
265282 unknownValueActionId
266283 ) ;
267284
268- let currentBest : RootNode ;
269-
270- const perfMeasurement = await measurePerformanceOfStateFunctions ( 10000 ) ;
271- console . log ( 'state function performance:' ) ;
272- console . dir ( perfMeasurement ) ;
273-
274285
286+ const optimizeState = JSON . parse ( fs . readFileSync ( BDD_OPTIMIZE_STATE_LOCATION , 'utf-8' ) ) ;
287+ const performanceMeasurement = optimizeState . performanceMeasurement ;
288+ let currentBest : RootNode ;
275289 const resolvers : ResolverFunctions = { } ;
276290 new Array ( orderedStateList . length ) . fill ( 0 ) . forEach ( ( _x , index ) => {
277291 const fn = ( state : string ) => booleanStringToBoolean ( ( state as any ) [ index ] ) ;
278292 resolvers [ index ] = fn ;
279293 } ) ;
280294
281- function getQuality ( bdd : RootNode ) {
282- return getQualityOfBdd (
283- bdd ,
284- perfMeasurement ,
285- getQueryVariations ( ) ,
286- getTestProcedures ( )
287- ) ;
288- }
289-
290295 await optimizeBruteForce ( {
291296 truthTable,
292297 iterations : 10000000 ,
@@ -313,12 +318,11 @@ async function run() {
313318 }
314319 }
315320
316-
317321 if ( currentBest ) {
318322 console . log (
319323 'current best bdd has ' + currentBest . countNodes ( ) + ' nodes ' +
320- 'and a quality of ' + getQuality ( currentBest ) + ' ' +
321- 'while newly tested one has quality of ' + getQuality ( bdd )
324+ 'and a quality of ' + getQuality ( currentBest , performanceMeasurement ) + ' ' +
325+ 'while newly tested one has quality of ' + getQuality ( bdd , performanceMeasurement )
322326 ) ;
323327 } else {
324328 currentBest = bdd ;
@@ -327,7 +331,7 @@ async function run() {
327331 compareResults : ( a : RootNode , b : RootNode ) => {
328332 const betterOne = getBetterBdd (
329333 a , b ,
330- perfMeasurement ,
334+ performanceMeasurement ,
331335 getQueryVariations ( ) ,
332336 getTestProcedures ( )
333337 ) ;
@@ -338,19 +342,27 @@ async function run() {
338342 console . log ( '## Yeah! found better bdd ##' ) ;
339343 lastBetterFoundTime = new Date ( ) . getTime ( ) ;
340344 const bddMinimalString = bddToMinimalString ( currentBest ) ;
341- const quality = getQuality ( currentBest ) ;
345+ const quality = getQuality ( currentBest , performanceMeasurement ) ;
342346 console . log ( 'nodes: ' + currentBest . countNodes ( ) ) ;
343347 console . log ( 'quality(new): ' + quality ) ;
344- console . log ( 'quality(old): ' + getQuality ( currentBest ) ) ;
348+ console . log ( 'quality(old): ' + getQuality ( currentBest , performanceMeasurement ) ) ;
345349 console . log ( 'new string: ' + bddMinimalString ) ;
346350 currentBest = res . bdd ;
347351
348- writeBddTemplate (
349- bddMinimalString
350- ) ;
351- console . log ( '-' . repeat ( 100 ) ) ;
352+ const currentOptimizeState = JSON . parse ( fs . readFileSync ( BDD_OPTIMIZE_STATE_LOCATION , 'utf-8' ) ) ;
353+ if ( quality > currentOptimizeState . quality ) {
354+ console . log ( '########## BETTER THEN BEFORE ! -> Save it' ) ;
355+ writeBddTemplate (
356+ bddMinimalString ,
357+ performanceMeasurement ,
358+ quality
359+ ) ;
360+ console . log ( '-' . repeat ( 100 ) ) ;
361+ } else {
362+ console . log ( '# DROP BECAUSE has better one with quality ' + currentOptimizeState . quality ) ;
363+ }
352364 } ,
353- log : true
365+ log : false
354366 } ) ;
355367 } ) ( ) ;
356368 break ;
0 commit comments