Class AlloySession

java.lang.Object
org.clafer.alloy.solve.AlloySession

public final class AlloySession extends Object
An Alloy model in this JVM and its solutions: claferIG's AlloyIG.java, whose operations are the methods here rather than messages on a pipe. A solution is Alloy's XML of it, as AlloyIG sends it.

The model is parsed from its text, in memory. The solutions of a dynamic model, a trace each, are solved for one by one, without the traces given so far (next()); fork(int) and nextConfiguration() give other traces, and check(String) the counterexample of an assertion. The unsat core of the model comes from the minisat prover, claferIG's fixed one (FixedMiniSatProver).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    The sigs of the model and the global scope of its command.
    static final record 
    A sig of the model, as load sends it.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    check(String assertion)
    check: the counterexample of the assertion with the given label, at the scopes and the trace length of the model, if any.
    fork(int forkState)
    fork: a trace with the same states as the trace shown last before the given state, which differs from the traces given so far.
    boolean
     
    load(String model)
    load: parses the model.
    next: the next solution, if any.
    nextConfiguration: a trace whose relations that do not change over time differ from those of the traces given so far, or an instance of a static model whose structure differs from those of the instances given so far.
    void
    removeConstraint(int y, int x, int y2, int x2)
    removeConstraint: the constraint at the span, as the unsat core gives it (the second column one more than Alloy's).
    void
    resolve: solves the command again, from its first solution.
    void
    restoreState.
    void
    saveState: to generate counterexamples, the model is mutated; its state is saved first and restored once completed.
    void
    setBitwidth(int bitwidth)
    setBitwidth.
    void
    setGlobalScope(int scopeSize)
    setGlobalScope.
    void
    setMaxTraceLength(int maxTraceLength)
    setMaxTraceLength.
    void
    setScope(String sigName, int scopeSize)
    setScope: the scope of the sig with the given label.
    void
    unsatCoreMinimization: 0 (best), 1 or 2 (fastest).
    List<int[]>
    unsatCore: the spans of the constraints of the unsat core of the model, each as {line, column, line, column + 1}, or none.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • load

      public AlloySession.Loaded load(String model) throws edu.mit.csail.sdg.alloy4.Err
      load: parses the model.
      Throws:
      edu.mit.csail.sdg.alloy4.Err - the errors of the model
    • isDynamic

      public boolean isDynamic()
      Returns:
      whether the model has mutable sigs or fields: its solutions are traces
    • resolve

      public void resolve() throws edu.mit.csail.sdg.alloy4.Err
      resolve: solves the command again, from its first solution.
      Throws:
      edu.mit.csail.sdg.alloy4.Err
    • next

      public Optional<String> next() throws edu.mit.csail.sdg.alloy4.Err
      next: the next solution, if any.
      Throws:
      edu.mit.csail.sdg.alloy4.Err
    • fork

      public Optional<String> fork(int forkState) throws edu.mit.csail.sdg.alloy4.Err
      fork: a trace with the same states as the trace shown last before the given state, which differs from the traces given so far.
      Throws:
      edu.mit.csail.sdg.alloy4.Err
    • nextConfiguration

      public Optional<String> nextConfiguration() throws edu.mit.csail.sdg.alloy4.Err
      nextConfiguration: a trace whose relations that do not change over time differ from those of the traces given so far, or an instance of a static model whose structure differs from those of the instances given so far.
      Throws:
      edu.mit.csail.sdg.alloy4.Err
    • check

      public Optional<String> check(String assertion) throws edu.mit.csail.sdg.alloy4.Err
      check: the counterexample of the assertion with the given label, at the scopes and the trace length of the model, if any. It has no unsat core. The solutions of the model stay as they are.
      Throws:
      edu.mit.csail.sdg.alloy4.Err
    • setGlobalScope

      public void setGlobalScope(int scopeSize)
      setGlobalScope.
    • setScope

      public void setScope(String sigName, int scopeSize) throws edu.mit.csail.sdg.alloy4.ErrorSyntax
      setScope: the scope of the sig with the given label.
      Throws:
      edu.mit.csail.sdg.alloy4.ErrorSyntax
    • setBitwidth

      public void setBitwidth(int bitwidth)
      setBitwidth.
    • setMaxTraceLength

      public void setMaxTraceLength(int maxTraceLength)
      setMaxTraceLength.
    • setUnsatCoreMinimization

      public void setUnsatCoreMinimization(int level)
      unsatCoreMinimization: 0 (best), 1 or 2 (fastest).
    • saveState

      public void saveState()
      saveState: to generate counterexamples, the model is mutated; its state is saved first and restored once completed.
    • restoreState

      public void restoreState()
      restoreState.
    • removeConstraint

      public void removeConstraint(int y, int x, int y2, int x2)
      removeConstraint: the constraint at the span, as the unsat core gives it (the second column one more than Alloy's).
      Throws:
      IllegalStateException - if there is no constraint at the span
    • unsatCore

      public List<int[]> unsatCore()
      unsatCore: the spans of the constraints of the unsat core of the model, each as {line, column, line, column + 1}, or none. Only the model has an unsat core: not the next solution, when the solutions of the model run out. Alloy reports no minimized core when it finds the model unsatisfiable without solving, e.g., [ some b ] and [ no b ], so the core is not checked by its size.