Some cleanup of Thibaud's patches.
* AUTHORS: Add Thibaud. * NEWS: Mention ltlgrind and ltlcross --grind. * src/ltlvisit/mutation.hh, src/ltlvisit/mutation.cc: Use an enum instead of #define. Rename get_mutations() into mutate(). Other minor cosmetic changes. * src/bin/ltlgrind.cc: Adjust. * src/bin/ltlcross.cc: Slight changes the the output * doc/org/ltlcross.org, doc/org/ltlgrind.org: Minor rewordings and fix for org-mode syntax. * src/ltltest/ltlcrossgrind.test, src/ltltest/ltlgrind.test: Fix copyright year.
This commit is contained in:
parent
4e1586dc54
commit
645ecce1c9
10 changed files with 325 additions and 141 deletions
|
|
@ -1307,25 +1307,31 @@ namespace
|
|||
unsigned mutation_max;
|
||||
while (res)
|
||||
{
|
||||
std::cerr << "Trying to find a bogus mutation of \"" << bogus <<
|
||||
"\"" << std::endl;
|
||||
std::vector<const spot::ltl::formula*>::iterator it;
|
||||
std::cerr << "Trying to find a bogus mutation of ";
|
||||
if (color_opt)
|
||||
std::cerr << bright_blue;
|
||||
std::cerr << bogus;
|
||||
if (color_opt)
|
||||
std::cerr << reset_color;
|
||||
std::cerr << "...\n";
|
||||
|
||||
mutations = get_mutations(f);
|
||||
mutations = mutate(f);
|
||||
mutation_count = 1;
|
||||
mutation_max = mutations.size();
|
||||
res = 0;
|
||||
for (it = mutations.begin(); it != mutations.end() && !res; ++it)
|
||||
for (auto g: mutations)
|
||||
{
|
||||
std::cerr << "Mutation [" << mutation_count << '/'
|
||||
<< mutation_max << ']' << std::endl;
|
||||
std::cerr << "Mutation " << mutation_count << '/'
|
||||
<< mutation_max << ": ";
|
||||
f->destroy();
|
||||
f = (*it)->clone();
|
||||
res = process_formula(*it);
|
||||
f = g->clone();
|
||||
res = process_formula(g->clone());
|
||||
if (res)
|
||||
break;
|
||||
++mutation_count;
|
||||
}
|
||||
for (; it != mutations.end(); ++it)
|
||||
(*it)->destroy();
|
||||
for (auto g: mutations)
|
||||
g->destroy();
|
||||
if (res)
|
||||
{
|
||||
if (lbt_input)
|
||||
|
|
@ -1336,18 +1342,19 @@ namespace
|
|||
*bogus_output << bogus << std::endl;
|
||||
}
|
||||
}
|
||||
std::cerr << "The smallest bogus mutation found for ";
|
||||
std::cerr << "Smallest bogus mutation found for ";
|
||||
if (color_opt)
|
||||
std::cerr << bright_blue;
|
||||
std::cerr << input;
|
||||
if (color_opt)
|
||||
std::cerr << reset_color;
|
||||
std::cerr << " was ";
|
||||
std::cerr << " is ";
|
||||
if (color_opt)
|
||||
std::cerr << bright_blue;
|
||||
std::cerr << bogus << std::endl << std::endl;
|
||||
std::cerr << bogus;
|
||||
if (color_opt)
|
||||
std::cerr << reset_color;
|
||||
std::cerr << ".\n\n";
|
||||
*grind_output << bogus << std::endl;
|
||||
}
|
||||
f->destroy();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2014 Laboratoire de Recherche et Développement de
|
||||
// l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "common_sys.hh"
|
||||
#include <argp.h>
|
||||
#include <limits>
|
||||
#include "common_setup.hh"
|
||||
#include "common_finput.hh"
|
||||
#include "common_output.hh"
|
||||
|
|
@ -41,24 +40,25 @@
|
|||
#define OPT_SORT 8
|
||||
|
||||
static unsigned mutation_nb = 1;
|
||||
static int max_output = std::numeric_limits<int>::max();
|
||||
static unsigned max_output = -1U;
|
||||
|
||||
static unsigned opt_all = 0xfff;
|
||||
static unsigned opt_all = spot::ltl::Mut_All;
|
||||
static unsigned mut_opts = 0;
|
||||
static bool opt_sort = false;
|
||||
|
||||
const char * argp_program_doc = "List formulas that are similar to but " \
|
||||
"simpler than a given formula.";
|
||||
static const char * argp_program_doc =
|
||||
"List formulas that are similar to but simpler than a given formula.";
|
||||
|
||||
static const argp_option options[] = {
|
||||
{"mutations", 'm', "N", 0, "number of mutations to apply to the " \
|
||||
"formulae (default: 1)", -1},
|
||||
{"sort", OPT_SORT, 0, 0, "sort the result by formula size", 0},
|
||||
{0, 0, 0, 0, "Transformation rules:", 15},
|
||||
{0, 0, 0, 0, "Mutation rules (all enabled unless those options are used):",
|
||||
15},
|
||||
{"ap-to-const", OPT_AP2CONST, 0, 0,
|
||||
"atomic propositions are replaced with true/false", 15},
|
||||
{"remove-one-ap", OPT_REMOVE_ONE_AP, 0, 0,
|
||||
"all occurrences of an atomic proposition are replaced with another" \
|
||||
"all occurrences of an atomic proposition are replaced with another " \
|
||||
"atomic proposition used in the formula", 15},
|
||||
{"remove-multop-operands", OPT_REMOVE_MULTOP_OPERANDS, 0, 0,
|
||||
"remove one operand from multops", 15},
|
||||
|
|
@ -75,8 +75,7 @@ static const argp_option options[] = {
|
|||
"a W b, etc.", 0},
|
||||
{"simplify-bounds", OPT_SIMPLIFY_BOUNDS, 0, 0,
|
||||
"on a bounded unary operator, decrement one of the bounds, or set min to " \
|
||||
"0 or max to " \
|
||||
"unbounded.", 15},
|
||||
"0 or max to unbounded", 15},
|
||||
{0, 0, 0, 0, "Output options:", 20},
|
||||
{"max-output", 'n', "N", 0, "maximum number of mutations to output", 20},
|
||||
{0, 0, 0, 0, "Miscellaneous options:", -1},
|
||||
|
|
@ -112,25 +111,21 @@ to_unsigned (const char *s)
|
|||
|
||||
namespace
|
||||
{
|
||||
using namespace spot::ltl;
|
||||
|
||||
class mutate_processor:
|
||||
public job_processor
|
||||
{
|
||||
public:
|
||||
int
|
||||
process_formula(const formula* f, const char *filename = 0,
|
||||
process_formula(const spot::ltl::formula* f, const char *filename = 0,
|
||||
int linenum = 0)
|
||||
{
|
||||
std::vector<const formula*> mutations =
|
||||
get_mutations(f, mut_opts, opt_sort, max_output, mutation_nb);
|
||||
|
||||
auto mutations =
|
||||
spot::ltl::mutate(f, mut_opts, max_output, mutation_nb, opt_sort);
|
||||
f->destroy();
|
||||
std::vector<const formula*>::iterator it;
|
||||
for (it = mutations.begin(); it != mutations.end(); ++it)
|
||||
for (auto g: mutations)
|
||||
{
|
||||
output_formula_checked(*it, filename, linenum);
|
||||
(*it)->destroy();
|
||||
output_formula_checked(g, filename, linenum);
|
||||
g->destroy();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -150,31 +145,31 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
break;
|
||||
case OPT_AP2CONST:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_AP2CONST;
|
||||
mut_opts |= spot::ltl::Mut_Ap2Const;
|
||||
break;
|
||||
case OPT_REMOVE_ONE_AP:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_REMOVE_ONE_AP;
|
||||
mut_opts |= spot::ltl::Mut_Remove_One_Ap;
|
||||
break;
|
||||
case OPT_REMOVE_MULTOP_OPERANDS:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_REMOVE_MULTOP_OPERANDS;
|
||||
mut_opts |= spot::ltl::Mut_Remove_Multop_Operands;
|
||||
break;
|
||||
case OPT_REMOVE_OPS:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_REMOVE_OPS;
|
||||
mut_opts |= spot::ltl::Mut_Remove_Ops;
|
||||
break;
|
||||
case OPT_SPLIT_OPS:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_SPLIT_OPS;
|
||||
mut_opts |= spot::ltl::Mut_Split_Ops;
|
||||
break;
|
||||
case OPT_REWRITE_OPS:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_REWRITE_OPS;
|
||||
mut_opts |= spot::ltl::Mut_Rewrite_Ops;
|
||||
break;
|
||||
case OPT_SIMPLIFY_BOUNDS:
|
||||
opt_all = 0;
|
||||
mut_opts |= MUT_SIMPLIFY_BOUNDS;
|
||||
mut_opts |= spot::ltl::Mut_Simplify_Bounds;
|
||||
break;
|
||||
case OPT_SORT:
|
||||
opt_sort = true;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#! /bin/sh
|
||||
# Copyright (C) 2013 Laboratoire de Recherche et Developement to
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2014 Laboratoire de Recherche et Dévelopement to
|
||||
# l'Epita (LRDE).
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#! /bin/sh
|
||||
# Copyright (C) 2013 Laboratoire de Recherche et Developement to
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2014 Laboratoire de Recherche et Dévelopement to
|
||||
# l'Epita (LRDE).
|
||||
#
|
||||
# This file is part of Spot, a model checking library.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (C) 2013 Laboratoire de Recherche et Developpement de
|
||||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2014 Laboratoire de Recherche et Developpement de
|
||||
// l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -26,17 +27,17 @@
|
|||
#include "ltlvisit/length.hh"
|
||||
#include "misc/hash.hh"
|
||||
|
||||
#define Implies_(x, y) \
|
||||
#define Implies_(x, y) \
|
||||
spot::ltl::binop::instance(spot::ltl::binop::Implies, (x), (y))
|
||||
#define And_(x, y) \
|
||||
#define And_(x, y) \
|
||||
spot::ltl::multop::instance(spot::ltl::multop::And, (x), (y))
|
||||
#define AndRat_(x, y) \
|
||||
#define AndRat_(x, y) \
|
||||
spot::ltl::multop::instance(spot::ltl::multop::AndRat, (x), (y))
|
||||
#define AndNLM_(x) \
|
||||
#define AndNLM_(x) \
|
||||
spot::ltl::multop::instance(spot::ltl::multop::AndNLM, (x))
|
||||
#define Concat_(x, y) \
|
||||
#define Concat_(x, y) \
|
||||
spot::ltl::multop::instance(spot::ltl::multop::Concat, (x), (y))
|
||||
#define Not_(x) \
|
||||
#define Not_(x) \
|
||||
spot::ltl::unop::instance(spot::ltl::unop::Not, (x))
|
||||
|
||||
namespace spot
|
||||
|
|
@ -50,15 +51,16 @@ namespace spot
|
|||
public:
|
||||
void visit(const atomic_prop* ap)
|
||||
{
|
||||
if (ap == (*ap1_))
|
||||
result_ = (*ap2_)->clone();
|
||||
if (ap == ap1_)
|
||||
result_ = ap2_->clone();
|
||||
else
|
||||
result_ = ap->clone();
|
||||
}
|
||||
|
||||
const formula*
|
||||
replace(const formula* f,
|
||||
atomic_prop_set::iterator ap1, atomic_prop_set::iterator ap2)
|
||||
const atomic_prop* ap1,
|
||||
const atomic_prop* ap2)
|
||||
{
|
||||
ap1_ = ap1;
|
||||
ap2_ = ap2;
|
||||
|
|
@ -66,8 +68,8 @@ namespace spot
|
|||
}
|
||||
|
||||
private:
|
||||
atomic_prop_set::iterator ap1_;
|
||||
atomic_prop_set::iterator ap2_;
|
||||
const atomic_prop* ap1_;
|
||||
const atomic_prop* ap2_;
|
||||
};
|
||||
|
||||
typedef std::vector<const formula*> vec;
|
||||
|
|
@ -81,7 +83,7 @@ namespace spot
|
|||
void visit(const atomic_prop* ap)
|
||||
{
|
||||
result_ = 0;
|
||||
if (opts_ & MUT_AP2CONST)
|
||||
if (opts_ & Mut_Ap2Const)
|
||||
{
|
||||
if (mutation_counter_-- == 0)
|
||||
result_ = constant::true_instance();
|
||||
|
|
@ -95,7 +97,7 @@ namespace spot
|
|||
void visit(const unop* uo)
|
||||
{
|
||||
result_ = 0;
|
||||
if (opts_ & MUT_REMOVE_OPS)
|
||||
if (opts_ & Mut_Remove_Ops)
|
||||
{
|
||||
if ((uo->op() == unop::G
|
||||
|| uo->op() == unop::F
|
||||
|
|
@ -121,11 +123,11 @@ namespace spot
|
|||
const formula* second = bo->second();
|
||||
result_ = 0;
|
||||
|
||||
if (opts_ & MUT_REMOVE_OPS && mutation_counter_-- == 0)
|
||||
if (opts_ & Mut_Remove_Ops && mutation_counter_-- == 0)
|
||||
result_ = first->clone();
|
||||
if (opts_ & MUT_REMOVE_OPS && mutation_counter_-- == 0)
|
||||
if (opts_ & Mut_Remove_Ops && mutation_counter_-- == 0)
|
||||
result_ = second->clone();
|
||||
if (opts_ & MUT_REWRITE_OPS)
|
||||
if (opts_ & Mut_Rewrite_Ops)
|
||||
{
|
||||
switch (bo->op())
|
||||
{
|
||||
|
|
@ -151,7 +153,7 @@ namespace spot
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (opts_ & MUT_SPLIT_OPS)
|
||||
if (opts_ & Mut_Split_Ops)
|
||||
{
|
||||
switch (bo->op())
|
||||
{
|
||||
|
|
@ -191,9 +193,9 @@ namespace spot
|
|||
const formula* c = bu->child()->clone();
|
||||
result_ = 0;
|
||||
|
||||
if (opts_ & MUT_REMOVE_OPS && mutation_counter_-- == 0)
|
||||
if (opts_ & Mut_Remove_Ops && mutation_counter_-- == 0)
|
||||
result_ = c->clone();
|
||||
if (opts_ & MUT_SIMPLIFY_BOUNDS)
|
||||
if (opts_ & Mut_Simplify_Bounds)
|
||||
{
|
||||
if (bu->min() > 0 && mutation_counter_-- == 0)
|
||||
result_ =
|
||||
|
|
@ -225,14 +227,14 @@ namespace spot
|
|||
int i;
|
||||
result_ = 0;
|
||||
|
||||
if (opts_ & MUT_REMOVE_MULTOP_OPERANDS)
|
||||
if (opts_ & Mut_Remove_Multop_Operands)
|
||||
{
|
||||
for (i = 0; i < mos; ++i)
|
||||
if (mutation_counter_-- == 0)
|
||||
result_ = mo->all_but(i);
|
||||
}
|
||||
|
||||
if (opts_ & MUT_SPLIT_OPS && mo->op() == multop::AndNLM)
|
||||
if (opts_ & Mut_Split_Ops && mo->op() == multop::AndNLM)
|
||||
{
|
||||
if (mutation_counter_ >= 0 && mutation_counter_ < 2 * (mos - 1))
|
||||
{
|
||||
|
|
@ -323,7 +325,7 @@ namespace spot
|
|||
|
||||
void
|
||||
single_mutation_rec(const formula* f, fset_t& mutations, unsigned opts,
|
||||
int& n, unsigned m)
|
||||
unsigned& n, unsigned m)
|
||||
{
|
||||
if (m == 0)
|
||||
{
|
||||
|
|
@ -348,7 +350,7 @@ namespace spot
|
|||
|
||||
void
|
||||
replace_ap_rec(const formula* f, fset_t& mutations, unsigned opts,
|
||||
int& n, unsigned m)
|
||||
unsigned& n, unsigned m)
|
||||
{
|
||||
if (m == 0)
|
||||
{
|
||||
|
|
@ -360,35 +362,34 @@ namespace spot
|
|||
}
|
||||
else
|
||||
{
|
||||
const formula* mut;
|
||||
if (!n)
|
||||
return;
|
||||
replace_visitor rv;
|
||||
std::unique_ptr<atomic_prop_set> aps =
|
||||
std::unique_ptr<atomic_prop_set>(atomic_prop_collect(f));
|
||||
atomic_prop_set::iterator ap1;
|
||||
atomic_prop_set::iterator ap2;
|
||||
for (ap1 = aps->begin(); ap1 != aps->end() && n > 0; ++ap1)
|
||||
for (ap2 = aps->begin(); ap2 != aps->end() && n > 0; ++ap2)
|
||||
auto aps =
|
||||
std::unique_ptr<atomic_prop_set>(atomic_prop_collect(f));
|
||||
for (auto ap1: *aps)
|
||||
for (auto ap2: *aps)
|
||||
{
|
||||
if (ap1 == ap2)
|
||||
continue;
|
||||
mut = rv.replace(f, ap1, ap2);
|
||||
auto mut = rv.replace(f, ap1, ap2);
|
||||
replace_ap_rec(mut, mutations, opts, n, m - 1);
|
||||
mut->destroy();
|
||||
if (!n)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec get_mutations(const formula* f,
|
||||
unsigned opts,
|
||||
bool sort,
|
||||
int n,
|
||||
unsigned m)
|
||||
std::vector<const formula*>
|
||||
mutate(const formula* f, unsigned opts, unsigned max_output,
|
||||
unsigned mutation_count, bool sort)
|
||||
{
|
||||
fset_t mutations;
|
||||
single_mutation_rec(f, mutations, opts, n, m);
|
||||
if (opts & MUT_REMOVE_ONE_AP)
|
||||
replace_ap_rec(f, mutations, opts, n, m);
|
||||
single_mutation_rec(f, mutations, opts, max_output, mutation_count);
|
||||
if (opts & Mut_Remove_One_Ap)
|
||||
replace_ap_rec(f, mutations, opts, max_output, mutation_count);
|
||||
|
||||
vec res(mutations.begin(), mutations.end());
|
||||
if (sort)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2009, 2010, 2012, 2013, 2014 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
// Copyright (C) 2014 Laboratoire de Recherche et Développement de
|
||||
// l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -24,29 +21,31 @@
|
|||
# define SPOT_LTLVISIT_MUTATION_HH
|
||||
|
||||
#include "ltlast/formula.hh"
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#define MUT_AP2CONST 0x1
|
||||
#define MUT_SIMPLIFY_BOUNDS 0x2
|
||||
#define MUT_REMOVE_MULTOP_OPERANDS 0x4
|
||||
#define MUT_REMOVE_OPS 0x8
|
||||
#define MUT_SPLIT_OPS 0x10
|
||||
#define MUT_REWRITE_OPS 0x20
|
||||
#define MUT_REMOVE_ONE_AP 0x40
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
typedef std::vector<const formula*> vec;
|
||||
enum mut_opts
|
||||
{
|
||||
Mut_Ap2Const = 1U<<0,
|
||||
Mut_Simplify_Bounds = 1U<<1,
|
||||
Mut_Remove_Multop_Operands = 1U<<2,
|
||||
Mut_Remove_Ops = 1U<<3,
|
||||
Mut_Split_Ops = 1U<<4,
|
||||
Mut_Rewrite_Ops = 1U<<5,
|
||||
Mut_Remove_One_Ap = 1U<<6,
|
||||
Mut_All = -1U
|
||||
};
|
||||
|
||||
SPOT_API
|
||||
vec get_mutations(const formula*,
|
||||
unsigned opts = 0xfff,
|
||||
bool sort = true,
|
||||
int n = std::numeric_limits<int>::max(),
|
||||
unsigned m = 1);
|
||||
std::vector<const formula*> mutate(const formula* f,
|
||||
unsigned opts = Mut_All,
|
||||
unsigned max_output = -1U,
|
||||
unsigned mutation_count = 1,
|
||||
bool sort = true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue