Ejemplo n.º 1
0
 /**
  * Extracts the morphism from rule nodes to input graph nodes corresponding to the transition's
  * input parameters.
  *
  * @return if {@code null}, the binding cannot be constructed and so the rule cannot match
  */
 private RuleToHostMap extractBinding(Step step) {
   RuleToHostMap result = this.state.getGraph().getFactory().createRuleToHostMap();
   Object[] sourceValues = this.state.getActualValues();
   for (Assignment assign : step.getEnterAssignments()) {
     sourceValues = assign.compute(sourceValues);
   }
   for (Pair<Var, Binding> entry : step.getRuleSwitch().getCallBinding()) {
     Binding bind = entry.two();
     HostNode value;
     if (bind == null) {
       // this corresponds to an output parameter of the call
       continue;
     }
     switch (bind.getSource()) {
       case CONST:
         value = bind.getValue().getNode();
         break;
       case VAR:
         value = Valuator.get(sourceValues, bind);
         break;
       default:
         assert false;
         value = null;
     }
     RuleNode ruleNode = entry.one().getRuleNode();
     if (isCompatible(ruleNode, value)) {
       result.putNode(ruleNode, value);
     } else {
       result = null;
       break;
     }
   }
   return result;
 }
Ejemplo n.º 2
0
 @Override
 public void report() throws IOException {
   Pair<FileType, Exporter> stateFormat = Exporters.getAcceptingFormat(this.statePattern);
   if (stateFormat == null) {
     this.logger.append(
         "Pattern %s does not specify export format: states saved in native GXL%n",
         this.statePattern);
   } else {
     this.logger.append("States saved as %s%n", stateFormat.one().getDescription());
   }
   for (GraphState state : getExploration().getResult()) {
     File savedFile = exportState(state, this.statePattern);
     this.logger.append("State saved: %s%n", savedFile);
   }
 }
Ejemplo n.º 3
0
 /**
  * Exports a given state using a filename derived from a state pattern.
  *
  * @param state the state to be exported
  * @param pattern the filename pattern
  * @throws IOException if anything went wrong during export
  */
 public static File exportState(GraphState state, String pattern) throws IOException {
   String stateFilename = pattern.replace(PLACEHOLDER, "" + state.getNumber());
   File stateFile = new File(stateFilename);
   Pair<FileType, Exporter> stateFormat = Exporters.getAcceptingFormat(stateFilename);
   if (stateFormat != null) {
     try {
       stateFormat.two().doExport(new Exportable(state.getGraph()), stateFile, stateFormat.one());
     } catch (PortException e1) {
       throw new IOException(e1);
     }
   } else {
     if (!FileType.hasAnyExtension(stateFile)) {
       stateFile = FileType.STATE.addExtension(stateFile);
     }
     Groove.saveGraph(GraphConverter.toAspect(state.getGraph()), stateFile);
   }
   return stateFile;
 }