Package srsim.domain

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


  @Test
  public void testLightingChangeThroughActuator()
      throws SimulationContextException,
      SimulationConfigurationException, InterruptedException {
    double targetBrightness = 6000.0D;
    Simulation simulation = new Simulation(new SystemTimeTimeSource());
    simulation.setResolution(0);
    Room room = new Room();
    AbstractController controller = new LightingController();
    ISensor sensor = new LightSensor();
    IActuator[] lights = new IActuator[10];
    simulation.addRoom(room);
    simulation.getContext().setBrightness(5999.0D);
    room.getLocalContext().setPreference("targetBrightness",
        String.valueOf(targetBrightness));
    controller.attachSensor(sensor);
    for (int i = 0; i < 10; i++) {
      lights[i] = new LightingActuator();
      controller.attachActuator(lights[i]);
      room.addActuator(lights[i]);
    }
    room.addController(controller);
    room.addSensor(sensor);
    double brightness = room.getLocalContext().getBrightness();
    double previousBrightness = brightness;
    while (brightness < targetBrightness) {
      simulation.step();
      previousBrightness = brightness;
      brightness = room.getLocalContext().getBrightness();
      Assert.assertTrue(brightness > previousBrightness);
    }
  }
View Full Code Here

    controller.attachActuator(actuator);
  }
 
  @Test
  public void testInitiatingActuatorChangeFromSensorUpdate() throws SimulationContextException {
    Simulation simulation = new Simulation(new SystemTimeTimeSource());
    Room room = new Room();
    HeatingController controller = new HeatingController();
    ISensor sensor = new TemperatureSensor();
    IActuator actuator = new HeatingActuator();
    room.setContext(simulation.getContext());
    simulation.getContext().setTemperature(0.0D);
    simulation.getContext().setPreference("targetTemperature","21.5D");
    controller.attachSensor(sensor);
    controller.attachActuator(actuator);
    Assert.assertTrue(actuator.getState() == IActuator.IDLE);
    room.addSensor(sensor);
    room.addController(controller);
View Full Code Here

  private PreferencesServer preferencesServer;

  private void init(final IDataStore dataStore) {
    setName("SmartRoomSimulator");
    running = false;
    simulation = new Simulation(new SystemTimeTimeSource());
    if (dataStore != null) {
      tracker = new SimulationTracker(this, dataStore);
    }
  }
View Full Code Here

      timeSource = (ITimeSource) Class.forName(timeSourceClass)
          .newInstance();
    } else {
      timeSource = new SystemTimeTimeSource();
    }
    Simulation simulation = new Simulation(timeSource);

    JsonNumber resolution = simulationObject.getJsonNumber("resolution");
    simulation.setResolution(resolution != null ? resolution.longValue()
        : 1000L);

    JsonNumber temperature = simulationObject.getJsonNumber("temperature");
    if (temperature != null) {
      simulation.getContext().setTemperature(temperature.doubleValue());
    }
    JsonNumber brightness = simulationObject.getJsonNumber("brightness");
    if (brightness != null) {
      simulation.getContext().setBrightness(brightness.doubleValue());
    }

    JsonArray colorArray = simulationObject.getJsonArray("lightColor");
    if (colorArray != null && colorArray.size() == 3) {
      simulation.getContext().setLightColor(
          new int[] { colorArray.getInt(0), colorArray.getInt(1),
              colorArray.getInt(2) });
    }

    JsonArray rooms = simulationObject.getJsonArray("rooms");
    if (rooms != null) {
      for (JsonObject roomDescription : rooms
          .getValuesAs(JsonObject.class)) {
        Room room = readRoom(roomDescription);
        simulation.addRoom(room);
      }
    }

    JsonObject preferencesObject = simulationObject
        .getJsonObject("preferences");
    if (preferencesObject != null) {
      for (String key : preferencesObject.keySet()) {
        simulation.getContext().setPreference(key,
            preferencesObject.getString(key));
      }
    }
    return simulation;
  }
View Full Code Here

TOP

Related Classes of srsim.domain.Simulation

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.