Package statechum

Examples of statechum.Configuration


  /** For a maximal automaton, a reject-path overrides an accept-one. This is a test with a single-state graph. */
  @Test
  public void testPTAconstruction_singleRejectState_max()
  {
    Configuration config = mainConfiguration.copy();
    RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
    config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
    l.getTentativeAutomaton().initPTA();
    for(List<Label> sequence:buildSet(new String[][] { new String[]{} },config,converter))
      l.getTentativeAutomaton().paths.augmentPTA(sequence, false,true,null);
    for(List<Label> sequence:buildSet(new String[][] { },config,converter))
      l.getTentativeAutomaton().paths.augmentPTA(sequence, true,true,null);
View Full Code Here


   * @param expectedPTA a textual representation of a PTA which should be built.
   * @param expectMaxAutomataToBeTheSameAsPTA whether we expect augmentation of a maximal automaton to yield the same result as that of a normal PTA.
   */
  private void checkPTAconstruction(String[][] arrayPlusStrings,String [][] arrayMinusStrings, String expectedPTA, boolean expectMaxAutomataToBeTheSameAsPTA)
  {
    Configuration conf = mainConfiguration.copy();
    Set<List<Label>> plusStrings = buildSet(arrayPlusStrings,conf,converter), minusStrings = buildSet(arrayMinusStrings,conf,converter);
    LearnerGraph actualA = null, actualC =null, actualD = null, actualE = null, actualF = null;
    IllegalArgumentException eA = null, eC = null, eD = null, eE = null, eF = null;
    try
    {
      actualA = new LearnerGraph(Test_Orig_RPNIBlueFringeLearner.createAugmentedPTA(plusStrings, minusStrings),conf);
    }
    catch(IllegalArgumentException e)
    {
      // ignore this - it might be expected.
      eA = e;
    }

    try
    {
      Configuration config = mainConfiguration.copy();
      RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      l.init(plusStrings, minusStrings);
      actualC = l.getTentativeAutomaton();
    }
    catch(IllegalArgumentException e)
    {
      // ignore this - it might be expected.
      eC = e;
    }
   
    try
    {
      Configuration config = mainConfiguration.copy();
      RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      PTASequenceEngine engine = buildPTA(plusStrings, minusStrings);
      checkPTAConsistency(engine, plusStrings, true);if (engine.numberOfLeafNodes()>0) checkPTAConsistency(engine, minusStrings, false);
      l.init(engine,0,0);
      actualD = l.getTentativeAutomaton();
    }
    catch(IllegalArgumentException e)
    {
      // ignore this - it might be expected.
      eD = e;
    }

    try
    {
      Configuration config = mainConfiguration.copy();
      RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      l.init(buildPTA(plusStrings, buildSet(new String[][] {},config,converter)),0,0);
      for(List<Label> seq:minusStrings)
      {  Set<List<Label>> negativeSeq = new HashSet<List<Label>>();negativeSeq.add(seq);
        l.getTentativeAutomaton().paths.augmentPTA(buildPTA(buildSet(new String[][] {},config,converter),negativeSeq));
      }
      actualE = l.getTentativeAutomaton();
    }
    catch(IllegalArgumentException e)
    {
      // ignore this - it might be expected.
      eE = e;
    }

    try
    {
      Configuration config = mainConfiguration.copy();
      RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      l.getTentativeAutomaton().initPTA();
      l.getTentativeAutomaton().paths.augmentPTA(minusStrings, false,true);
      l.getTentativeAutomaton().paths.augmentPTA(plusStrings, true,true);
      actualF = l.getTentativeAutomaton();
    }
    catch(IllegalArgumentException e)
    {
      // ignore this - it might be expected.
      eF = e;
    }

    if (eA != null)
    {
      Assert.assertNotNull(eC);
      Assert.assertNotNull(eD);
      Assert.assertNotNull(eE);
      if (expectMaxAutomataToBeTheSameAsPTA) Assert.assertNotNull(eF);
      throw eA;
    }

    Assert.assertNull(eA);
    Assert.assertNull(eC);
    Assert.assertNull(eD);
    Assert.assertNull(eE);
    if (expectMaxAutomataToBeTheSameAsPTA) Assert.assertNull(eF);

    Configuration config = mainConfiguration.copy();
    config.setAllowedToCloneNonCmpVertex(true);
    checkM(expectedPTA,actualA, config,converter);
    checkM(expectedPTA,actualC, config,converter);checkDepthLabelling(actualC);
    //Visualiser.updateFrame(actualE,FsmParser.buildGraph(expectedPTA,"expected graph"));Visualiser.waitForKey();
    checkM(expectedPTA,actualD,config,converter);checkDepthLabelling(actualD);
    checkM(expectedPTA,actualE,config,converter);checkDepthLabelling(actualE);
View Full Code Here

   * @param expectedMAX a textual representation of a maximal automaton
   * which should be an outcome of augmenting the supplied one with the provided sequences.
   */
  private void checkMAXconstruction(String[][] arrayPlusStrings,String [][] arrayMinusStrings, String initialMax,String expectedMAX)
  {
    Configuration config = mainConfiguration.copy();
    Set<List<Label>> plusStrings = buildSet(arrayPlusStrings,config,converter), minusStrings = buildSet(arrayMinusStrings,config,converter);
   
    LearnerGraph graph = new LearnerGraph(config);
    if (initialMax != null)
      graph=FsmParser.buildLearnerGraph(initialMax, "initial_max",config,converter);
View Full Code Here

   * a maximal automaton or to a PTA.
   */
  @Test
  public void testAddPositive()
  {
    final Configuration conf = mainConfiguration;
    Set<List<Label>> plusStrings = buildSet(new String[][] {
        new String[]{"a","b","c"}, new String[]{"a","b"}, new String[]{"a","d","c"}},conf,converter),
    minusStrings = buildSet(new String[][] { new String[]{"a","b","c","d"}},conf,converter);

    for(boolean max:new boolean[]{true,false})
    {
      final boolean maxAutomaton = max;
      Configuration config = mainConfiguration.copy();
      final RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      l.getTentativeAutomaton().initPTA();
      l.getTentativeAutomaton().paths.augmentPTA(minusStrings, false,maxAutomaton);
      l.getTentativeAutomaton().paths.augmentPTA(plusStrings, true,maxAutomaton);
     
      checkForCorrectException(new whatToRun() { public @Override void run() throws NumberFormatException {
View Full Code Here

 
  /** Tests that updating a maximal automata can chop off parts of a tree. */
  @Test
  public void testPTAconstruction_max5()
  {
    Configuration config = mainConfiguration;
    Set<List<Label>> minusStrings = buildSet(new String[][] { new String[]{} },config,converter);
   
    LearnerGraph graph = buildLearnerGraph("A-a->B-b->C-c->A\nA-b->C-d->C", "initial_max",mainConfiguration.copy(),converter);
    graph.findVertex(VertexID.parseID("A")).setDepth(0);
    graph.config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
View Full Code Here

     
      // It is not hard to calculate what blue states will directly surround a specific state chosen to become red, however those blue states may in turn immediately become red after evaluation and the same would apply
      // to the newly-discovered red states, so we effectively have to re-implement blue state calculation here. For this reason, it was decided not to do this but instead clone the state machine (possibly in a trimmed form)
      // and ask it for a list of pairs.
      // In practice, this algorithm turned out to be rather slow because there could be many red states to choose from and among those, many would lead to many pairs, all of which have to be scored.
      Configuration configCloneAll = coregraph.config.copy();configCloneAll.setLearnerCloneGraph(true);// we need to clone vertices because chooseStatePairs would colour some of the vertices red or blue.
      for(CmpVertex tentativeRed:tentativeRedNodes)
      {
        LearnerGraph graph = new LearnerGraph(configCloneAll);LearnerGraph.copyGraphs(coregraph,graph);
        graph.findVertex(tentativeRed).setColour(JUConstants.RED);// mark the tentative blue as red
        Stack<PairScore> pairs = graph.pairscores.chooseStatePairs(null);// calculate the subsequent red-blue pairs
View Full Code Here

      // It is not hard to calculate what blue states will directly surround a specific state chosen to become red, however those blue states may in turn immediately become red after evaluation and the same would apply
      // to the newly-discovered red states, so we effectively have to re-implement blue state calculation here. For this reason, it was decided not to do this but instead clone the state machine (possibly in a trimmed form)
      // and ask it for a list of pairs.
      // Assuming that we received red states in the same order as they are encountered by Statechum, it is appropriate to return the first state that has the highest number of reds after mergers,
      // because where it is actually
      Configuration configCloneAll = coregraph.config.copy();configCloneAll.setLearnerCloneGraph(true);// we need to clone vertices because chooseStatePairs would colour some of the vertices red or blue.
      for(CmpVertex tentativeRed:tentativeRedNodes)
      {
        LearnerGraph graph = new LearnerGraph(configCloneAll);LearnerGraph.copyGraphs(coregraph,graph);
        graph.findVertex(tentativeRed).setColour(JUConstants.RED);// mark the tentative blue as red
        graph.pairscores.chooseStatePairs(null);// calculate the subsequent red-blue pairs
View Full Code Here

   * @return constructed graph.
   */
  public DirectedSparseGraph getGraph(String name)
  {
    DirectedSparseGraph result = null;
    Configuration cloneConfig = (Configuration)coregraph.config.clone();cloneConfig.setLearnerUseStrings(false);cloneConfig.setLearnerCloneGraph(true);
    synchronized (LearnerGraph.syncObj)
    {
      result = new DirectedSparseGraph();
      if (name != null)
        result.setUserDatum(JUConstants.TITLE, name,UserData.SHARED);
View Full Code Here

   */
  public static List<Boolean> mapPathToConfirmedElements(LearnerGraph hardFacts, List<Label> path, LearnerGraph [] ifthenAutomata)
  {
    List<Boolean> result = new ArrayList<Boolean>(path.size());
   
    final Configuration shallowCopy = hardFacts.config.copy();shallowCopy.setLearnerCloneGraph(false);
   
    for(int length=0;length < path.size();++length)
    {
      List<Label> prefix = path.subList(0, length+1);
      CmpVertex pathVertex = hardFacts.getVertex(prefix);
View Full Code Here

  public static <TARGET_A_TYPE,CACHE_A_TYPE extends CachedData<TARGET_A_TYPE, CACHE_A_TYPE>>
    void convertPairAssociationsToTransitions(DirectedSparseGraph whereTo,AbstractLearnerGraph<TARGET_A_TYPE, CACHE_A_TYPE> graph,Configuration config, ConvertALabel converter)
  {
    Set<Label> alphabet = graph.pathroutines.computeAlphabet();
   
    Configuration noClone = config.copy();noClone.setLearnerCloneGraph(false);
    LearnerGraphND result = new LearnerGraphND(graph,config);
    Set<CmpVertex> rowsProcessed = new HashSet<CmpVertex>();
   
    class TransitionAnnotationClass extends EdgeAnnotation
    {
View Full Code Here

TOP

Related Classes of statechum.Configuration

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.