Package edu.mit.csail.sdg.alloy4compiler.ast

Examples of edu.mit.csail.sdg.alloy4compiler.ast.Command


        return ans;
    }

    void runFor3(Expr expr) throws Err {
        A4Options opt = new A4Options();
        Command cmd = new Command(false, 3, 3, 3, expr.and(fact));
        A4Solution sol = TranslateAlloyToKodkod.execute_command(NOP, sigs, cmd, opt);
        System.out.println(sol.toString().trim());
        if (sol.satisfiable()) {
            System.out.println("In particular, File = " + sol.eval(file));
            System.out.println("In particular, Dir = " + sol.eval(dir));
View Full Code Here


    /** {@inheritDoc} */
    @Override public void resultSAT(Object command, long solvingTime, Object solution) {
        if (!(solution instanceof A4Solution) || !(command instanceof Command)) return;
        A4Solution sol = (A4Solution)solution;
        Command cmd = (Command)command;
        String formula = recordKodkod ? sol.debugExtractKInput() : "";
        String filename = tempfile+".xml";
        synchronized(SimpleReporter.class) {
            try {
                cb("R3", "   Writing the XML file...");
View Full Code Here

    }

    /** {@inheritDoc} */
    @Override public void minimizing(Object command, int before) {
        if (!(command instanceof Command)) return;
        Command cmd = (Command)command;
        minimized = System.currentTimeMillis();
        cb("minimizing", cmd.check, cmd.expects, before, minimized-lastTime);
    }
View Full Code Here

    /** {@inheritDoc} */
    @Override public void resultUNSAT(Object command, long solvingTime, Object solution) {
        if (!(solution instanceof A4Solution) || !(command instanceof Command)) return;
        A4Solution sol = (A4Solution)solution;
        Command cmd = (Command)command;
        String originalFormula = recordKodkod ? sol.debugExtractKInput() : "";
        String corefilename="", formulafilename="";
        if (originalFormula.length()>0 && tempfile!=null) {
            formulafilename=tempfile+".java";
            try { Util.writeAll(formulafilename, originalFormula); formulafilename="CNF: "+formulafilename; } catch(Throwable ex) { formulafilename=""; }
View Full Code Here

                synchronized(SimpleReporter.class) { latestMetamodelXML=outf; }
            } else for(int i=0; i<cmds.size(); i++) if (bundleIndex<0 || i==bundleIndex) {
                synchronized(SimpleReporter.class) { latestModule=world; latestKodkodSRC=ConstMap.make(map); }
                final String tempXML=tempdir+File.separatorChar+i+".cnf.xml";
                final String tempCNF=tempdir+File.separatorChar+i+".cnf";
                final Command cmd=cmds.get(i);
                rep.tempfile=tempCNF;
                cb(out, "bold", "Executing \""+cmd+"\"\n");
                A4Solution ai=TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), cmd, options);
                if (ai==null) result.add(null);
                else if (ai.satisfiable()) result.add(tempXML);
                else if (ai.highLevelCore().a.size()>0) result.add(tempCNF+".core");
                else result.add("");
            }
            (new File(tempdir)).delete(); // In case it was UNSAT, or canceled...
            if (result.size()>1) {
                rep.cb("bold", "" + result.size() + " commands were executed. The results are:\n");
                for(int i=0; i<result.size(); i++) {
                    Command r=world.getAllCommands().get(i);
                    if (result.get(i)==null) { rep.cb("", "   #"+(i+1)+": Unknown.\n"); continue; }
                    if (result.get(i).endsWith(".xml")) {
                        rep.cb("", "   #"+(i+1)+": ");
                        rep.cb("link", r.check?"Counterexample found. ":"Instance found. ", "XML: "+result.get(i));
                        rep.cb("", r.label+(r.check?" is invalid":" is consistent"));
View Full Code Here

        List<Sig> sigs = Arrays.asList(new Sig[]{A, B, A1, A2});

        // run { some A && atMostThree[B,B] } for 3 but 3 int, 3 seq
        Expr expr1 = A.some().and(atMost3.call(B,B));
        Command cmd1 = new Command(false, 3, 3, 3, expr1);
        A4Solution sol1 = TranslateAlloyToKodkod.execute_command(NOP, sigs, cmd1, opt);
        System.out.println("[Solution1]:");
        System.out.println(sol1.toString());

        // run { some f && SomeG[] } for 3 but 2 int, 1 seq, 5 A, exactly 6 B
        Expr expr2 = f.some().and(someG.call());
        Command cmd2 = new Command(false, 3, 2, 1, expr2);
        cmd2 = cmd2.change(A, false, 5);
        cmd2 = cmd2.change(B, true, 6);
        A4Solution sol2 = TranslateAlloyToKodkod.execute_command(NOP, sigs, cmd2, opt);
        System.out.println("[Solution2]:");
        System.out.println(sol2.toString());
    }
View Full Code Here

            List<Command> commands = new ArrayList<Command>();
            while(usercommand!=null) { commands.add(usercommand); usercommand = usercommand.parent; }
            // For each command...
            A4Solution sol = null;
            for(int i=commands.size()-1; i>=0; i--) {
                Command cmd = commands.get(i);
                sim.growableSigs = cmd.getGrowableSigs();
                while(cmd != null) {
                    rep.debug(cmd.scope.toString());
                    usercommand = cmd;
                    tr = new TranslateAlloyToKodkod(rep2, opt, sigs, cmd);
                    tr.makeFacts(cmd.formula);
                    sim.totalOrderPredicates = tr.totalOrderPredicates;
                    sol = tr.frame.solve(rep2, cmd, sim.partial==null || cmd.check ? new Simplifier() : sim, false);
                    if (!sol.satisfiable() && !cmd.check) {
                        start = System.currentTimeMillis() - start;
                        if (sim.partial==null) { rep.resultUNSAT(cmd, start, sol); return sol; } else { rep.resultSAT(cmd, start, sim.partial); return sim.partial; }
                    }
                    if (sol.satisfiable() && cmd.check) {
                        start = System.currentTimeMillis() - start;
                        rep.resultSAT(cmd, start, sol); return sol;
                    }
                    sim.partial = sol;
                    if (sim.growableSigs.isEmpty()) break;
                    for(Sig s: sim.growableSigs) {
                        CommandScope sc = cmd.getScope(s);
                        if (sc.increment > sc.endingScope - sc.startingScope) {cmd=null; break;}
                        cmd = cmd.change(s, sc.isExact, sc.startingScope+sc.increment, sc.endingScope, sc.increment);
                    }
                }
            }
            if (sol.satisfiable()) rep.resultSAT(usercommand, System.currentTimeMillis()-start, sol); else rep.resultUNSAT(usercommand, System.currentTimeMillis()-start, sol);
            return sol;
View Full Code Here

      if (label!=null) p=Pos.UNKNOWN.merge(p).merge(label.pos);
      status=3;
      if (n.length()==0) throw new ErrorSyntax(p, "Predicate/assertion name cannot be empty.");
      if (n.indexOf('@')>=0) throw new ErrorSyntax(p, "Predicate/assertion name cannot contain \'@\'");
      String labelName = (label==null || label.label.length()==0) ? n : label.label;
      Command parent = followUp ? commands.get(commands.size()-1) : null;
      Command newcommand = new Command(p, labelName, c, o, b, seq, exp, s, null, ExprVar.make(null, n), parent);
      if (parent!=null) commands.set(commands.size()-1, newcommand); else commands.add(newcommand);
   }
View Full Code Here

      status=3;
      String n;
      if (c) n=addAssertion(p,"check$"+(1+commands.size()),e);
      else addFunc(e.span().merge(p), Pos.UNKNOWN, n="run$"+(1+commands.size()), null, new ArrayList<Decl>(), null, e);
      String labelName = (label==null || label.label.length()==0) ? n : label.label;
      Command parent = followUp ? commands.get(commands.size()-1) : null;
      Command newcommand = new Command(e.span().merge(p), labelName, c, o, b, seq, exp, s, null, ExprVar.make(null, n), parent);
      if (parent!=null) commands.set(commands.size()-1, newcommand); else commands.add(newcommand);
   }
View Full Code Here

      if (parent!=null) commands.set(commands.size()-1, newcommand); else commands.add(newcommand);
   }

   /** Resolve a particular command. */
   private Command resolveCommand(Command cmd, ConstList<Sig> exactSigs, Expr globalFacts) throws Err {
      Command parent = cmd.parent==null ? null : resolveCommand(cmd.parent, exactSigs, globalFacts);
      String cname = ((ExprVar)(cmd.formula)).label;
      Expr e;
      if (cmd.check) {
         List<Object> m = getRawQS(2, cname); // We prefer assertion in the topmost module
         if (m.size()==0 && cname.indexOf('/')<0) m=getRawNQS(this, 2, cname);
         if (m.size()>1) unique(cmd.pos, cname, m);
         if (m.size()<1) throw new ErrorSyntax(cmd.pos, "The assertion \""+cname+"\" cannot be found.");
         e = ((Expr)(m.get(0))).not();
      } else {
         List<Object> m = getRawQS(4, cname); // We prefer fun/pred in the topmost module
         if (m.size()==0 && cname.indexOf('/')<0) m=getRawNQS(this, 4, cname);
         if (m.size()>1) unique(cmd.pos, cname, m);
         if (m.size()<1) throw new ErrorSyntax(cmd.pos, "The predicate/function \""+cname+"\" cannot be found.");
         Func f = (Func) (m.get(0));
         e = f.getBody();
         if (!f.isPred) e = e.in(f.returnDecl);
         if (f.decls.size()>0) e = ExprQt.Op.SOME.make(null, null, f.decls, e);
      }
      if (e==null) e = ExprConstant.TRUE;
      TempList<CommandScope> sc=new TempList<CommandScope>(cmd.scope.size());
      for(CommandScope et: cmd.scope) {
         Sig s = getRawSIG(et.sig.pos, et.sig.label);
         if (s==null) throw new ErrorSyntax(et.sig.pos, "The sig \""+et.sig.label+"\" cannot be found.");
         sc.add(new CommandScope(null, s, et.isExact, et.startingScope, et.endingScope, et.increment));
      }
      return new Command(cmd.pos, cmd.label, cmd.check, cmd.overall, cmd.bitwidth, cmd.maxseq, cmd.expects, sc.makeConst(), exactSigs, globalFacts.and(e), parent);
   }
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4compiler.ast.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.