Examples of Simulation


Examples of se.sics.cooja.Simulation

   *
   * @param arguments Command arguments
   * @return Reply to client (XML format)
   */
  private String writeMemory(Collection<Element> arguments) {
    Simulation simulation = myGUI.getSimulation();

    String type = null;
    String mote = null;
    String variable = null;
    String size = null;
    String address = null;
    String value = null;

    for (Element element : arguments) {
      if (element.getName().equals(XML_TYPE_NAME)) {
        type = element.getText();
      } else if (element.getName().equals(XML_MOTE_NAME)) {
        mote = element.getText();
      } else if (element.getName().equals(XML_VARIABLE_NAME)) {
        variable = element.getText();
      } else if (element.getName().equals(XML_SIZE_NAME)) {
        size = element.getText();
      } else if (element.getName().equals(XML_ADDRESS_NAME)) {
        address = element.getText();
      } else if (element.getName().equals(XML_VALUE_NAME)) {
        value = element.getText();
      } else {
        return createErrorMessage("Unknown write memory parameter: " + element.getName());
      }
    }

    if (type == null)
      return createErrorMessage("No write memory type specified");
    if (mote == null)
      return createErrorMessage("No mote specified");
    if (mote == null)
      return createErrorMessage("No mote ID specified");
    int moteNr = Integer.parseInt(mote);
    if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
      return createErrorMessage("Bad mote ID specified: " + moteNr);
    }
    MoteMemory memory = simulation.getMote(moteNr).getMemory();
   
    // Write integer variable
    if (type.equals("int")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
View Full Code Here

Examples of se.sics.cooja.Simulation

   *
   * @param arguments Command arguments
   * @return Reply to client (XML format)
   */
  private String addEventpoint(Collection<Element> arguments) {
    Simulation simulation = myGUI.getSimulation();

    String type = null;
    String mote = null;
    String variable = null;
    String time = null;
    String size = null;
    String triggeron = null;
    String address = null;
    String count = null;

    for (Element element : arguments) {
      if (element.getName().equals(XML_TYPE_NAME)) {
        type = element.getText();
      } else if (element.getName().equals(XML_MOTE_NAME)) {
        mote = element.getText();
      } else if (element.getName().equals(XML_VARIABLE_NAME)) {
        variable = element.getText();
      } else if (element.getName().equals(XML_TIME_NAME)) {
        time = element.getText();
      } else if (element.getName().equals(XML_SIZE_NAME)) {
        size = element.getText();
      } else if (element.getName().equals(XML_ADDRESS_NAME)) {
        address = element.getText();
      } else if (element.getName().equals(XML_TRIGGERON_NAME)) {
        triggeron = element.getText();
      } else if (element.getName().equals("count")) {
        count = element.getText();
      } else {
        return createErrorMessage("Unknown eventpoint parameter: " + element.getName());
      }
    }

    logger.debug("Eventpoint type: " + type);
    if (type == null)
      return createErrorMessage("No eventpoint type specified");

    // Integer variable watchpoint
    if (type.equals(XML_WATCHPOINT_INT)) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);

      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't write mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      Eventpoint newEventpoint = new IntegerWatchpoint(moteObject, variable);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }

    // Variable watchpoint
    if (type.equals(XML_WATCHPOINT_VARIABLE)) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);

      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't write mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      Eventpoint newEventpoint = new VariableWatchpoint(moteObject, variable, sizeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }


    // Memory area watchpoint
    if (type.equals(XML_WATCHPOINT_ADDRESS)) {
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }
      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);
      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      Eventpoint newEventpoint = new Watchpoint(moteObject, addressParsed, sizeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }

    // Simulation timepoint
    if (type.equals(XML_TIMEPOINT_SIMULATION)) {
      if (time == null)
        return createErrorMessage("No time specified");
      int timeParsed = Integer.parseInt(time);
      if (timeParsed < 0) {
        return createErrorMessage("Bad time specified: " + timeParsed);
      }

      Eventpoint newEventpoint = new SimulationTimepoint(simulation, timeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }

    // Real timepoint
    if (type.equals(XML_TIMEPOINT_REAL)) {
      if (time == null)
        return createErrorMessage("No time specified");
      long timeParsed = Long.parseLong(time);
      if (timeParsed < 0) {
        return createErrorMessage("Bad time specified: " + timeParsed);
      }

      Eventpoint newEventpoint = new RealTimepoint(timeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }

    // Radio medium event point
    if (type.equals(XML_EVENTPOINT_RADIOMEDIUM)) {
      int countInt;
      try {
        countInt = Integer.parseInt(count);
      } catch (NumberFormatException e) {
        return createErrorMessage("Bad count specified: " + e);
      }

      if (triggeron == null || triggeron.equals("all")) {
        Eventpoint newEventpoint = new RadioMediumEventpoint(simulation.getRadioMedium(), countInt);
        myEvaluator.addEventpoint(newEventpoint);
        return createOkMessage(newEventpoint, simulation.getSimulationTime());
      } else if (triggeron.equals("completed")) {
        Eventpoint newEventpoint = new TransmissionRadioMediumEventpoint(simulation.getRadioMedium(), countInt);
        myEvaluator.addEventpoint(newEventpoint);
        return createOkMessage(newEventpoint, simulation.getSimulationTime());
      } else {
        return createErrorMessage("Bad trigger on parameter: " + triggeron);
      }
    }

View Full Code Here

Examples of se.sics.cooja.Simulation

   *
   * @param arguments Command arguments
   * @return Reply to client (XML format)
   */
  private String getInfo(Collection<Element> arguments) {
    Simulation simulation = myGUI.getSimulation();
    String type = null;
    String mote = null;
    String variable = null;

    for (Element element : arguments) {
      if (element.getName().equals(XML_TYPE_NAME)) {
        type = element.getText();
      } else if (element.getName().equals(XML_MOTE_NAME)) {
        mote = element.getText();
      } else if (element.getName().equals(XML_VARIABLE_NAME)) {
        variable = element.getText();
      } else {
        return createErrorMessage("Unknown info parameter: " + element.getName());
      }
    }

    if (type.equals("motestate")) {
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }

      State state = simulation.getMote(moteNr).getState();
      if (state == State.DEAD)
        return XML_OK_START + 0 + XML_OK_END;
      return XML_OK_START + 1 + XML_OK_END;

    } else if (type.equals("time")) {
      return XML_OK_START + myGUI.getSimulation().getSimulationTime() + XML_OK_END;
    } else if (type.equals(XML_MOTECOUNT_NAME)) {
      return XML_OK_START + myGUI.getSimulation().getMotesCount() + XML_OK_END;
    } else if (type.equals("var_address")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);
      MoteMemory memory = simulation.getMote(moteNr).getMemory();
       
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variable address (not address memory)");

      if (!((AddressMemory) memory).variableExists(variable)) {
View Full Code Here

Examples of se.sics.cooja.Simulation

   *
   * @param arguments Command arguments
   * @return Reply to client (XML format)
   */
  private String handleCustomCommand(Collection<Element> arguments) {
    Simulation simulation = myGUI.getSimulation();
    String action = null;
    int id = -1;
    int visible = -1;
    int hide = -1;

    for (Element element : arguments) {
      if (element.getName().equals("action")) {
        action = element.getText();
      } else if (element.getName().equals("id")) {
        String idString = element.getText();
        id = Integer.parseInt(idString);
      } else if (element.getName().equals("hide")) {
        String hideString = element.getText();
        hide = Integer.parseInt(hideString);
      } else if (element.getName().equals("visible")) {
        String visibleString = element.getText();
        visible = Integer.parseInt(visibleString);
      } else {
        return createErrorMessage("Unknown info parameter: " + element.getName());
      }
    }
   
    if (action.equals("CLICK_SINK")) {
      simulation.getMote(0).getInterfaces().getButton().clickButton();
      return XML_OK;
    }

    if (action.equals("SHOW_FIRE")) {
      if (!simulation.getGUI().isVisualized())
        return XML_OK;

      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();

      try {
        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");
        Class[] parameterTypes = new Class[1];
        parameterTypes[0] = Boolean.TYPE;
        Method method = pluginClass.getMethod("showFire", parameterTypes);
        Object[] parameterArguments = new Object[1];
        parameterArguments[0] = new Boolean(visible==1?true:false);

        for (JInternalFrame plugin: allPlugins) {
          if (plugin.getClass() == pluginClass) {
            method.invoke(plugin, parameterArguments);
          }
        }

      } catch (Exception e) {
        return createErrorMessage("Exception: " + e.getMessage());
      }
      return XML_OK;
    }

    if (action.equals("RESET_COLORS")) {
      if (!simulation.getGUI().isVisualized())
        return XML_OK;

      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();

      try {
        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");
        Class[] parameterTypes = new Class[0];
        Method method = pluginClass.getMethod("resetColors", parameterTypes);
        Object[] parameterArguments = new Object[0];

        for (JInternalFrame plugin: allPlugins) {
          if (plugin.getClass() == pluginClass) {
            method.invoke(plugin, parameterArguments);
          }
        }

      } catch (Exception e) {
        return createErrorMessage("Exception: " + e.getMessage());
      }
      return XML_OK;
    }

    if (action.equals("SHOW_TRUCK")) {
      if (!simulation.getGUI().isVisualized())
        return XML_OK;

      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();

      try {
        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");

        if (hide == 0) {
          Class[] parameterTypes = new Class[0];
          Method method = pluginClass.getMethod("showTruck", parameterTypes);
          Object[] parameterArguments = new Object[0];

          for (JInternalFrame plugin: allPlugins) {
            if (plugin.getClass() == pluginClass) {
              method.invoke(plugin, parameterArguments);
            }
          }
        } else {
          Class[] parameterTypes = new Class[0];
          Method method = pluginClass.getMethod("hideTruck", parameterTypes);
          Object[] parameterArguments = new Object[0];

          for (JInternalFrame plugin: allPlugins) {
            if (plugin.getClass() == pluginClass) {
              method.invoke(plugin, parameterArguments);
            }
          }
        }

      } catch (Exception e) {
        return createErrorMessage("Exception: " + e.getMessage());
      }
      return XML_OK;
    }

    if (action.equals("INDICATE_MOTE")) {
      if (!simulation.getGUI().isVisualized())
        return XML_OK;

      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();

      try {
        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");
        Class[] parameterTypes = new Class[1];
        parameterTypes[0] = Integer.TYPE;
        Method method = pluginClass.getMethod("indicateMote", parameterTypes);
        Object[] parameterArguments = new Object[1];
        parameterArguments[0] = new Integer(id);
View Full Code Here

Examples of simulation.Simulation

   *         complete route
   * @throws Exception
   *             if anything goes wrong
   */
  public static String ExpandTrips(List<Edge> tripEdges) throws Exception {
    Simulation sim = Project.getCurrentlyLoadedProject().getSimulation();

    String simulationPath = sim.getExportPath();
    String roadNetworkFile = sim.getName() + ".net.xml";

    File tripsToExpand = new File(simulationPath + File.separator + "tripstoexpand.tmp");
    File expandedTrips = new File(simulationPath + File.separator + "expandedtrips.tmp");
    File expandedTripsAlt = new File(simulationPath + File.separator + "expandedtrips.tmp.alt");

View Full Code Here

Examples of srsim.domain.Simulation

  @Test
  public void testTemperatureChangeThroughActuator()
      throws SimulationContextException, InterruptedException {
    double targetTemperature = 21.5D;
    Simulation simulation = new Simulation(new SystemTimeTimeSource());
    simulation.setResolution(0);
    Room room = new Room();
    HeatingController controller = new HeatingController();
    ISensor sensor = new TemperatureSensor();
    IActuator actuator = new HeatingActuator();
    simulation.addRoom(room);
    room.getLocalContext().setTemperature(20.0D);
    room.getLocalContext().setPreference("targetTemperature", "21.5D");
    controller.attachSensor(sensor);
    controller.attachActuator(actuator);
    room.addActuator(actuator);
    room.addController(controller);
    room.addSensor(sensor);
    double temperature = room.getLocalContext().getTemperature();
    double previousTemperature = temperature;
    while (temperature < targetTemperature) {
      simulation.step();
      previousTemperature = temperature;
      temperature = room.getLocalContext().getTemperature();
      Assert.assertTrue(temperature >= previousTemperature);
    }
  }
View Full Code Here

Examples of zdenekdrahos.AI.Training.Simulation.Simulation

    private void loadDefaultSettings() {
        settings = new TrainingSettings();
        settings.separator = new DataSeparator();
        settings.feedForward = new FeedForward();
        settings.backPropagation = new BackPropagation();
        settings.simulation = new Simulation();
        settings.errorCalculator = new LeastSquares();
        settings.meanCalculator = new Mean();
    }
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.