* src/tgbaalgos/randomgraph.cc (random_graph): Make sure n > 0.

* src/tgbatest/randtgba.cc: Check the range of all arguments.
This commit is contained in:
Alexandre Duret-Lutz 2005-02-02 16:03:31 +00:00
parent f22b59bf95
commit 5533e9dc35
4 changed files with 58 additions and 14 deletions

View file

@ -1,5 +1,8 @@
2005-02-02 Alexandre Duret-Lutz <adl@src.lip6.fr> 2005-02-02 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/tgbaalgos/randomgraph.cc (random_graph): Make sure n > 0.
* src/tgbatest/randtgba.cc: Check the range of all arguments.
* bench/emptchk/models/eeaean1.pml: New file, from schwoon.05.tacas. * bench/emptchk/models/eeaean1.pml: New file, from schwoon.05.tacas.
* bench/emptchk/Makefile.am: Distribute models/eeaean1.pml * bench/emptchk/Makefile.am: Distribute models/eeaean1.pml
and build models/eeaean1.tgba. and build models/eeaean1.tgba.

View file

@ -1,4 +1,4 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie. // et Marie Curie.
// //
@ -94,6 +94,7 @@ namespace spot
int n_acc, float a, float t, int n_acc, float a, float t,
ltl::environment* env) ltl::environment* env)
{ {
assert(n > 0);
tgba_explicit* res = new tgba_explicit(dict); tgba_explicit* res = new tgba_explicit(dict);
int props_n = ap->size(); int props_n = ap->size();

View file

@ -1,4 +1,4 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie. // et Marie Curie.
// //
@ -33,7 +33,7 @@ namespace spot
/// \brief Construct a tgba randomly. /// \brief Construct a tgba randomly.
/// \ingroup tgba_misc /// \ingroup tgba_misc
/// ///
/// \param n The number of states wanted in the automata. All states /// \param n The number of states wanted in the automata (>0). All states
/// will be connected, and there will be no dead state. /// will be connected, and there will be no dead state.
/// \param d The density of the automata. This is the probability /// \param d The density of the automata. This is the probability
/// (between 0.0 and 1.0), to add a transition between two /// (between 0.0 and 1.0), to add a transition between two

View file

@ -214,6 +214,7 @@ syntax(char* prog)
exit(2); exit(2);
} }
int int
to_int(const char* s) to_int(const char* s)
{ {
@ -227,6 +228,32 @@ to_int(const char* s)
return res; return res;
} }
int
to_int_pos(const char* s, const char* arg)
{
int res = to_int(s);
if (res <= 0)
{
std::cerr << "argument of " << arg
<< " (" << res << ") must be positive" << std::endl;
exit(1);
}
return res;
}
int
to_int_nonneg(const char* s, const char* arg)
{
int res = to_int(s);
if (res < 0)
{
std::cerr << "argument of " << arg
<< " (" << res << ") must be nonnegative" << std::endl;
exit(1);
}
return res;
}
float float
to_float(const char* s) to_float(const char* s)
{ {
@ -241,6 +268,19 @@ to_float(const char* s)
return res; return res;
} }
float
to_float_nonneg(const char* s, const char* arg)
{
float res = to_float(s);
if (res < 0)
{
std::cerr << "argument of " << arg
<< " (" << res << ") must be nonnegative" << std::endl;
exit(1);
}
return res;
}
struct ec_stat struct ec_stat
{ {
int max_tgba_states; int max_tgba_states;
@ -1086,14 +1126,14 @@ main(int argc, char** argv)
{ {
if (argc < argn + 3) if (argc < argn + 3)
syntax(argv[0]); syntax(argv[0]);
opt_n_acc = to_int(argv[++argn]); opt_n_acc = to_int_nonneg(argv[++argn], "-a");
opt_a = to_float(argv[++argn]); opt_a = to_float_nonneg(argv[++argn], "-a");
} }
else if (!strcmp(argv[argn], "-d")) else if (!strcmp(argv[argn], "-d"))
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_d = to_float(argv[++argn]); opt_d = to_float_nonneg(argv[++argn], "-d");
} }
else if (!strcmp(argv[argn], "-D")) else if (!strcmp(argv[argn], "-D"))
{ {
@ -1105,7 +1145,7 @@ main(int argc, char** argv)
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_ec = to_int(argv[++argn]); opt_ec = to_int_nonneg(argv[++argn], "-e");
} }
else if (!strcmp(argv[argn], "-g")) else if (!strcmp(argv[argn], "-g"))
{ {
@ -1140,7 +1180,7 @@ main(int argc, char** argv)
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_n = to_int(argv[++argn]); opt_n = to_int_pos(argv[++argn], "-n");
} }
else if (!strcmp(argv[argn], "-O")) else if (!strcmp(argv[argn], "-O"))
{ {
@ -1171,20 +1211,20 @@ main(int argc, char** argv)
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_R = to_int(argv[++argn]); opt_R = to_int_pos(argv[++argn], "-R");
} }
else if (!strcmp(argv[argn], "-s")) else if (!strcmp(argv[argn], "-s"))
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_ec_seed = to_int(argv[++argn]); opt_ec_seed = to_int_nonneg(argv[++argn], "-s");
spot::srand(opt_ec_seed); spot::srand(opt_ec_seed);
} }
else if (!strcmp(argv[argn], "-t")) else if (!strcmp(argv[argn], "-t"))
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_t = to_float(argv[++argn]); opt_t = to_float_nonneg(argv[++argn], "-t");
} }
else if (!strcmp(argv[argn], "-z")) else if (!strcmp(argv[argn], "-z"))
{ {
@ -1202,13 +1242,13 @@ main(int argc, char** argv)
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_f = to_int(argv[++argn]); opt_f = to_int_pos(argv[++argn], "-f");
} }
else if (!strcmp(argv[argn], "-F")) else if (!strcmp(argv[argn], "-F"))
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_F = to_int(argv[++argn]); opt_F = to_int_nonneg(argv[++argn], "-F");
} }
else if (!strcmp(argv[argn], "-p")) else if (!strcmp(argv[argn], "-p"))
{ {
@ -1220,7 +1260,7 @@ main(int argc, char** argv)
{ {
if (argc < argn + 2) if (argc < argn + 2)
syntax(argv[0]); syntax(argv[0]);
opt_l = to_int(argv[++argn]); opt_l = to_int_nonneg(argv[++argn], "-l");
} }
else if (!strcmp(argv[argn], "-u")) else if (!strcmp(argv[argn], "-u"))
{ {