Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.LearnerGraphND$ignoreNoneClass


 
  @Test
  public final void testGD_nondetA()
  {
    Configuration config = Configuration.getDefaultConfiguration();
    final LearnerGraphND
      grA=buildLearnerGraphND("A-x->A-a->C-u->C-v->C-c->F\nC-c->G\nC-c->A\nC-b->A\n"+
        "G-b->A\nG-a->C\nG-b->F\n"+
        "F-a->A\nF-a->C\nF-a->G\n"
        , "TestGD_MultipleCasesOfRenamingA",config,converter),
      grB = buildLearnerGraphND(
View Full Code Here


  /** Clashes between disconnected vertices and the original ones. */
  @Test
  public final void testGD_nondetB()
  {
    Configuration config = Configuration.getDefaultConfiguration();
    final LearnerGraphND
      grA=buildLearnerGraphND("A-x->A-a->C-u->C-v->C-c->F\nC-c->G\nC-c->A\nC-b->A\n"+
        "G-b->A\nG-a->C\nG-b->F\n"+
        "F-a->A\nF-a->C\nF-a->G\n"
        , "TestGD_MultipleCasesOfRenamingA",config,converter),
      grB = buildLearnerGraphND(
        "B-x->B-a->D-u->D-v->D-b->"+stateC+"-b->D\n"+stateC+"-b->A\n"+stateC+"-b->G\n", "TestGD_MultipleCasesOfRenamingB_"+stateC,config,converter);
    CmpVertex disconnectedA1 = AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID("T"), config),
      disconnectedA2 = AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID("U"), config),
      disconnectedB2 = AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID("U"), config),
      disconnectedB3 = AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID("E"), config);
    disconnectedA1.setColour(JUConstants.BLUE);disconnectedA2.setColour(JUConstants.AMBER);
    disconnectedB2.setHighlight(true);disconnectedB3.setDepth(5);
    grA.transitionMatrix.put(disconnectedA1,grA.createNewRow());grA.transitionMatrix.put(disconnectedA2,grA.createNewRow());
    grB.transitionMatrix.put(disconnectedB2,grB.createNewRow());grB.transitionMatrix.put(disconnectedB3,grB.createNewRow());
   
    String [] expectedDuplicates = (stateC.equals("C"))? new String[]{ stateC,"A" }:new String[]{"A"};
    LearnerGraphND outcome = runTest(grA,grB, "D", expectedDuplicates);
    Assert.assertNull(outcome.findVertex(disconnectedA1));
    Assert.assertTrue(DeterministicDirectedSparseGraph.deepEquals(disconnectedB2, outcome.findVertex(disconnectedB2)));
    Assert.assertTrue(DeterministicDirectedSparseGraph.deepEquals(disconnectedB3, outcome.findVertex(disconnectedB3)));
  }
View Full Code Here

  /** Graph B is slightly different now, hence duplicates are different too. */
  @Test
  public final void testGD_nondetC()
  {
    Configuration config = Configuration.getDefaultConfiguration().copy();
    final LearnerGraphND
      grA=buildLearnerGraphND("A-x->A-a->C-u->C-c->F\nC-c->G\nC-c->A\nC-b->A\n"+
        "G-b->A\nG-a->C\nG-b->F\n"+
        "F-a->A\nF-a->C\nF-a->G\n"
        , "TestGD_MultipleCasesOfRenamingA",config,converter),
      grB = buildLearnerGraphND(
View Full Code Here

    Set<CmpVertex> duplicatesExpected = new TreeSet<CmpVertex>();
    for(String dup:duplicatesExpectedString) duplicatesExpected.add(gd.origToNewB.get(grB.findVertex(VertexID.parseID(dup))));
   
    Assert.assertEquals(duplicatesExpected,gd.duplicates);
    Configuration cloneConfig = config.copy();cloneConfig.setLearnerCloneGraph(true);
    LearnerGraphND graph = new LearnerGraphND(cloneConfig);AbstractLearnerGraph.copyGraphs(grA, graph);
    ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()), converter);
    LearnerGraphND outcome = new LearnerGraphND(config);AbstractLearnerGraph.copyGraphs(graph, outcome);
    Assert.assertNull(WMethod.checkM(grB, graph));

    // Now do the same as above, but renumber states to match grB
    AbstractLearnerGraph.copyGraphs(grA, graph);
    Configuration configMut = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
    LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> graphPatcher = new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(graph,configMut,null);
    ChangesRecorder.loadDiff(graphPatcher, recorder.writeGD(TestGD.createDoc()), converter);
    graphPatcher.removeDanglingStates();
    LearnerGraphND result = new LearnerGraphND(configMut);
    graphPatcher.relabel(result);
    Assert.assertNull(WMethod.checkM_and_colours(grB, result,VERTEX_COMPARISON_KIND.DEEP));
    return outcome;
  }
View Full Code Here

 
  @Test
  public final void testGD_nondet_incompatibles()
  {
    Configuration config = Configuration.getDefaultConfiguration();
    final LearnerGraphND
      grA=buildLearnerGraphND("A-x->A-a->C-u->C-c->F\nC-v->C\nC-c->G\nC-c->A\nC-b->A\n"+
        "G-b->A\nG-b->C\nG-b->F\n"+
        "F-a->A\nF-a->C\nF-a->G\n"
        , "TestGD_MultipleCasesOfRenamingA",config,converter),
      grB = buildLearnerGraphND(
        "B-x->B-a->D-u->D-v->D-b->"+stateC+"-bD->D\n"+stateC+"-bA->A\n"+stateC+"-bG->G\n"+stateC+"-bE->E\n", "TestGD_MultipleCasesOfRenamingB_"+stateC,config,converter);
       
    // add incompatibles for A
    for(String []pair:new String[][]{
        new String[]{"A","C"},
        new String[]{"A","F"},
        new String[]{"C","G"},
        new String[]{"C","F"}
    })
    {
      CmpVertex a=grA.findVertex(pair[0]),b=grA.findVertex(pair[1]);
      Assert.assertNotNull(a);Assert.assertNotNull(b);
      grA.addToCompatibility(a,b,JUConstants.PAIRCOMPATIBILITY.INCOMPATIBLE);
    }
   
    // add incompatibles for B
    for(String []pair:new String[][]{
        new String[]{"B","D"},
View Full Code Here

  public static DirectedSparseGraph obtainDifferenceGraph(String graphA, String graphB,int counter,boolean display)
  {
    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd =
      new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
    Configuration config = Configuration.getDefaultConfiguration();
    LearnerGraphND grA=new LearnerGraphND(buildGraph(graphA, "labellingDemo_A_"+counter),config),grB=
    new LearnerGraphND(buildGraph(graphB, "labellingDemo_B_"+counter),config);
    DirectedSparseGraph gr = gd.showGD(
        grA,grB,
        ExperimentRunner.getCpuNumber());
    if (display)
    {
View Full Code Here

   * @return inverted graph
   */
  public static LearnerGraphND computeInverseGraph(LearnerGraph graph)
  {
    Configuration shallowCopy = graph.config.copy();shallowCopy.setLearnerCloneGraph(false);
    LearnerGraphND inverseGraph = new LearnerGraphND(shallowCopy);inverseGraph.initEmpty();
    AbstractPathRoutines.buildInverse(graph,LearnerGraphND.ignoreNone,inverseGraph)// do the inverse to the tentative graph
    return inverseGraph;
  }
View Full Code Here

   * @return inverted graph
   */
  public static LearnerGraphND computeInverseGraph(LearnerGraph graph)
  {
    Configuration shallowCopy = graph.config.copy();shallowCopy.setLearnerCloneGraph(false);
    LearnerGraphND inverseGraph = new LearnerGraphND(shallowCopy);inverseGraph.initEmpty();
    AbstractPathRoutines.buildInverse(graph,LearnerGraphND.ignoreNone,inverseGraph)// do the inverse to the tentative graph
    return inverseGraph;
  }
View Full Code Here

      }
  }
 
  public static void printTraceLeadingTo(LearnerGraph graph, String vert)
  {
    LearnerGraphND ptaInverse = new LearnerGraphND(graph.config);
    AbstractPathRoutines.buildInverse(graph, new StatesToConsider() {
      @Override public boolean stateToConsider(@SuppressWarnings("unused") CmpVertex v) { return true; }}
      , ptaInverse);
    CmpVertex v=ptaInverse.findVertex(vert);
    for(int i=0;i<10;++i)
    {
      Map<Label,List<CmpVertex>> transitions = ptaInverse.transitionMatrix.get(v);
      if (transitions.size() > 1)
      {
View Full Code Here

                        if (command.equals(msgComputeDiff) && message.arity() == 4)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            LearnerGraphND grA = new LearnerGraphND(learnerInitConfiguration.config), grB = new LearnerGraphND(learnerInitConfiguration.config);
                            Synapse.StatechumProcess.parseStatemachine(message.elementAt(2),grA,null,true);
                            Synapse.StatechumProcess.parseStatemachine(message.elementAt(3),grB,null,true);
                            OtpErlangObject difference  = DifferenceVisualiser.ChangesToGraph.computeGD(grA, grB, learnerInitConfiguration.config);
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,difference});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,learn, pid
                        // pid is optional, where provided, progress messages are reported in a form of {Ref,'status',step}
                        // in the course of learning, the learner is receptive to messages directed at its normal PID, a {Ref,terminate} command will kill it and the response will be {Ref,terminate}.
                        // Response: Ref,ok,fsm
                        // on error: Ref,failure,text_of_the_error (as string)
                        if (command.equals(msgLearnEDSM) && message.arity() >= 2)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            final AtomicLong counter = new AtomicLong();
                            RPNIUniversalLearner learner = new RPNIUniversalLearner(null, learnerInitConfiguration) {

                              @Override
                              public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
                              {
                                // send the notification if necessary
                                if (message.arity() > 2 && message.elementAt(2) instanceof OtpErlangPid)
                                  sendProgress((OtpErlangPid)message.elementAt(2), ref, graph, null, counter);
                               
                                // check if we were asked to terminate
                                try {
                                  OtpErlangObject messageReceived = mbox.receive(0);// do not wait, return null if anything received
                                  if (messageReceived != null && messageReceived instanceof OtpErlangTuple && ((OtpErlangTuple)messageReceived).arity() == 2)
                                  {
                                    OtpErlangTuple cmd = ((OtpErlangTuple)messageReceived);
                                    if (cmd.elementAt(0).equals(ref) && cmd.elementAt(1).equals(msgStop))
                                      throw new AskedToTerminateException();
                                  }
                                } catch (OtpErlangExit e) {
                                  Helper.throwUnchecked("node exited", e);
                                } catch (OtpErlangDecodeException e) {
                                  Helper.throwUnchecked("decode exception", e);
                                }
                                // resume learning.
                                return super.ChooseStatePairs(graph);
                              }

                              @Override
                              public Pair<Integer, String> CheckWithEndUser(
                                  LearnerGraph model,
                                  List<Label> question,
                                  int expectedForNoRestart,
                                  List<Boolean> consistentFacts,
                                  PairScore pairBeingMerged,
                                  Object[] moreOptions) {

                                return super.CheckWithEndUser(model, question, expectedForNoRestart,
                                    consistentFacts, pairBeingMerged, moreOptions);
                              }
                             
                            };
                            learner.init(sPlus, sMinus);
                            if (learnerInitConfiguration.graph != null)
                            {
                              learnerInitConfiguration.graph.clearColours();learnerInitConfiguration.graph.getInit().setColour(JUConstants.RED);
                              LearnerGraph.copyGraphs(learnerInitConfiguration.graph,learner.getTentativeAutomaton());
                            }
                            LearnerGraph graphLearnt = learner.learnMachine();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  constructFSM(graphLearnt)});
                          }
                          catch(AskedToTerminateException e)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgTerminate});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                         
                        }
                        else
                        // Args: Ref,learn, pid
                        // pid is optional, where provided, progress messages are reported in a form of {Ref,'status',step}
                        // in the course of learning, the learner is receptive to messages directed at its normal PID, a {Ref,terminate} command will kill it and the response will be {Ref,terminate}.
                        // Response: Ref,ok,fsm
                        // on error: Ref,failure,text_of_the_error (as string)
                        if (command.equals(msgLearnEDSMMARKOV) && message.arity() >= 2)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            final AtomicLong counter = new AtomicLong();
                            learnerInitConfiguration.config.setLearnerScoreMode(ScoreMode.ONLYOVERRIDE);
                            LearnerGraph pta=new LearnerGraph(learnerInitConfiguration.config);
                            for(List<Label> seq:sPlus)
                              pta.paths.augmentPTA(seq,true,false,null);
                            for(List<Label> seq:sMinus)
                              pta.paths.augmentPTA(seq,false,false,null);
                            final MarkovModel m= new MarkovModel(3,true,true,false);

                            new MarkovClassifier(m, pta).updateMarkov(false);// construct Markov chain if asked for.
                            final ConsistencyChecker checker = new MarkovClassifier.DifferentPredictionsInconsistencyNoBlacklistingIncludeMissingPrefixes();
                         
                            pta.clearColours();
                            EDSM_MarkovLearner learner = new EDSM_MarkovLearner(learnerInitConfiguration,pta,0) {

                              @Override
                              public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
                              {
                                // send the notification if necessary
                                if (message.arity() > 2 && message.elementAt(2) instanceof OtpErlangPid)
                                  sendProgress((OtpErlangPid)message.elementAt(2), ref, graph, null, counter);
                               
                                // check if we were asked to terminate
                                try {
                                  OtpErlangObject messageReceived = mbox.receive(0);// do not wait, return null if anything received
                                  if (messageReceived != null && messageReceived instanceof OtpErlangTuple && ((OtpErlangTuple)messageReceived).arity() == 2)
                                  {
                                    OtpErlangTuple cmd = ((OtpErlangTuple)messageReceived);
                                    if (cmd.elementAt(0).equals(ref) && cmd.elementAt(1).equals(msgStop))
                                      throw new AskedToTerminateException();
                                  }
                                } catch (OtpErlangExit e) {
                                  Helper.throwUnchecked("node exited", e);
                                } catch (OtpErlangDecodeException e) {
                                  Helper.throwUnchecked("decode exception", e);
                                }
                                // resume learning.
                                return super.ChooseStatePairs(graph);
                              }

                              @Override
                              public Pair<Integer, String> CheckWithEndUser(
                                  LearnerGraph model,
                                  List<Label> question,
                                  int expectedForNoRestart,
                                  List<Boolean> consistentFacts,
                                  PairScore pairBeingMerged,
                                  Object[] moreOptions) {

                                return super.CheckWithEndUser(model, question, expectedForNoRestart,
                                    consistentFacts, pairBeingMerged, moreOptions);
                              }
                             
                            };
                            learner.setMarkov(m);learner.setChecker(checker);
                            learner.setUseNewScoreNearRoot(false);learner.setUseClassifyPairs(false);
                            learner.setDisableInconsistenciesInMergers(false);
                           
                            if (learnerInitConfiguration.graph != null)
                            {
                              learnerInitConfiguration.graph.clearColours();learnerInitConfiguration.graph.getInit().setColour(JUConstants.RED);
                              LearnerGraph.copyGraphs(learnerInitConfiguration.graph,learner.getTentativeAutomaton());
                            }
                            LearnerGraph graphLearnt = learner.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  constructFSM(graphLearnt)});
                          }
                          catch(AskedToTerminateException e)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgTerminate});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                         
                        }
                        else
                        // Args: Ref,addTypeInformation,list of pairs containing method names and types.
                        if (command.equals(msgAddTypeInformation) && message.arity() >= 3)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            updateFrom((OtpErlangList)message.elementAt(2), overrides);
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  typeMapToList(overrides)});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,purgeModuleInformation
                        // Since using addTypeInformation followed by learnErlang causes changes to the alphabet modules we are dealing with, independence of tests requires the collection of loaded modules to be purged. This is the purpose of this function.
                        if (command.equals(msgPurgeModuleInformation) && message.arity() >= 2)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            ErlangModule.flushRegistry();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,extractTypeInformation,moduleFileFullPath.
                        // Returns a list of pairs of method names and types.
                        if (command.equals(msgExtractTypeInformation) && message.arity() >= 3)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            ErlangModule.setupErlangConfiguration(learnerInitConfiguration.config, new File(((OtpErlangAtom)message.elementAt(2)).atomValue()));
                           
                            // we start a separate Erlang node to run the questions
                            ErlangRunner erlangRunner = ErlangRuntime.getDefaultRuntime().createNewRunner();
                            learnerInitConfiguration.config.setErlangMboxName(erlangRunner.getRunnerName());
                            final ErlangModule mod = ErlangModule.loadModule(learnerInitConfiguration.config);
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  typeMapToList(mod.sigTypes)});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,learnErlang,moduleFileFullPath, pid
                        // pid is optional, where provided, progress messages are reported in a form of {Ref,'status',step}
                        // in the course of learning, the learner is receptive to messages directed at its normal PID, a {Ref,terminate} command will kill it and the response will be {Ref,terminate}.
                        // Response: Ref,ok,fsm
                        // on error: Ref,failure,text_of_the_error (as string)
                        if (command.equals(msgLearnErlang) && message.arity() >= 3)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            ErlangModule.setupErlangConfiguration(learnerInitConfiguration.config, new File(((OtpErlangAtom)message.elementAt(2)).atomValue()));
                           
                            // we start a separate Erlang node to run the questions
                            ErlangRunner erlangRunner = ErlangRuntime.getDefaultRuntime().createNewRunner();
                            learnerInitConfiguration.config.setErlangMboxName(erlangRunner.getRunnerName());
                            final AtomicLong counter = new AtomicLong();
                            final ErlangModule mod = ErlangModule.loadModule(learnerInitConfiguration.config);
                            mod.rebuildSigs(learnerInitConfiguration.config, overrides);mod.behaviour.generateAlphabet(learnerInitConfiguration.config);
                           
                            ErlangOracleLearner learner = new ErlangOracleLearner(null, learnerInitConfiguration) {

                              @Override
                              public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
                              {
                                // check if we were asked to terminate
                                try {
                                  if (message.arity() > 3 && message.elementAt(3) instanceof OtpErlangPid)
                                    // send the notification if necessary
                                    sendProgress((OtpErlangPid)message.elementAt(3), ref, graph, mod, counter);

                                  OtpErlangObject messageReceived = mbox.receive(0);// do not wait, return null if anything received
                                  if (messageReceived != null && messageReceived instanceof OtpErlangTuple && ((OtpErlangTuple)messageReceived).arity() == 2)
                                  {
                                    OtpErlangTuple cmd = ((OtpErlangTuple)messageReceived);
                                    if (cmd.elementAt(0).equals(ref) && cmd.elementAt(1).equals(msgStop))
                                      throw new AskedToTerminateException();
                                  }
                                } catch (OtpErlangExit e) {
                                  Helper.throwUnchecked("node exited", e);
                                } catch (OtpErlangDecodeException e) {
                                  Helper.throwUnchecked("decode exception", e);
                                }
                               
                                // resume learning.
                                return super.ChooseStatePairs(graph);
                              }

                              @Override
                              public Pair<Integer, String> CheckWithEndUser(
                                  LearnerGraph model,
                                  List<Label> question,
                                  int expectedForNoRestart,
                                  List<Boolean> consistentFacts,
                                  PairScore pairBeingMerged,
                                  Object[] moreOptions) {
                                return super.CheckWithEndUser(model, question, expectedForNoRestart,consistentFacts, pairBeingMerged, moreOptions);
                              }
                             
                            };
                            if (learnerInitConfiguration.config.getAskQuestions()) // only generate initial traces if we are permited to ask questions.
                              learner.init(learner.GenerateInitialTraces(learnerInitConfiguration.config.getErlangInitialTraceLength()),0,0);
                            System.out.println("random trace generation complete");
                            LearnerGraph graphLearnt = learner.learnMachine(),
                                graphWithTrimmedLabels = new LearnerGraph(learnerInitConfiguration.config);
                           
                            if (learnerInitConfiguration.config.getErlangStripModuleNamesFromFunctionsInNonGenModules())
                              convertLabelsToStrings(graphLearnt,graphWithTrimmedLabels);
                            else
                              AbstractLearnerGraph.interpretLabelsOnGraph(graphLearnt,graphWithTrimmedLabels,mod.behaviour.new ConverterModToErl());
                           
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  constructFSM(graphWithTrimmedLabels)});
                            erlangRunner.close();
                          }
                          catch(AskedToTerminateException e)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgTerminate});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                         
                        }
                        else
                        if (command.equals(msgTestDiffParsing) && message.arity() == 4) // this one computes a graph reflecting the differences and returns the labelling part of it as a string. Inputs are one of the original machines and the differences.
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            DirectedSparseGraph diff = DifferenceVisualiser.ChangesToGraph.computeVisualisationParameters(message.elementAt(2), message.elementAt(3));
                           
                            Set<String> modifiedLines = new TreeSet<String>();
                            for(Object obj:diff.getEdges()) // getEdges returns edges in a JDK-dependent order, we use TreeSet to sort them so that expected values can be determined without associating them with specific versions of JDK.
                            {
                              StringBuffer textOfTheOutcome = new StringBuffer();
                             
                              textOfTheOutcome.append(obj.toString());textOfTheOutcome.append(":");textOfTheOutcome.append( ((Edge)obj).getUserDatum(JUConstants.DIFF) );
                              modifiedLines.add(textOfTheOutcome.toString());
                            }
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,new OtpErlangAtom(modifiedLines.toString())});
                          }
                          catch(Throwable ex)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                         
                        // Arguments: Ref, 'displayDiff', first graph, diff, atom with the name of the difference and (optional) list of states (as atoms) to ignore.
                        // Upon error, no notifications are sent and instead an error is reported.
                        // Note: if the difference name is an empty sequence, no graph is displayed but notifications are provided (for testing).
                        if (command.equals(msgDisplayDiff) && message.arity() >= 5)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            DirectedSparseGraph diff = DifferenceVisualiser.ChangesToGraph.computeVisualisationParameters(message.elementAt(2), message.elementAt(3));
                            int windowNumber = setOptions(message,4,diff);
                            if (windowNumber >= 0)
                              Visualiser.updateFrameWithPos(diff,windowNumber);

                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk});
                          }
                          catch(Throwable ex)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                          // Arguments: Ref, 'displayFSM', graph, atom with the name of the difference and (optional) list of states (as atoms) to ignore.
                          // Upon error, no notifications are sent and instead an error is reported.
                          // Note: if the difference name is an empty sequence, no graph is displayed but notifications are provided (for testing).
                          if (command.equals(msgDisplayFSM) && message.arity() >= 4)
                          {
                            OtpErlangObject outcome = null;
                            try
                            {
                              Configuration config = Configuration.getDefaultConfiguration().copy();
                              LearnerGraphND machine = new LearnerGraphND(config);Synapse.StatechumProcess.parseStatemachine(message.elementAt(2),machine,null,true);
                              DirectedSparseGraph fsmPicture = machine.pathroutines.getGraph();
                              if (!fsmPicture.containsUserDatumKey(JUConstants.LAYOUTOPTIONS))
                                fsmPicture.addUserDatum(JUConstants.LAYOUTOPTIONS,new LayoutOptions(), UserData.SHARED);
                              int windowNumber = setOptions(message,3,fsmPicture);
                              if (windowNumber >= 0)
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.LearnerGraphND$ignoreNoneClass

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.