From 3db80dc65b18355b719e8d56032400c753aa4eb7 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 23 Apr 2009 21:09:12 -0700 Subject: [PATCH] model-checker: Kill dependencies and move back to libpspp. Commit 95b074ff3 "Moved the datasheet testing code out of src/{libspp,data}" moved the model-checker implementation from libpspp into language/tests because it depended on math/moments.h and data/val-type.h, which violates the dependency structure of the PSPP libraries. However, now I want to use the model checker in a test that should not need to use anything from language/tests, so this commit eliminates these dependencies and moves the model checker back to src/libpspp. --- src/language/tests/automake.mk | 2 -- src/language/tests/check-model.q | 4 ++-- src/language/tests/datasheet-check.c | 2 +- src/libpspp/automake.mk | 2 ++ .../tests => libpspp}/model-checker.c | 21 +++++++++---------- .../tests => libpspp}/model-checker.h | 0 6 files changed, 15 insertions(+), 16 deletions(-) rename src/{language/tests => libpspp}/model-checker.c (98%) rename src/{language/tests => libpspp}/model-checker.h (100%) diff --git a/src/language/tests/automake.mk b/src/language/tests/automake.mk index 54d95107..6268422e 100644 --- a/src/language/tests/automake.mk +++ b/src/language/tests/automake.mk @@ -11,8 +11,6 @@ language_tests_sources = \ src/language/tests/format-guesser-test.c \ src/language/tests/float-format.c \ src/language/tests/moments-test.c \ - src/language/tests/model-checker.c \ - src/language/tests/model-checker.h \ src/language/tests/paper-size.c \ src/language/tests/pool-test.c diff --git a/src/language/tests/check-model.q b/src/language/tests/check-model.q index b1f44ffa..2f7b34df 100644 --- a/src/language/tests/check-model.q +++ b/src/language/tests/check-model.q @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ #include -#include #include +#include #include "error.h" #include "fwriteerror.h" diff --git a/src/language/tests/datasheet-check.c b/src/language/tests/datasheet-check.c index cb2732bc..53b62c31 100644 --- a/src/language/tests/datasheet-check.c +++ b/src/language/tests/datasheet-check.c @@ -18,7 +18,6 @@ #include #include "datasheet-check.h" -#include "model-checker.h" #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libpspp/automake.mk b/src/libpspp/automake.mk index dc512bb2..1564569c 100644 --- a/src/libpspp/automake.mk +++ b/src/libpspp/automake.mk @@ -47,6 +47,8 @@ src_libpspp_libpspp_la_SOURCES = \ src/libpspp/message.h \ src/libpspp/misc.c \ src/libpspp/misc.h \ + src/libpspp/model-checker.c \ + src/libpspp/model-checker.h \ src/libpspp/msg-locator.c \ src/libpspp/msg-locator.h \ src/libpspp/pool.c \ diff --git a/src/language/tests/model-checker.c b/src/libpspp/model-checker.c similarity index 98% rename from src/language/tests/model-checker.c rename to src/libpspp/model-checker.c index a0407500..1f83266a 100644 --- a/src/language/tests/model-checker.c +++ b/src/libpspp/model-checker.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ #include -#include "model-checker.h" +#include #include #include @@ -26,12 +26,11 @@ #include #include -#include #include #include #include +#include #include -#include #include "error.h" #include "minmax.h" @@ -620,7 +619,8 @@ struct mc_results /* Depth statistics. */ int max_depth_reached; /* Max depth state examined. */ - struct moments1 *depth_moments; /* Enables reporting mean depth. */ + unsigned long int depth_sum; /* Sum of depths. */ + int n_depths; /* Number of depths in depth_sum. */ /* If error_count > 0, path to the last error reported. */ struct mc_path error_path; @@ -646,7 +646,6 @@ mc_results_create (void) { struct mc_results *results = xcalloc (1, sizeof (struct mc_results)); results->stop_reason = MC_CONTINUING; - results->depth_moments = moments1_create (MOMENT_MEAN); gettimeofday (&results->start, NULL); return results; } @@ -657,7 +656,6 @@ mc_results_destroy (struct mc_results *results) { if (results != NULL) { - moments1_destroy (results->depth_moments); mc_path_destroy (&results->error_path); free (results); } @@ -726,9 +724,9 @@ mc_results_get_max_depth_reached (const struct mc_results *results) double mc_results_get_mean_depth_reached (const struct mc_results *results) { - double mean; - moments1_calculate (results->depth_moments, NULL, &mean, NULL, NULL, NULL); - return mean != SYSMIS ? mean : 0.0; + return (results->n_depths == 0 + ? 0 + : (double) results->depth_sum / results->n_depths); } /* Returns the path traversed to obtain the last error @@ -1200,7 +1198,8 @@ enqueue_state (struct mc *mc, struct mc_state *new) if (new->path.length > mc->results->max_depth_reached) mc->results->max_depth_reached = new->path.length; - moments1_add (mc->results->depth_moments, new->path.length, 1.0); + mc->results->depth_sum += new->path.length; + mc->results->n_depths++; if (deque_count (&mc->queue_deque) < mc->options->queue_limit) { diff --git a/src/language/tests/model-checker.h b/src/libpspp/model-checker.h similarity index 100% rename from src/language/tests/model-checker.h rename to src/libpspp/model-checker.h -- 2.30.2