PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-3_0_1/src/groove/verify/ModelChecking.java

https://bitbucket.org/wthys/groove
Java | 244 lines | 106 code | 29 blank | 109 comment | 9 complexity | 1a255bd1eef9a84b2528ae711bd41730 MD5 | raw file
  1. /* GROOVE: GRaphs for Object Oriented VErification
  2. * Copyright 2003--2007 University of Twente
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing,
  10. * software distributed under the License is distributed on an
  11. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12. * either express or implied. See the License for the specific
  13. * language governing permissions and limitations under the License.
  14. *
  15. * $Id: ModelChecking.java,v 1.5 2008/03/20 13:29:51 kastenberg Exp $
  16. */
  17. package groove.verify;
  18. import groove.explore.DefaultScenario;
  19. import groove.explore.strategy.DefaultBoundedModelCheckingStrategy;
  20. import groove.graph.Edge;
  21. import groove.lts.GTS;
  22. import groove.trans.Rule;
  23. import groove.util.Reporter;
  24. import java.util.Collection;
  25. import rwth.i2.ltl2ba4j.model.IGraphProposition;
  26. /**
  27. * This class contains a number of constants to be used for model checking.
  28. * @author Harmen Kastenberg
  29. * @version $Revision: 1.5 $
  30. */
  31. public class ModelChecking {
  32. /** constant for non-toggled state colour white */
  33. public static final int NO_COLOUR = 0;
  34. /** constant for state colour black (so-called pocket state) */
  35. // public static final int BLACK = 1;
  36. /** constant for non-toggled state colour white */
  37. public static final int WHITE = 2;
  38. /** constant for non-toggled state colour cyan */
  39. public static final int CYAN = 3;
  40. /** constant for non-toggled state colour blue */
  41. public static final int BLUE = 4;
  42. /** constant for non-toggled state colour red */
  43. public static final int RED = 5;
  44. /** constant for toggled state colour white */
  45. public static final int WHITE_TOGGLE = -2;
  46. /** constant for toggled state colour cyan */
  47. public static final int CYAN_TOGGLE = -3;
  48. /** constant for toggled state colour blue */
  49. public static final int BLUE_TOGGLE = -4;
  50. /** constant for toggled state colour red */
  51. public static final int RED_TOGGLE = -5;
  52. /** the value for the colour white in the current colour-scheme. */
  53. public static int CURRENT_WHITE = WHITE;
  54. /** the value for the colour cyan in the current colour-scheme. */
  55. public static int CURRENT_CYAN = CYAN;
  56. /** the value for the colour blue in the current colour-scheme. */
  57. public static int CURRENT_BLUE = BLUE;
  58. /** the value for the colour red in the current colour-scheme. */
  59. public static int CURRENT_RED = RED;
  60. /** constant to keep track of dynamic colour-schemes */
  61. private static int NEXT_FREE_COLOUR = 6;
  62. /** the value for marking pocket states */
  63. public static int POCKET = 1;
  64. /** the value for marking non-pocket states */
  65. public static int NO_POCKET = -1;
  66. /** constant for notifying the system is OK */
  67. public static final int OK = 1;
  68. /** constant for notifying that a counter-example has been identified */
  69. public static final int COUNTER_EXAMPLE = 2;
  70. /** constant for the true label in the Buchi automaton */
  71. public static final String SIGMA = "<SIGMA>";
  72. /** constant for the conjunction symbol in labels in the Buchi automaton */
  73. public static final String CONJUNCTION_SYMBOL = "&";
  74. private static boolean TOGGLE = false;
  75. /** constant specifying whether to mark pocket-states */
  76. public static boolean MARK_POCKET_STATES;
  77. /** constant specifying the maximal number of iterations to be performed */
  78. public static int MAX_ITERATIONS = -1;
  79. /** constant specifying the maximal number of iterations to be performed */
  80. public static int CURRENT_ITERATION = 0;
  81. /** constant specifying the maximal amount of time to spend */
  82. public static long MINUTES = -1;
  83. /** constant specifying the maximal amount of time to spend */
  84. public static long MAX_TIME = 0;
  85. /** constant specifying the maximal amount of time to spend */
  86. public static boolean START_FROM_BORDER_STATES = false;
  87. /**
  88. * Return the current constant for the colour white.
  89. * @return the constant {@link ModelChecking#CURRENT_WHITE}
  90. */
  91. public static int white() {
  92. return CURRENT_WHITE;
  93. }
  94. /**
  95. * Return the current constant for the colour cyan.
  96. * @return the constant {@link ModelChecking#CURRENT_CYAN}
  97. */
  98. public static int cyan() {
  99. return CURRENT_CYAN;
  100. }
  101. /**
  102. * Return the current constant for the colour blue.
  103. * @return the constant {@link ModelChecking#CURRENT_BLUE}
  104. */
  105. public static int blue() {
  106. return CURRENT_BLUE;
  107. }
  108. /**
  109. * Return the current constant for the colour red.
  110. * @return the constant {@link ModelChecking#CURRENT_RED}
  111. */
  112. public static int red() {
  113. return CURRENT_RED;
  114. }
  115. /**
  116. * Return the constant for the colour black. This colour
  117. * is shared by all colour-schemes.
  118. * @return the constant {@link ModelChecking#BLACK}
  119. */
  120. // public static int black() {
  121. // return BLACK;
  122. // }
  123. /**
  124. * Toggle the colour-scheme used.
  125. */
  126. public static void toggle() {
  127. TOGGLE = !TOGGLE;
  128. if (TOGGLE) {
  129. CURRENT_WHITE = WHITE_TOGGLE;
  130. CURRENT_CYAN = CYAN_TOGGLE;
  131. CURRENT_BLUE = BLUE_TOGGLE;
  132. CURRENT_RED = RED_TOGGLE;
  133. } else {
  134. CURRENT_WHITE = WHITE;
  135. CURRENT_CYAN = CYAN;
  136. CURRENT_BLUE = BLUE;
  137. CURRENT_RED = RED;
  138. }
  139. }
  140. /**
  141. * Reset the iteration counter.
  142. */
  143. public static void resetIteration() {
  144. CURRENT_ITERATION = 0;
  145. }
  146. /**
  147. * Increase the iteration count.
  148. */
  149. public static void nextIteration() {
  150. CURRENT_ITERATION++;
  151. // updateColourScheme();
  152. }
  153. public static void updateColourScheme() {
  154. if (ModelChecking.START_FROM_BORDER_STATES) {
  155. nextColourScheme();
  156. }
  157. }
  158. /**
  159. * Instantiate a fresh colour-scheme.
  160. */
  161. public static void nextColourScheme() {
  162. assert (NEXT_FREE_COLOUR % 4 == 2) : "Faulty colour-scheme in use: constant for WHITE should be have value n*4+1";
  163. CURRENT_WHITE = nextFreeColour();
  164. CURRENT_CYAN = nextFreeColour();
  165. CURRENT_BLUE = nextFreeColour();
  166. CURRENT_RED = nextFreeColour();
  167. }
  168. /**
  169. * Returns the next integer value that is available for colouring.
  170. * @return the next integer value that is available for colouring.
  171. */
  172. private static int nextFreeColour() {
  173. return NEXT_FREE_COLOUR++;
  174. }
  175. /**
  176. * Checks whether a Buchi-transition is enabled, given a set
  177. * of rule-names of applicable rules.
  178. * @return <tt>true</tt> if the given transition is enabled,
  179. * <tt>false</tt> otherwise
  180. */
  181. public static boolean isPropertyTransitionEnabled(BuchiTransition transition, Collection<Rule> rules) {
  182. boolean result = true;
  183. for (IGraphProposition gp: transition.getLabels()) {
  184. if (gp.getFullLabel().equals(SIGMA)) {
  185. continue;
  186. }
  187. boolean applicable = false;
  188. // only take the label of the proposition - negation will be checked afterwards
  189. String prop = gp.getLabel();
  190. for (Rule rule: rules) {
  191. if (prop.equals(rule.getName().name())) {
  192. applicable = true;
  193. }
  194. }
  195. boolean match = (gp.isNegated() ^ applicable);
  196. result = result && match;
  197. }
  198. return result;
  199. }
  200. /**
  201. * Checks whether the given edge is labelled with {@link ModelChecking#SIGMA}.
  202. * @param edge the edge to be checked
  203. * @return <tt>true</tt> if the edge is indeed labelled with
  204. * {@link ModelChecking#SIGMA}, <tt>false</tt> otherwise
  205. */
  206. public static boolean hasSigmaLabel(Edge edge) {
  207. return edge.label().text().equals(SIGMA);
  208. }
  209. /** Reporter for profiling information. */
  210. // static public final Reporter reporter = Reporter.register(ModelChecking.class);
  211. // static public final int POCKET_STATE_REPORTER = reporter.newMethod("blackPainting()");
  212. // public static int NEXT = reporter.newMethod("ModelChecking.next");
  213. // public static int UPDATE = reporter.newMethod("ModelChecking.updateNext");
  214. // public static int BACKTRACK = reporter.newMethod("ModelChecking.backtrack");
  215. }