Examples of Simulation


Examples of org.contikios.cooja.Simulation

    if (!executeDir.endsWith(".jar")) {
      throw new RuntimeException("Not a proper JAR archive: " + executeDir);
    }
    executeDir = executeDir.substring(0, executeDir.length()-".jar".length());

    Simulation simulation = gui.getSimulation();
    if (simulation == null) {
      throw new RuntimeException(
          "No simulation active"
      );
    }

    /* Check dependencies: mote type */
    for (MoteType t: simulation.getMoteTypes()) {
      if (!t.getClass().getName().contains("SkyMoteType")) {
        throw new RuntimeException(
            "You simulation contains the mote type: " + Cooja.getDescriptionOf(t.getClass()) + "\n" +
            "Only the Sky Mote Type is currently supported.\n"
        );
View Full Code Here

Examples of org.contikios.cooja.Simulation

      return "Show LEDs on " + mote;
    }

    @Override
    public void doAction(Visualizer visualizer, Mote mote) {
      Simulation simulation = mote.getSimulation();
      LED led = mote.getInterfaces().getLED();
      if (led == null) {
        return;
      }

      /* Extract description (input to plugin) */
      String desc = Cooja.getDescriptionOf(mote.getInterfaces().getLED());

      MoteInterfaceViewer viewer
              = (MoteInterfaceViewer) simulation.getCooja().tryStartPlugin(
                      MoteInterfaceViewer.class,
                      simulation.getCooja(),
                      simulation,
                      mote);
      if (viewer == null) {
        return;
      }
View Full Code Here

Examples of org.contikios.cooja.Simulation

      return "Show serial port on " + mote;
    }

    @Override
    public void doAction(Visualizer visualizer, Mote mote) {
      Simulation simulation = mote.getSimulation();
      SerialPort serialPort = null;
      for (MoteInterface intf : mote.getInterfaces().getInterfaces()) {
        if (intf instanceof SerialPort) {
          serialPort = (SerialPort) intf;
          break;
        }
      }

      if (serialPort == null) {
        return;
      }

      /* Extract description (input to plugin) */
      String desc = Cooja.getDescriptionOf(serialPort);

      MoteInterfaceViewer viewer
              = (MoteInterfaceViewer) simulation.getCooja().tryStartPlugin(
                      MoteInterfaceViewer.class,
                      simulation.getCooja(),
                      simulation,
                      mote);
      if (viewer == null) {
        return;
      }
View Full Code Here

Examples of org.contikios.cooja.Simulation

    }

    public void doAction(Visualizer visualizer, Mote mote) {
      /* Remove all motes of this type */
      /* TODO Confirm? */
      Simulation simulation = mote.getSimulation();
      Mote[] motes = simulation.getMotes();
      for (Mote m: motes) {
        if (m.getType() == mote.getType()) {
          simulation.removeMote(m);
        }
      }
    }
View Full Code Here

Examples of org.drools.simulation.Simulation

public class SimulationTest {

    @Test
    public Simulation testOnePathNoDSL() {

        Simulation simulation = new SimulationImpl();

        String str = "";
        str += "package org.drools \n";
        str += "global java.util.List list \n";
        str += "rule rule1 \n";
        str += "    dialect \"java\" \n";
        str += "when \n";
        str += "    $p : Person() \n";
        str += "then \n";
        str += "    list.add( $p ); \n";
        str += "end \n";

        PathImpl path = new PathImpl( simulation,
                                      "path1" );

        List<Step> steps = new ArrayList<Step>();

        List<Command> cmds = new ArrayList<Command>();

        cmds.add( new SetVariableCommand( "path1",
                                          "kbuilder",
                                          new NewKnowledgeBuilderCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                                                                                 ResourceType.DRL,
                                                                                                 null ),
                                                                 "kbuilder",
                                                                 null,
                                                                 null, null ) );

        cmds.add( new SetVariableCommand( "path1",
                                          "kbase",
                                          new NewKnowledgeBaseCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 null, null ) );

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );

        cmds.add( new SetVariableCommand( "path1",
                                          "ksession",
                                          new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
                                                                                         "kbuilder",
                                                                                         "kbase",
                                                                                         null, null ) ) );

        List list = new ArrayList();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
                                                                                       list ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        steps.add( new StepImpl( path,
                                 cmds,
                                 0 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
                                                                                                      97 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 2000 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
                                                                                                      98 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 4000 ) );

        cmds = new ArrayList<Command>();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
                                                                                   2,
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "size()" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "darth",
                                                                                               97 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 0 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "yoda",
                                                                                               98 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 1 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        steps.add( new StepImpl( path,
                                 new TestGroupCommand( "test1",
                                                       cmds ),
                                 5000 ) );

        path.setSteps( steps );

        simulation.getPaths().put( "path1",
                                   path );

        return simulation;

        //        Simulator simulator = new Simulator( simulation,
View Full Code Here

Examples of org.drools.simulation.Simulation

    }

    @Test
    public Simulation testTwoPathsNoDSL() {

        Simulation simulation = new SimulationImpl();

        String str = "";
        str += "package org.drools \n";
        str += "global java.util.List list \n";
        str += "rule rule1 \n";
        str += "    dialect \"java\" \n";
        str += "when \n";
        str += "    $p : Person() \n";
        str += "then \n";
        str += "    list.add( $p ); \n";
        str += "end \n";

        PathImpl path = new PathImpl( simulation,
                                      "path1" );

        List<Step> steps = new ArrayList<Step>();

        List<Command> cmds = new ArrayList<Command>();

        cmds.add( new SetVariableCommand( "ROOT",
                                          "kbuilder",
                                          new NewKnowledgeBuilderCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                                                                                 ResourceType.DRL,
                                                                                                 null ),
                                                                 "kbuilder",
                                                                 null,
                                                                 null, null ) );

        cmds.add( new SetVariableCommand( "ROOT",
                                          "kbase",
                                          new NewKnowledgeBaseCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 null, null ) );

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );

        cmds.add( new SetVariableCommand( "ROOT",
                                          "ksession",
                                          new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
                                                                                         "kbuilder",
                                                                                         "kbase",
                                                                                         null, null ) ) );

        List list = new ArrayList();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
                                                                                       list ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        steps.add( new StepImpl( path,
                                 cmds,
                                 0 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
                                                                                                      97 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 2000 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
                                                                                                      98 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 4000 ) );

        path.setSteps( steps );

        simulation.getPaths().put( "path1",
                                   path );

        path = new PathImpl( simulation,
                             "path2" );

        steps = new ArrayList<Step>();

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "bobba",
                                                                                                      77 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 1500 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "luke",
                                                                                                      30 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 2200 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "ben",
                                                                                                      150 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 4500 ) );

        cmds = new ArrayList<Command>();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
                                                                                   5,
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "size()" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "bobba",
                                                                                               77 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 0 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "darth",
                                                                                               97 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 1 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "luke",
                                                                                               30 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 2 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "yoda",
                                                                                               98 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 3 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "ben",
                                                                                               150 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 4 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        steps.add( new StepImpl( path,
                                 new TestGroupCommand( "test2",
                                                       cmds ),
                                 5000 ) );

        path.setSteps( steps );

        simulation.getPaths().put( "path2",
                                   path );

        return simulation;

    }
View Full Code Here

Examples of org.drools.simulation.Simulation

        }

        try {
            for ( Method method : methods ) {

                Simulation simulation = (Simulation) method.invoke( object,
                                                                    null );

                for ( SimulationPath path : simulation.getPaths().values() ) {
                    for ( SimulationStep step : path.getSteps() ) {
                        for ( Command command : step.getCommands() ) {
                            if ( command instanceof TestGroupCommand ) {
                                String testName = ((TestGroupCommand) command).getName();
                                Description testGroupDescr = Description.createTestDescription( cls,
View Full Code Here

Examples of org.drools.simulation.Simulation

        }

        try {
            for ( Method method : methods ) {

                Simulation simulation = (Simulation) method.invoke( object,
                                                                    null );

                for ( Path path : simulation.getPaths().values() ) {
                    for ( Step step : path.getSteps() ) {
                        for ( Command command : step.getCommands() ) {
                            if ( command instanceof TestGroupCommand ) {
                                String testName = ((TestGroupCommand) command).getName();
                                Description testGroupDescr = Description.createTestDescription( cls,
View Full Code Here

Examples of org.drools.simulation.Simulation

        }

        try {
            for ( Method method : methods ) {

                Simulation simulation = (Simulation) method.invoke( object,
                                                                    null );

                for ( Path path : simulation.getPaths().values() ) {
                    for ( Step step : path.getSteps() ) {
                        for ( Command command : step.getCommands() ) {
                            if ( command instanceof TestGroupCommand ) {
                                String testName = ((TestGroupCommand) command).getName();
                                Description testGroupDescr = Description.createTestDescription( cls,
View Full Code Here

Examples of org.drools.simulation.Simulation

        }

        try {
            for ( Method method : methods ) {

                Simulation simulation = (Simulation) method.invoke( object,
                                                                    null );

                for ( Path path : simulation.getPaths().values() ) {
                    for ( Step step : path.getSteps() ) {
                        for ( Command command : step.getCommands() ) {
                            if ( command instanceof TestGroupCommand ) {
                                String testName = ((TestGroupCommand) command).getName();
                                Description testGroupDescr = Description.createTestDescription( cls,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.