当前位置: 首页>>代码示例>>Java>>正文


Java TranslateAlloyToKodkod类代码示例

本文整理汇总了Java中edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod的典型用法代码示例。如果您正苦于以下问题:Java TranslateAlloyToKodkod类的具体用法?Java TranslateAlloyToKodkod怎么用?Java TranslateAlloyToKodkod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TranslateAlloyToKodkod类属于edu.mit.csail.sdg.alloy4compiler.translator包,在下文中一共展示了TranslateAlloyToKodkod类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main2

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
/** Displays the amount of memory taken per solution enumeration. */
public static void main2(String[] args) throws Exception {
    String filename = "models/examples/algorithms/dijkstra.als";
    Module world = CompUtil.parseEverything_fromFile(A4Reporter.NOP, null, filename);
    A4Options options = new A4Options();
    for (Command command: world.getAllCommands()) {
        A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
        while(ans.satisfiable()) {
            String hc = "Answer: " + ans.toString().hashCode();
            System.gc();
            System.gc();
            System.gc();
            Thread.sleep(500);
            System.gc();
            System.gc();
            System.gc();
            Thread.sleep(500);
            long t = Runtime.getRuntime().totalMemory(), f = Runtime.getRuntime().freeMemory(), m = Runtime.getRuntime().maxMemory();
            System.out.println(hc + " total=" + t + " free=" + f + " max="+m); System.out.flush();
            ans=ans.next();
        }
        return;
    }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:25,代码来源:InternalTest.java

示例2: validate

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
public static boolean validate(final String atomType) {
  final InstanceTranslatorReasoningForAtom instanceTranslator =
      new InstanceTranslatorReasoningForAtom(atomType);
  instanceTranslator.translate();
  AlloyValidatorReasoningForAtom.reasonRelations = instanceTranslator.getReasonRelations();

  final String filename = instanceTranslator.getBaseFileDirectory() + "reasoningForAtom.als";

  try {
    final A4Reporter rep = new A4Reporter() {
      @Override
      public void warning(final ErrorWarning msg) {
        System.out.print("Relevance Warning:\n" + msg.toString().trim() + "\n\n");
        System.out.flush();
      }
    };
    Module world = null;

    world = CompUtil.parseEverything_fromFile(rep, null, filename);

    final A4Options options = new A4Options();
    options.solver = A4Options.SatSolver.SAT4J;

    for (final Command command : world.getAllCommands()) {
      A4Solution ans = null;
      ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command,
          options);

      if (ans.satisfiable()) {
        return true;
      }
    }

  } catch (final Err e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return false;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:41,代码来源:AlloyValidatorReasoningForAtom.java

示例3: validate

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
public static boolean validate() {
  AlloyValidator.isCanceled = false;
  final InstanceTranslator instanceTranslator = new InstanceTranslator();
  instanceTranslator.translate();

  final String filename = instanceTranslator.getBaseFileDirectory() + "validation.als";

  try {
    final A4Reporter rep = new A4Reporter() {
      @Override
      public void warning(final ErrorWarning msg) {
        System.out.print("Relevance Warning:\n" + msg.toString().trim() + "\n\n");
        System.out.flush();
      }
    };
    Module world = null;

    world = CompUtil.parseEverything_fromFile(rep, null, filename);

    final A4Options options = new A4Options();
    options.solver = A4Options.SatSolver.SAT4J;

    for (final Command command : world.getAllCommands()) {
      A4Solution ans = null;
      ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command,
          options);
      if (ans.satisfiable()) {
        return true;
      }
    }

  } catch (final Err e) {
    e.printStackTrace();
  }
  return false;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:37,代码来源:AlloyValidator.java

示例4: validate

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
public static boolean validate() {
  final InstanceTranslatorDiscovering instanceTranslator = new InstanceTranslatorDiscovering();
  instanceTranslator.translate();
  AlloyValidatorDiscovering.discoverSigs = instanceTranslator.getDiscoverSig2ExpectValue();

  final String filename = instanceTranslator.getBaseFileDirectory() + "discovering.als";

  try {
    final A4Reporter rep = new A4Reporter() {
      @Override
      public void warning(final ErrorWarning msg) {
        System.out.print("Relevance Warning:\n" + msg.toString().trim() + "\n\n");
        System.out.flush();
      }
    };
    Module world = null;

    world = CompUtil.parseEverything_fromFile(rep, null, filename);

    final A4Options options = new A4Options();
    options.solver = A4Options.SatSolver.SAT4J;

    for (final Command command : world.getAllCommands()) {
      A4Solution ans = null;
      ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command,
          options);

      if (ans.satisfiable()) {
        return true;
      }
    }

  } catch (final Err e) {
    e.printStackTrace();
  }

  return false;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:39,代码来源:AlloyValidatorDiscovering.java

示例5: validate

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
public static boolean validate() {
  final InstanceTranslatorReasoning instanceTranslator = new InstanceTranslatorReasoning();
  instanceTranslator.translate();
  AlloyValidatorReasoning.reasonRelations = instanceTranslator.getReasonRelations();

  final String filename = instanceTranslator.getBaseFileDirectory() + "reasoning.als";

  try {
    final A4Reporter rep = new A4Reporter() {
      @Override
      public void warning(final ErrorWarning msg) {
        System.out.print("Relevance Warning:\n" + msg.toString().trim() + "\n\n");
        System.out.flush();
      }
    };
    Module world = null;

    world = CompUtil.parseEverything_fromFile(rep, null, filename);

    final A4Options options = new A4Options();
    options.solver = A4Options.SatSolver.SAT4J;

    for (final Command command : world.getAllCommands()) {
      A4Solution ans = null;
      ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command,
          options);

      if (ans.satisfiable()) {
        return true;
      }
    }

  } catch (final Err e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return false;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:40,代码来源:AlloyValidatorReasoning.java

示例6: executeCommand

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
/**
 * Executes given command
 * 
 * @param command to run
 * @return solution if it is satisfiable else null
 * @throws Err
 */
public A4Solution executeCommand(Command command) throws Err {
  if (world == null)
    return null;

  final A4Options options = new A4Options();
  options.solver = A4Options.SatSolver.SAT4J;
  A4Solution solution =
      TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command, options);
  if (solution.satisfiable()) {
    return solution;
  }

  return null;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:AlloyExecuter.java

示例7: runFor3

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
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));
        System.out.println("In particular, contains = " + sol.eval(contains));
        System.out.println("In particular, parent = " + sol.eval(parent));
    }
    System.out.println();
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:14,代码来源:DemoFileSystem.java

示例8: run

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
public void run(WorkerCallback out) throws Exception {
    cb(out, "S2", "Starting the solver...\n\n");
    final SimpleReporter rep = new SimpleReporter(out, options.recordKodkod);
    final Module world = CompUtil.parseEverything_fromFile(rep, map, options.originalFilename, resolutionMode);
    final List<Sig> sigs = world.getAllReachableSigs();
    final ConstList<Command> cmds = world.getAllCommands();
    cb(out, "warnings", bundleWarningNonFatal);
    if (rep.warn>0 && !bundleWarningNonFatal) return;
    List<String> result = new ArrayList<String>(cmds.size());
    if (bundleIndex==-2) {
        final String outf=tempdir+File.separatorChar+"m.xml";
        cb(out, "S2", "Generating the metamodel...\n");
        PrintWriter of = new PrintWriter(outf, "UTF-8");
        Util.encodeXMLs(of, "\n<alloy builddate=\"", Version.buildDate(), "\">\n\n");
        A4SolutionWriter.writeMetamodel(ConstList.make(sigs), options.originalFilename, of);
        Util.encodeXMLs(of, "\n</alloy>");
        Util.close(of);
        if ("yes".equals(System.getProperty("debug"))) validate(outf);
        cb(out, "metamodel", outf);
        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"));
                if (r.expects==0) rep.cb("", ", contrary to expectation");
                else if (r.expects==1) rep.cb("", ", as expected");
            } else if (result.get(i).endsWith(".core")) {
                rep.cb("", "   #"+(i+1)+": ");
                rep.cb("link", r.check?"No counterexample found. ":"No instance found. ", "CORE: "+result.get(i));
                rep.cb("", r.label+(r.check?" may be valid":" may be inconsistent"));
                if (r.expects==1) rep.cb("", ", contrary to expectation");
                else if (r.expects==0) rep.cb("", ", as expected");
            } else {
                if (r.check) rep.cb("", "   #"+(i+1)+": No counterexample found. "+r.label+" may be valid");
                else rep.cb("", "   #"+(i+1)+": No instance found. "+r.label+" may be inconsistent");
                if (r.expects==1) rep.cb("", ", contrary to expectation");
                else if (r.expects==0) rep.cb("", ", as expected");
            }
            rep.cb("", ".\n");
        }
        rep.cb("", "\n");
    }
    if (rep.warn>1) rep.cb("bold", "Note: There were "+rep.warn+" compilation warnings. Please scroll up to see them.\n");
    if (rep.warn==1) rep.cb("bold", "Note: There was 1 compilation warning. Please scroll up to see it.\n");
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:65,代码来源:SimpleReporter.java

示例9: main

import edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod; //导入依赖的package包/类
public static void main(String[] args) throws Err {

        // Chooses the Alloy4 options
        A4Options opt = new A4Options();
        opt.solver = A4Options.SatSolver.SAT4J;

        // abstract sig A {}
        PrimSig A = new PrimSig("A", Attr.ABSTRACT);

        // sig B {}
        PrimSig B = new PrimSig("B");

        // one sig A1 extends A {}
        PrimSig A1 = new PrimSig("A1", A, Attr.ONE);

        // one sig A2 extends A {}
        PrimSig A2 = new PrimSig("A2", A, Attr.ONE);

        // A { f: B lone->lone B }
        Expr f = A.addField("f", B.lone_arrow_lone(B));
        // Since (B lone->lone B) is not unary,  the default is "setOf",  meaning "f:set (B lone->lone B)"

        // A { g: B }
        Expr g = A.addField("g", B);
        // The line above is the same as:   A.addField(null, "g", B.oneOf())  since B is unary.
        // If you want "setOf", you need:   A.addField(null, "g", B.setOf())

        // pred someG { some g }
        Func someG = new Func(null, "SomeG", null, null, g.some());

        // pred atMostThree[x:univ, y:univ] { #(x+y) >= 3 }
        Decl x = UNIV.oneOf("x");
        Decl y = UNIV.oneOf("y");
        Expr body = x.get().plus(y.get()).cardinality().lte(ExprConstant.makeNUMBER(3));
        Func atMost3 = new Func(null, "atMost3", Util.asList(x,y), null, body);

        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());
    }
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:55,代码来源:ExampleUsingTheAPI.java


注:本文中的edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。