Commit f986550d authored by Christian Müller's avatar Christian Müller

aalta

parent e57b83c3
FORMULAFILES = formula/aalta_formula.cpp formula/dnf_clause.cpp \
formula/dnf_formula.cpp formula/olg_formula.cpp formula/olg_item.cpp
PARSERFILES = ltlparser/ltl_formula.c ltlparser/ltllexer.c ltlparser/ltlparser.c ltlparser/trans.c
UTILFILES = util/utility.cpp
BUCHI = buchi/buchi_node.cpp buchi/buchi_automata.cpp
MINISAT = minisat/core/Solver.cc
CHECKING = checking/checker.cpp checking/nondeter_checker.cpp checking/scc.cpp
PROGRESSION = progression/nondeter_prog_state.cpp
ALLFILES = $(CHECKING) $(PROGRESSION) $(MINISAT) $(FORMULAFILES) $(PARSERFILES) $(UTILFILES) $(BUCHI) sat_solver.cpp main.cpp
COSAFETYFILES = $(PARSERFILES) $(UTILFILES) formula/aalta_formula.cpp cosafety2smv.cpp
CC = g++
FLAG = -I./ -I./minisat/ -I./formula/ -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS
DEBUGFLAG = -g -pg
RELEASEFLAG = -O2
aalta : release
ltlparser/ltllexer.c :
ltlparser/grammar/ltllexer.l
flex ltlparser/grammar/ltllexer.l
ltlparser/ltlparser.c :
ltlparser/grammar/ltlparser.y
bison ltlparser/grammar/ltlparser.y
cosafety2smv : $(COSAFETYFILES)
$(CC) $(FLAG) $(DEBUGFLAG) $(COSAFETYFILES) -lz -o cosafety2smv
.PHONY : release debug clean
release : $(ALLFILES)
$(CC) $(FLAG) $(RELEASEFLAG) $(ALLFILES) -lz -o aalta
debug : $(ALLFILES)
$(CC) $(FLAG) $(DEBUGFLAG) $(ALLFILES) -lz -o aalta
clean :
rm -f *.o *~ aalta
#!/usr/bin/perl
use File::Find;
use POSIX qw/strftime/;
use Time::HiRes qw( time );
#print strftime('%D %T',localtime);
$start = strftime('%D %T',localtime);
my $files;
find(\&wanted, 'benchmarks');
$n = 1;
#open(TIMEOUTFILE, ">timeout_aalta") or die "cannot open the file!";
#open(TIMEOUTFILE, ">error") or die "cannot open the file!";
foreach(@content)
{
if(-f $_)
{
#print "$_\n";
if($_ =~ /.*\.alaska/)
{
open(INFILE, "$_") or die "cannot open the input file!";
open(OUTFILE, ">output/$_") or die "cannot open the file!";
#open(TIMEOUTFILE, ">>output/timeout_aalta") or die "cannot open the file!";
$line = <INFILE>;
while ($line ne "")
{
eval
{
local $SIG{ALRM} = sub { die "timeout\n" };
alarm(60);
$t0 = time();
#print "checking\ $_ ...\n";
$output = `./aalta -fd "$line"`;
print OUTFILE "$output\n";
$n = $n + 1;
alarm(0);
};
if($@)
{
#print TIMEOUTFILE ("$_\n");
$output = `killall -9 aalta`;
print OUTFILE "timeout\n";
$n = $n + 1;
sleep 1;
}
$line = <INFILE>;
}
close(INFILE);
#close(OUTFILE);
}
}
}
close(TIMEOUTFILE);
$end = strftime('%D %T',localtime);
open(TIMEFILE, ">timeinfo") or die "cannot open the file!";
print TIMEFILE ("start time: $start\n");
print TIMEFILE ("end time: $end\n");
close(TIMEFILE);
exit;
sub wanted
{
push @content, $File::Find::name;
return;
}
#!/usr/bin/perl
use File::Find;
use POSIX qw/strftime/;
use Time::HiRes qw( time );
#print strftime('%D %T',localtime);
$start = strftime('%D %T',localtime);
my $files;
find(\&wanted, 'benchmarks');
$n = 1;
#open(TIMEOUTFILE, ">timeout_aalta") or die "cannot open the file!";
#open(TIMEOUTFILE, ">error") or die "cannot open the file!";
foreach(@content)
{
if(-f $_)
{
#print "$_\n";
if($_ =~ /.*\.alaska/)
{
open(INFILE, "$_") or die "cannot open the input file!";
open(OUTFILE, ">output/$_") or die "cannot open the file!";
#open(TIMEOUTFILE, ">>output/timeout_aalta") or die "cannot open the file!";
$line = <INFILE>;
while ($line ne "")
{
eval
{
local $SIG{ALRM} = sub { die "timeout\n" };
alarm(60);
$t0 = time();
#print "checking\ $_ ...\n";
$output = `./aalta -fn "$line"`;
print OUTFILE "$output\n";
$n = $n + 1;
alarm(0);
};
if($@)
{
#print TIMEOUTFILE ("$_\n");
$output = `killall -9 aalta`;
print OUTFILE "timeout\n";
$n = $n + 1;
sleep 1;
}
$line = <INFILE>;
}
close(INFILE);
#close(OUTFILE);
}
}
}
close(TIMEOUTFILE);
$end = strftime('%D %T',localtime);
open(TIMEFILE, ">timeinfo") or die "cannot open the file!";
print TIMEFILE ("start time: $start\n");
print TIMEFILE ("end time: $end\n");
close(TIMEFILE);
exit;
sub wanted
{
push @content, $File::Find::name;
return;
}
/*
* aiger translator to aalta_formula
* File: AIGER.cpp
* Author: Jianwen Li
*
* Created on November 19, 2014
*/
#include "AIGER.h"
#include "formula/aalta_formua.h"
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
aalta_formula* aiger_to_ltl (const string& fn, bool safety)
{
//get aiger object
aiger* aig = aiger_init ();
aiger_open_and_read_from_file(aig, fn.c_str());
const char * err = aiger_error(aig);
if (err)
{
cout << err << endl;
throw InputError(err);
}
if (!aiger_is_reencoded(aig))
aiger_reencode(aig);
if (safety) //safety property
return aiger_safety (aig);
else
return aiger_fair (aig);
}
aalta_formula* aiger_safety (aiger *aig)
{
aalta_formula *result, *constraint, *output, *bad;
result = NULL;
constraint = NULL;
output = NULL;
bad = NULL;
for (size_t i = 0; i < aig->num_constraints; ++i)
{
if (i == 0)
constraint = generate_constraint (aig, 0);
else
constraint = aalta_formula (aalta_formula::And, constraint, generate_constraint (aiger, i)).unique ();
}
/* not sure for the outputs!!
for (size_t i = 0; i < aig->num_outputs; ++i)
{
if (i == 0)
output = generate_output (aig, 0);
else
output = aalta_formula (aalta_formula::Or, output, generate_output (aiger, i)).unique ();
}
*/
for (size_t i = 0; i < aig->num_bad; ++i)
{
if (i == 0)
bad = generate_bad (aig, 0);
else
bad = aalta_formula (aalta_formula::Or, bad, generate_bad (aiger, i)).unique ();
}
if (constraint == NULL)
{
if (bad != NULL)
result = bad;
}
else
{
assert (bad != NULL);
bad = aalta_formula (aalta_formula::And, constraint, bad).unique ();
result = aalta_formula (aalta_formula::Until, constraint, bad).unique ();
}
return result;
}
aalta_formula* generate_constraint (aiger *aig, unsigned pos)
{
unsigned id = aig->constraints[pos].lit;
aalta_formula *result = generate_formula (aig, id);
return result;
}
aalta_formula* generate_bad (aiger *aig, unsigned pos)
{
unsigned id = aig->bad[pos].lit;
aalta_formula *result = generate_formula (aig, id);
return result;
}
aalta_formula* aiger_fair (aiger* aig)
{
aalta_formula *result, *fair, *justice, *f, *g;
result = NULL;
for (size_t i = 0; i < aig->num_constraints; ++i)
{
if (i == 0)
result = generate_constraint (aig, 0);
else
result = aalta_formula (aalta_formula::And, result, generate_constraint (aiger, i)).unique ();
}
if (result != NULL)
result = aalta_formula (aalta_formula::Release, aalta_formula::FALSE (), result).unique ();
for (size_t i = 0; i < aig->num_fairness; ++i)
{
fair = generate_fair (aig, i);
f = aalta_formula (aalta_formula::Until, aalta_formula::TRUE (), fair).unique ();
g = aalta_formula (aalta_formula::Release, aalta_formula::FALSE (), f).unique ();
if (result == NULL)
result = g;
else
result = aalta_formula (aalta_formula::And, result, g).unique ();
}
for (size_t i = 0; i < aig->num_justice; ++i)
{
justice = generate_justice (aig, i);
if (result == NULL)
result = justice;
else
result = aalta_formula (aalta_formula::Or, result, justice).unique ();
}
return result;
}
aalta_formula* generate_fair (aiger *aig, unsigned pos)
{
unsigned id = aig->fairness[pos].lit;
aalta_formula *result = generate_formula (aig, id);
return result;
}
aalta_formula* generate_justice (aiger *aig, unsigned pos)
{
const aiger_symbol & sym = aig->justice[pos];
aalta_formula *result, *just, *f, *g;
result = NULL;
for (size_t j = 0; j < sym.size; ++j)
{
just = generate_formula (aig, sym.lits[j]);
f = aalta_formula (aalta_formula::Until, aalta_formula::TRUE (), fair).unique ();
g = aalta_formula (aalta_formula::Release, aalta_formula::FALSE (), f).unique ();
if (result == NULL)
result = g;
else
result = aalta_formula (aalta_formula::And, result, g).unique ();
}
return result;
}
aalta_formula* generate_formula (aiger *aig, unsigned id)
{
unsigned pos = id / 2;
aalta_formula *result;
if (FORMULAS[pos] != NULL)
result = FORMULAS[pos];
else
{
unsigned index;
aalta_formula *f, *l, *r;
for (size_t i = 0; i < aig->num_inputs; ++i)
{
index = aig->inputs[i].lit / 2;
if (FORMULAS[index] == NULL)
FORMULAS[index] = aalta_formula (index).unique ();
if (pos == index)
{
result = FORMULAS[index];
break;
}
}
for (size_t i = 0; i < aig->num_ands; ++i)
{
const aiger_and * aa = aig->ands + i;
index = aa->lhs / 2;
if (FORMULAS[index] == NULL)
{
l = generate_formula (aig, aa->rhs0);
r = generate_formula (aig, aa->rhs1);
f = aalta_formula (aalta_formula::And, l, r).unique ();
FORMULAS[index] = f;
}
if (pos == index)
{
result = FORMULAS[index];
break;
}
}
for (size_t i = 0; i < aig->num_latches, ++i)
{
index = aig->latches[i].lit / 2;
if (FORMULAS[index] == NULL)
FORMULAS[index] = aalta_formula (index).unique ();
if (id == index)
{
result = FORMULAS[index];
break;
}
unsigned next = aig->latches[i].next / 2;
if (FORMULAS[next] == NULL)
FORMULAS[next] = aalta_formula (aalta_formula::Next, NULL, FORMULAS[index]).unique ();
if (pos == next)
{
result = FORMULAS[next];
break;
}
}
if (id % 2 != 0)
{
result = aalta_formula (aalta_formula::Not, NULL, result).unique ();
result = result->nnf ();
}
}
return result;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
a.out : lex parse
cc parse.tab.c trans.c -ll
lex :
flex scan.l
parse :
bison parse.y
.PHONY : clean
clean :
rm a.out
Copyright 2011 Tatsuhiro Tsuchiya. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY Tatsuhiro Tsuchiya ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Tatsuhiro Tsuchiya OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Tatsuhiro Tsuchiya.
This diff is collapsed.
/*
* Copyright 2011 Tatsuhiro Tsuchiya. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY Tatsuhiro Tsuchiya ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Tatsuhiro Tsuchiya OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of Tatsuhiro Tsuchiya.
*
*/
typedef enum _Node_Type {
VAR_Node,
AND_Node = '&',
OR_Node = '|',
EQ_Node = '=',
IMP_Node,
NOT_Node = '!'
} Node_Type;
typedef struct _Node {
Node_Type type;
struct _Node *left, *right;
int index;
} Node;
Node *make_node();
int run();
40
33
124
41
38
p cnf 4 4
4 0
-4 2 0
-4 3 0
-2 -1 1 0
This diff is collapsed.
%{
/*
* Copyright 2011 Tatsuhiro Tsuchiya. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY Tatsuhiro Tsuchiya ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Tatsuhiro Tsuchiya OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of Tatsuhiro Tsuchiya.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "node.h"
int no_variables;
int no_terms;
int no_clauses;
int result_output;
extern int plus(Node *);
extern int yyparse();
%}
%union {
int var; /* variable index */
Node *node;
}
%token <var> VAR
%token IMP
%type <node> program exp
%left '='
%left IMP
%left '|'
%left '&'
%right '!'
%start program
%%
program
: exp { result_output = 0;
plus( $1);
printf("p cnf %d %d\n", no_terms, ++no_clauses);
printf("%d 0\n", $1->index);
result_output = 1;
plus( $1);
}
;
exp
: VAR { $$ = make_node( VAR_Node, NULL, NULL, $1); printf("%d\n", $1);}
| '(' exp ')' { $$ = $2; }
| exp '&' exp { no_terms++; $$ = make_node( '&', $1, $3, no_terms); }
| exp '|' exp { no_terms++; $$ = make_node( '|', $1, $3, no_terms); }
| exp '=' exp { no_terms++; $$ = make_node( '=', $1, $3, no_terms); }
| exp IMP exp { no_terms++; $$ = make_node( IMP_Node, $1, $3, no_terms); }
| '!' exp { $$ = make_node( '!', $2, NULL, -$2->index); }
;
%%
int main(void)
{