stutter_invariance_formulas.cc 3.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "bin/common_sys.hh"
#include "bin/common_setup.hh"
#include "bin/common_finput.hh"
#include "bin/common_output.hh"
#include "tgbaalgos/translate.hh"
#include "tgbaalgos/stutter_invariance.hh"
Thibaud Michaud's avatar
Thibaud Michaud committed
26
#include "tgbaalgos/dupexp.hh"
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "ltlast/allnodes.hh"
#include "ltlvisit/apcollect.hh"
#include "ltlvisit/length.hh"
#include "misc/timer.hh"
#include <argp.h>
#include "error.h"

const char argp_program_doc[] ="";

const struct argp_child children[] =
  {
    { &finput_argp, 0, 0, 1 },
    { &output_argp, 0, 0, -20 },
    { &misc_argp, 0, 0, -1 },
    { 0, 0, 0, 0 }
  };

namespace
{
  class stut_processor: public job_processor
  {
  public:
    spot::translator& trans;
    std::string formula;

    stut_processor(spot::translator& trans) : trans(trans)
    {
    }

    int
    process_string(const std::string& input,
                   const char* filename, int linenum)
    {
      formula = input;
      return job_processor::process_string(input, filename, linenum);
    }

    int
    process_formula(const spot::ltl::formula* f,
                    const char*, int)
    {
      const spot::ltl::formula* nf =
	spot::ltl::unop::instance(spot::ltl::unop::Not,
				  f->clone());
Thibaud Michaud's avatar
Thibaud Michaud committed
71
72
73
      spot::tgba_digraph_ptr a = trans.run(f);
      spot::tgba_digraph_ptr na = trans.run(nf);
      unsigned num_states = a->num_states();
74
75
76
77
78
79
80
81
82
83
84
85
      spot::ltl::atomic_prop_set* ap = spot::ltl::atomic_prop_collect(f);
      bdd apdict = spot::ltl::atomic_prop_collect_as_bdd(f, a);
      bool res;
      bool prev = true;
      for (char algo = '1'; algo <= '8'; ++algo)
        {
          // set SPOT_STUTTER_CHECK environment variable
          char algostr[2] = { 0 };
          algostr[0] = algo;
          setenv("SPOT_STUTTER_CHECK", algostr, true);

          spot::stopwatch sw;
Thibaud Michaud's avatar
Thibaud Michaud committed
86
87
88
          auto dup_a = std::make_shared<spot::tgba_digraph>(a);
          auto dup_na = std::make_shared<spot::tgba_digraph>(na);

89
          sw.start();
Thibaud Michaud's avatar
Thibaud Michaud committed
90
91
          res = spot::is_stutter_invariant(std::move(dup_a),
                                           std::move(dup_na), apdict);
92
93
94
          const double time = sw.stop();

          std::cout << formula << ", " << algo << ", " << ap->size() << ", "
Thibaud Michaud's avatar
Thibaud Michaud committed
95
		    << num_states << ", " << res << ", " << time * 1000000 << std::endl;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

          if (algo > '1')
            assert(res == prev);
          prev = res;
        }
      f->destroy();
      nf->destroy();
      delete(ap);
      return 0;
    }
  };
}

int
main(int argc, char** argv)
{
  setup(argv);

  const argp ap = { 0, 0, "[FILENAME[/COL]...]",
                    argp_program_doc, children, 0, 0 };

  if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0))
    exit(err);

  spot::translator trans;
  stut_processor processor(trans);
  if (processor.run())
    return 2;

  return 0;
}