main.cpp 6.25 KB
Newer Older
Christian Müller's avatar
aalta  
Christian Müller committed
1 2 3 4 5 6 7
#include "sat_solver.h"
#include "buchi/buchi_automata.h"
#include "checking/nondeter_checker.h"
#include "util/utility.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
8
#define MAXN 1000000
Christian Müller's avatar
aalta  
Christian Müller committed
9 10 11 12 13 14 15 16
char in[MAXN];


void 
nondeter_sat (int argc, char** argv)
{
  if (argc == 1)
    {
Christian Müller's avatar
Christian Müller committed
17
      // puts ("please input the formula:");
Christian Müller's avatar
aalta  
Christian Müller committed
18 19 20 21 22 23 24 25 26 27 28 29
      if (fgets (in, MAXN, stdin) == NULL)
      {
        printf ("Error: read input!\n");
        exit (0);
      }
    }
  else
    {
      strcpy (in, argv[1]);
    }
  aalta_formula* af;
  
Christian Müller's avatar
Christian Müller committed
30
  //printf("Simplifying ...");
Christian Müller's avatar
aalta  
Christian Müller committed
31 32
  af = aalta_formula(in).unique();
  af = af->simplify ();
33

Christian Müller's avatar
Christian Müller committed
34
  //printf("Checking satisfiability...");
Christian Müller's avatar
aalta  
Christian Müller committed
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 71 72 73 74 75 76 77 78 79
  
  nondeter_checker ch (af);
  
  printf ("%s\n", ch.check () ? "sat" : "unsat");
  //aalta_formula::print_sat_count ();
  aalta_formula::destroy();
}

/*
void 
deter_sat (int argc, char** argv)
{
  if (argc == 1)
    {
      puts ("please input the formula:");
      if (fgets (in, MAXN, stdin) == NULL)
      {
        printf ("Error: read input!\n");
        exit (0);
      }
    }
  else
    {
      strcpy (in, argv[1]);
    }
  aalta_formula* af;
  
  af = aalta_formula(in).unique();
  af = af->simplify ();
  checker ch (af);
  //af = af -> classify();
  printf ("%s\n", ch.check () ? "sat" : "unsat");
  aalta_formula::destroy();
}
*/


void
sat (int argc, char** argv)
{
  //freopen ("tests/in", "r", stdin);
  bool dfa = false;
  bool f2l = false;
  if (argc == 1)
    {
Christian Müller's avatar
Christian Müller committed
80
      // puts ("please input the formula:");
Christian Müller's avatar
aalta  
Christian Müller committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      if (fgets (in, MAXN, stdin) == NULL)
      {
        printf ("Error: read input!\n");
        exit (0);
      }
    }
  else
    {
      strcpy (in, argv[1]);
    }
  aalta_formula* af;
  sat_solver solver;
  
  af = aalta_formula(in).unique();
  af = af -> classify();
  printf ("%s\n", solver.sat (af) ? "sat" : "unsat");
  aalta_formula::destroy();
}

void
ltlf_sat (int argc, char** argv)
{
  //freopen ("tests/in", "r", stdin);
  bool dfa = false;
  bool f2l = false;
  if (argc == 1)
    {
Christian Müller's avatar
Christian Müller committed
108
      // puts ("please input the formula:");
Christian Müller's avatar
aalta  
Christian Müller committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
      if (fgets (in, MAXN, stdin) == NULL)
      {
        printf ("Error: read input!\n");
        exit (0);
      }
    }
  else
    {
      strcpy (in, argv[1]);
    }
  aalta_formula* af;
  sat_solver solver;
  
  af = aalta_formula(in, true).unique();
  af = af->simplify ();
  
  printf ("%s\n", solver.satLTLf (af) ? "sat" : "unsat");
  aalta_formula::destroy();
}

void
dnf (int argc, char** argv)
{
  if (freopen ("tests/in", "r", stdin) == NULL)
  {
    printf ("Error: read the file tests/in!\n");
    exit (0);
  }
  if (argc == 1)
    {
Christian Müller's avatar
Christian Müller committed
139
      // puts ("please input the formula:");
Christian Müller's avatar
aalta  
Christian Müller committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
      if (fgets (in, MAXN, stdin) == NULL)
      {
        printf ("Error: read input!\n");
        exit (0);
      }
    }
  else
    {
      strcpy (in, argv[1]);
    }
  dnf_formula dnf (in);
  printf ("%s\n", dnf.to_string ().c_str ());
}


void
buchi (int argc, char** argv)
{
  //freopen ("tests/in", "r", stdin);
  if (argc == 1)
    {
      puts ("please input the formula:");
      if (fgets (in, MAXN, stdin) == NULL)
      {
        printf ("Error: read input!\n");
        exit (0);
      }
    }
  else
    {
      strcpy (in, argv[1]);
    }
  buchi_automata ba (in);
  printf ("%s\n", ba.to_neverclaim ().c_str ());
  //printf ("%s\n", ba.to_lbtt ().c_str ());
  //  printf ("%s\n", ba.to_string ().c_str ());
}


double
current_time ()
{
  struct timeval tv;
  gettimeofday (&tv, NULL);
  return tv.tv_sec + tv.tv_usec / 1000000.0;
}

void print_help()
{
  printf("\n\tThe parameters of Aalta are listed as follows:\n");
  
  printf("\n\t\t-l -c (-e)\t\tLTL satisfiability checking (default). An evidence is shown if '-e' is given and the formula is satisfiable.;\n");
  printf("\n\t\t-f -c (-e)\t\tLTLf satisfiability checking. An evidence is given if '-e' is given and the formula is satisfiable.;\n");
  printf("\n\t\t-l -b\t\tLTL-to-Buchi translation.\n");
  printf("\n\t\t-h\t\t Help information\n");
  printf("\n\t\twhere every parameter has the meaning of:\n");
  printf("\t\t-l\t\tThe input is an LTL formula;\n");
  printf("\t\t-f\t\tThe input is an LTLf formula;\n");
  printf("\t\t-c\t\tDo the satisfiability checking;\n");
  printf("\t\t-e\t\tShow an evidence for the satisfiable formula;\n");
  printf("\t\t-b\t\tGenerate the Buchi automaton;\n");
}

int
main (int argc, char** argv)
{
/*
  bool ltl = false;
  bool ltlf = false;
  bool evidence = false;
  bool buchi = false;
  bool check = false;
  bool help = false;
  if(argc == 1)
  {
    ltl = true;
    check = true;
  }
  else
  {
    for (int i = 1; i < argc; i++)
    {
      if(strcmp(argv[i], "-l") == 0)
      {
        ltl = true;
        continue;
      }
      if(strcmp(argv[i], "-f") == 0)
      {
        ltlf = true;
        continue;
      }
      if(strcmp(argv[i], "-c") == 0)
      {
        check = true;
        continue;
      }
      if(strcmp(argv[i], "-e") == 0)
      {
        evidence = true;
        continue;
      }
      if(strcmp(argv[i], "-b") == 0)
      {
        buchi = true;
        continue;
      }
      if(strcmp(argv[i], "-h") == 0)
      {
        help = true;
        continue;
      }
    }
  }
  if(help)
  {
    print_help();
    return 0;
  }
  
  //to do: show the evidence!!
  if(ltl && check && !ltlf && !buchi)
  {
    puts ("please input the formula:");
    fgets (in, MAXN, stdin);
    aalta_formula* af;
    sat_solver solver;
  
    af = aalta_formula(in).unique();
    af = af -> classify();
    printf ("%s\n", solver.sat (af) ? "sat" : "unsat");
    if(evidence)
      printf ("%s\n", solver._evidence.c_str());
    aalta_formula::destroy();
    return 0;
  }
  if(ltlf && check && !ltl && !buchi)
  {
    puts ("please input the formula:");
    fgets (in, MAXN, stdin);
    aalta_formula* af;
    sat_solver solver;
    af = aalta_formula(in, true).unique();
    printf ("%s\n", solver.satLTLf (af) ? "sat" : "unsat");
    if(evidence)
      printf ("%s\n", solver._evidence.c_str());
    aalta_formula::destroy();
    return 0;
  }
  if(ltl && buchi && !ltlf && !check)
  {
    puts ("please input the formula:");
    fgets (in, MAXN, stdin);
    buchi_automata ba (in);
    printf ("%s\n", ba.to_neverclaim ().c_str ());
    return 0;
  }
  print_help();
  return 0;
  */
  
  //dnf (argc, argv);
  //sat (argc, argv);
  //ltlf_sat(argc, argv);
  //buchi (argc, argv);
  nondeter_sat (argc, argv);
  return 0;
  

}