Esempio n. 1
0
  @Test
  public void testConvertLinearDynamicTwoVarsOneInput() {
    String path = UNIT_BASEDIR + "linear_dynamic/";
    SpaceExDocument test1 =
        SpaceExImporter.importModels(
            path + "two_var_one_input.cfg", path + "two_var_one_input.xml");

    Configuration c = flatten(test1);
    BaseComponent ha = (BaseComponent) c.root;

    Classification cls = new Classification();
    Classification.ha = ha;
    cls.setVarID(ha);
    SimulinkStateflowPrinter sp = new SimulinkStateflowPrinter();
    sp.ha = ha;
    // sp.setVarID(ha);
    AutomatonMode mode = ha.modes.get("running");
    cls.setLinearMatrix(mode);

    String A = sp.convertFlowToAMatrix(mode);
    String resultA = "[-1.0 4.0 ;-2.0 -3.0 ;]";
    Assert.assertEquals(resultA, A);
    String B = sp.convertInputToBMatrix(mode);
    String resultB = "[-0.2 2.0 ;]";
    Assert.assertEquals(resultB, B);
  }
Esempio n. 2
0
  @Test
  public void testClassifySubtract() {
    String[][] dy = {{"x", "-x - 2 * y -0.2 * u"}, {"y", "4 * x - 3 * y + 2 * u"}, {"u", "1"}};
    // Automaton with three variables ['x', 'y', 'u'] and flows:
    // x' == -x - 2 * y -0.2 * u
    // y' == 4 * x - 3 * y + 2 * u
    // u' == 1
    Configuration c = AutomatonUtil.makeDebugConfiguration(dy);
    BaseComponent ha = ((BaseComponent) c.root);
    AutomatonMode mode = ha.modes.values().iterator().next();

    Classification cls = new Classification();
    Classification.ha = ha;
    cls.setVarID(ha);
    cls.setLinearMatrix(mode);
    double TOL = 1e-9;
    Assert.assertEquals(-1, Classification.linearMatrix[0][0], TOL);
  }
Esempio n. 3
0
  @Test
  public void testConvertLinearDynamicThreeVars() {
    String path = UNIT_BASEDIR + "linear_dynamic/";
    SpaceExDocument test1 =
        SpaceExImporter.importModels(path + "three_var.cfg", path + "three_var.xml");

    Configuration c = flatten(test1);
    BaseComponent ha = (BaseComponent) c.root;

    Classification cls = new Classification();
    Classification.ha = ha;
    cls.setVarID(ha);
    SimulinkStateflowPrinter sp = new SimulinkStateflowPrinter();
    sp.ha = ha;
    // sp.setVarID(ha);
    AutomatonMode mode = ha.modes.get("running");
    cls.setLinearMatrix(mode);
    String s = sp.convertFlowToAMatrix(mode);
    String result = "[-1.0 4.0 2.0 ;2.0 -3.0 3.0 ;0.0 2.0 4.0 ;]";
    Assert.assertEquals(s, result);
  }
Esempio n. 4
0
  @Test
  public void testConvertLinearDynamicTwoVarTwoHavocTwoInput() {
    String path = UNIT_BASEDIR + "linear_dynamic/";
    SpaceExDocument test1 =
        SpaceExImporter.importModels(
            path + "four_var_two_input.cfg", path + "four_var_two_input.xml");
    Map<String, Component> componentTemplates = TemplateImporter.createComponentTemplates(test1);

    Configuration c = ConfigurationMaker.fromSpaceEx(test1, componentTemplates);

    new FlattenAutomatonPass().runVanillaPass(c, null);
    BaseComponent ha = (BaseComponent) c.root;

    // Configuration c = flatten(test1);
    // BaseComponent ha = (BaseComponent)c.root;
    Classification cls = new Classification();
    Classification.ha = ha;
    cls.setVarID(ha);
    SimulinkStateflowPrinter sp = new SimulinkStateflowPrinter();
    sp.ha = ha;
    // sp.setVarID(ha);
    AutomatonMode mode = ha.modes.get("running");
    cls.setLinearMatrix(mode);
    // test A matrix
    String A = sp.convertFlowToAMatrix(mode);
    String resultA = "[1.0 4.0 ;0.5 -3.0 ;]";
    Assert.assertEquals(A, resultA);
    // test B matrix
    String B = sp.convertInputToBMatrix(mode);
    String resultB = "[0.5 -2.0 ;-0.2 3.0 ;]";
    Assert.assertEquals(B, resultB);
    // test A matrix
    String C = sp.convertInvToMatrix(mode);
    String resultC = "[1 2.0 ;0 1 ;]";
    Assert.assertEquals(C, resultC);
  }