Commit 062045eb authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Speedup reduc.test by not spawning one process per formula.

* src/ltltest/reduc.cc: Add an option -f to read a lost of
formulae from a file.  Running a process for each formula was
too slow.  Also add an option -h to hide reduced formulae.
* src/ltltest/reduc.test: Simplify accordingly.
parent 7262dff0
2010-01-21 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Speedup reduc.test by not spawning one process per formula.
* src/ltltest/reduc.cc: Add an option -f to read a lost of
formulae from a file. Running a process for each formula was
too slow. Also add an option -h to hide reduced formulae.
* src/ltltest/reduc.test: Simplify accordingly.
2010-01-21 Alexandre Duret-Lutz <adl@lrde.epita.fr> 2010-01-21 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Move the last test from emptchk.test to emptchke.test. Move the last test from emptchk.test to emptchke.test.
......
// Copyright (C) 2004, 2006, 2007, 2008, 2009 Laboratoire // Copyright (C) 2008, 2009, 2010 Laboratoire de Recherche et Dveloppement
// d'Informatique de Paris 6 (LIP6), dpartement Systmes Rpartis // de l'Epita (LRDE).
// Coopratifs (SRC), Universit Pierre et Marie Curie. // Copyright (C) 2004, 2006, 2007 Laboratoire d'Informatique de Paris
// 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC),
// Universit Pierre et Marie Curie.
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
// //
...@@ -20,8 +22,11 @@ ...@@ -20,8 +22,11 @@
// 02111-1307, USA. // 02111-1307, USA.
#include <iostream> #include <iostream>
#include <fstream>
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <string>
#include <cstring>
#include "ltlparse/public.hh" #include "ltlparse/public.hh"
#include "ltlvisit/lunabbrev.hh" #include "ltlvisit/lunabbrev.hh"
#include "ltlvisit/tunabbrev.hh" #include "ltlvisit/tunabbrev.hh"
...@@ -43,9 +48,28 @@ syntax(char* prog) ...@@ -43,9 +48,28 @@ syntax(char* prog)
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
bool readfile = false;
bool hidereduc = false;
unsigned long sum_before = 0;
unsigned long sum_after = 0;
if (argc < 3) if (argc < 3)
syntax(argv[0]); syntax(argv[0]);
if (!strncmp(argv[1], "-f", 3))
{
readfile = true;
++argv;
--argc;
}
if (!strncmp(argv[1], "-h", 3))
{
hidereduc = true;
++argv;
--argc;
}
int o = spot::ltl::Reduce_None; int o = spot::ltl::Reduce_None;
switch (atoi(argv[1])) switch (atoi(argv[1]))
{ {
...@@ -109,104 +133,158 @@ main(int argc, char** argv) ...@@ -109,104 +133,158 @@ main(int argc, char** argv)
return 2; return 2;
} }
spot::ltl::parse_error_list p1; spot::ltl::formula* f1 = 0;
spot::ltl::formula* f1 = spot::ltl::parse(argv[2], p1);
spot::ltl::formula* f2 = 0; spot::ltl::formula* f2 = 0;
if (spot::ltl::format_parse_errors(std::cerr, argv[2], p1)) std::ifstream* fin = 0;
return 2;
if (readfile)
{
fin = new std::ifstream(argv[2]);
if (!*fin)
{
std::cerr << "Cannot open " << argv[2] << std::endl;
exit(2);
}
}
int exit_code = 0;
next_line:
if (fin)
{
std::string input;
do
{
if (!std::getline(*fin, input))
goto end;
}
while (input == "");
spot::ltl::parse_error_list p1;
f1 = spot::ltl::parse(input, p1);
if (spot::ltl::format_parse_errors(std::cerr, input, p1))
return 2;
}
else
{
spot::ltl::parse_error_list p1;
f1 = spot::ltl::parse(argv[2], p1);
if (spot::ltl::format_parse_errors(std::cerr, argv[2], p1))
return 2;
}
if (argc == 4) if (argc == 4)
{ {
if (readfile)
{
std::cerr << "Cannot read from file and check result." << std::endl;
exit(2);
}
spot::ltl::parse_error_list p2; spot::ltl::parse_error_list p2;
f2 = spot::ltl::parse(argv[3], p2); f2 = spot::ltl::parse(argv[3], p2);
if (spot::ltl::format_parse_errors(std::cerr, argv[3], p2)) if (spot::ltl::format_parse_errors(std::cerr, argv[3], p2))
return 2; return 2;
} }
int exit_code = 0; {
spot::ltl::formula* ftmp1;
spot::ltl::formula* ftmp2;
ftmp1 = f1;
f1 = unabbreviate_logic(f1);
ftmp2 = f1;
f1 = negative_normal_form(f1);
ftmp1->destroy();
ftmp2->destroy();
spot::ltl::formula* ftmp1;
spot::ltl::formula* ftmp2;
ftmp1 = f1; int length_f1_before = spot::ltl::length(f1);
f1 = unabbreviate_logic(f1); std::string f1s_before = spot::ltl::to_string(f1);
ftmp2 = f1;
f1 = negative_normal_form(f1);
ftmp1->destroy();
ftmp2->destroy();
ftmp1 = f1;
f1 = spot::ltl::reduce(f1, o);
ftmp2 = f1;
f1 = spot::ltl::unabbreviate_logic(f1);
ftmp1->destroy();
ftmp2->destroy();
int length_f1_before = spot::ltl::length(f1); int length_f1_after = spot::ltl::length(f1);
std::string f1s_before = spot::ltl::to_string(f1); std::string f1s_after = spot::ltl::to_string(f1);
ftmp1 = f1; std::string f2s = "";
f1 = spot::ltl::reduce(f1, o); if (f2)
ftmp2 = f1; {
f1 = spot::ltl::unabbreviate_logic(f1); ftmp1 = f2;
ftmp1->destroy(); f2 = unabbreviate_logic(f2);
ftmp2->destroy(); ftmp2 = f2;
f2 = negative_normal_form(f2);
ftmp1->destroy();
ftmp2->destroy();
ftmp1 = f2;
f2 = unabbreviate_logic(f2);
ftmp1->destroy();
f2s = spot::ltl::to_string(f2);
}
int length_f1_after = spot::ltl::length(f1); sum_before += length_f1_before;
std::string f1s_after = spot::ltl::to_string(f1); sum_after += length_f1_after;
bool red = (length_f1_after < length_f1_before); // If -h is set, we want to print only formulae that have become larger.
std::string f2s = ""; if (!f2 && (!hidereduc || (length_f1_after > length_f1_before)))
if (f2)
{ {
ftmp1 = f2; std::cout << length_f1_before << " " << length_f1_after
f2 = unabbreviate_logic(f2); << " '" << f1s_before << "' reduce to '" << f1s_after << "'"
ftmp2 = f2; << std::endl;
f2 = negative_normal_form(f2);
ftmp1->destroy();
ftmp2->destroy();
ftmp1 = f2;
f2 = unabbreviate_logic(f2);
ftmp1->destroy();
f2s = spot::ltl::to_string(f2);
} }
if ((red | !red) && !f2) if (f2)
{ {
std::cout << length_f1_before << " " << length_f1_after if (f1 != f2)
<< " '" << f1s_before << "' reduce to '" << f1s_after << "'" {
<< std::endl; if (length_f1_after < length_f1_before)
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " KOREDUC " << std::endl;
else
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " KOIDEM " << std::endl;
exit_code = 1;
}
else
{
if (f1s_before != f1s_after)
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " OKREDUC " << std::endl;
else
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " OKIDEM" << std::endl;
exit_code = 0;
}
}
else
{
if (length_f1_after > length_f1_before)
exit_code = 1;
}
f1->destroy();
if (f2)
f2->destroy();
if (fin)
goto next_line;
} }
end:
if (f2) if (fin)
{ {
if (f1 != f2) float before = sum_before;
{ float after = sum_after;
if (length_f1_after < length_f1_before) std::cout << "gain: "
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after << (1 - (after / before)) * 100 << "%" << std::endl;
<< " KOREDUC " << std::endl;
else
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " KOIDEM " << std::endl;
exit_code = 1;
}
else
{
if (f1s_before != f1s_after)
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " OKREDUC " << std::endl;
else
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after
<< " OKIDEM" << std::endl;
exit_code = 0;
}
} }
else
{
if (length_f1_after < length_f1_before)
exit_code = 0;
}
f1->destroy();
if (f2)
f2->destroy();
assert(spot::ltl::atomic_prop::instance_count() == 0); assert(spot::ltl::atomic_prop::instance_count() == 0);
assert(spot::ltl::unop::instance_count() == 0); assert(spot::ltl::unop::instance_count() == 0);
......
#! /bin/sh #! /bin/sh
# Copyright (C) 2004, 2005, 2006, 2009 Laboratoire d'Informatique de # Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement de
# Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC), # l'Epita (LRDE).
# Universit Pierre et Marie Curie. # Copyright (C) 2004, 2005, 2006 Laboratoire d'Informatique de Paris 6
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
# Pierre et Marie Curie.
# #
# This file is part of Spot, a model checking library. # This file is part of Spot, a model checking library.
# #
...@@ -34,24 +36,11 @@ for i in 10 12 14 16 18 20; do ...@@ -34,24 +36,11 @@ for i in 10 12 14 16 18 20; do
run 0 ../randltl -u -s 100 -f $i a b c d e f -F 100 >> $FILE run 0 ../randltl -u -s 100 -f $i a b c d e f -F 100 >> $FILE
done done
for opt in 0 1 2 3 7 8 9; do for opt in 0 1 2 3 7; do
rm -f result.data run 0 ../reduc -f -h $opt "$FILE"
done
cat $FILE | # Running the above through valgrind is quite slow already.
while read f; do # Don't use valgrind for the next reductions (even slower).
../reduc $opt "$f" >> result.data for opt in 8 9; do
done ../reduc -f -h $opt "$FILE"
test $? = 0 || exit 1
perl -ne 'BEGIN { $sum1 = 0; $sum2 = 0; }
/^(\d+)\s+(\d+)/;
$sum1 += $1;
$sum2 += $2;
END { print 100 - ($sum2 * 100 / $sum1); print "\n"; }
' < result.data
done done
rm -f result.data
rm -f $FILE
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment