Example #1
0
 public double getLossRate(int senderID, int receiverID) {
   Double d = (Double) connectivityGraph.get(graphKey(senderID, receiverID));
   if (d == null) {
     throw new ArrayIndexOutOfBoundsException(
         "no connectivity entry for " + senderID + " -> " + receiverID);
   }
   return d.doubleValue();
 }
Example #2
0
  public void handleEvent(SimEvent event) {
    if (event instanceof SimObjectEvent) {
      SimObjectEvent simObjectEvent = (SimObjectEvent) event;
      SimObject simObject = simObjectEvent.getSimObject();
      switch (simObjectEvent.getType()) {
        case SimObjectEvent.OBJECT_ADDED:
        case SimObjectEvent.OBJECT_REMOVED:
          // always fully update the model
          debug.err.println("RADIOMODEL: sim object add/remove, updating model");
          updateModel();
          break;
      }
    } else if (event instanceof AttributeEvent) {
      AttributeEvent attributeEvent = (AttributeEvent) event;
      switch (attributeEvent.getType()) {
        case ATTRIBUTE_CHANGED:
          if (attributeEvent.getAttribute() instanceof MoteCoordinateAttribute) {
            MoteSimObject mote = (MoteSimObject) attributeEvent.getOwner();
            debug.err.println("RADIOMODEL: " + mote + " moved, updating links");
            updateLossRates(mote);
          }
          break;
      }
    }

    // XXX/demmer this isn't necessary since we already respond to the
    // updated location attributes
    //     else if (event instanceof SimObjectDraggedEvent) {
    //       updateModel(true);
    //     }

    else if (event instanceof OptionSetEvent) {
      OptionSetEvent ose = (OptionSetEvent) event;

      if (ose.name.equals("radiomodel")) {
        PropagationModel pm = (PropagationModel) models.get(ose.value);
        if (pm != null) {
          debug.err.println("RADIOMODEL: Setting model to " + pm);
          curModel = pm;
          updateModel();
        }
      }

      // also not necessary since it generates new simobjectevents
      //     } else if (event instanceof TossimInitEvent) {
      //       driver.pause();
      //       updateModel();
      //       publishModel();
      //       driver.resume();
    }
  }
Example #3
0
  // Send the loss rate for all pairs of motes to the simulator
  public void publishModel() {
    debug.err.println("RADIOMODEL: Publishing model, current is " + curModel);
    Iterator it1 = state.getMoteSimObjects().iterator();
    while (it1.hasNext()) {
      MoteSimObject moteSender = (MoteSimObject) it1.next();
      MoteCoordinateAttribute moteSenderCoord = moteSender.getCoordinate();
      Iterator it2 = state.getMoteSimObjects().iterator();
      while (it2.hasNext()) {
        MoteSimObject moteReceiver = (MoteSimObject) it2.next();
        if (moteReceiver.getID() == moteSender.getID()) continue;

        String key = graphKey(moteSender, moteReceiver);
        double prob = ((Double) connectivityGraph.get(key)).doubleValue();
        publishLossRate(moteSender, moteReceiver, prob);
      }
    }
  }
Example #4
0
 public PropagationModel getModel(String name) {
   return (PropagationModel) models.get(name);
 }
Example #5
0
 public void setCurModel(String modelname) {
   PropagationModel m = (PropagationModel) models.get(modelname);
   if (m != null) {
     this.curModel = m;
   }
 }