예제 #1
0
  /**
   * Loads configuration. It verifies the constraints defined in {@link WireByMethod}.
   *
   * @param prefix the configuration prefix for this class
   */
  public WireByMethod(String prefix) {
    super(prefix);

    // get the method
    try {
      final Class wire =
          Configuration.getClass(
              prefix + "." + PAR_CLASS, Class.forName("peersim.graph.GraphFactory"));
      method =
          WireByMethod.getMethod(wire, Configuration.getString(prefix + "." + PAR_METHOD, "wire"));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // set the constant args (those other than 0th)
    Class[] argt = method.getParameterTypes();
    args = new Object[argt.length];
    for (int i = 1; i < args.length; ++i) {

      if (argt[i] == int.class) args[i] = Configuration.getInt(prefix + "." + PAR_ARG + i);
      else if (argt[i] == long.class) args[i] = Configuration.getLong(prefix + "." + PAR_ARG + i);
      else if (argt[i] == double.class)
        args[i] = Configuration.getDouble(prefix + "." + PAR_ARG + i);
      else if (i == args.length - 1 && argt[i].isInstance(CommonState.r)) args[i] = CommonState.r;
      else {
        // we should neve get here
        throw new RuntimeException(
            "Unexpected error, please " + "report this problem to the peersim team");
      }
    }
  }
예제 #2
0
 /**
  * Used to construct the prototype node. This class currently does not have specific configuration
  * parameters and so the parameter <code>prefix</code> is not used. It reads the protocol
  * components (components that have type {@value peersim.core.Node#PAR_PROT}) from the
  * configuration.
  */
 public GeneralNode(String prefix) {
   System.err.println("Instantiating GenralNode with prefix = " + prefix);
   String[] names = Configuration.getNames(PAR_PROT);
   String[] names_specs = Configuration.getNames(prefix);
   CommonState.setNode(this);
   ID = nextID();
   protocol = new Protocol[names.length + names_specs.length];
   System.err.println(
       "Instantiating GenralNode with prefix = " + prefix + " ==> Loading protocols");
   int i = 0;
   for (i = 0; i < names.length; i++) {
     System.err.println("Loading protocol: " + names[i]);
     CommonState.setPid(i);
     Protocol p = (Protocol) Configuration.getInstance(names[i]);
     if (p == null) System.err.println(" ############## Failed to instantiate: " + names[i]);
     protocol[i] = p;
   }
   System.err.println(
       "Instantiating GenralNode with prefix = " + prefix + " ==> Loading secondary protocols");
   for (int j = 0; j < names_specs.length; j++, i++) {
     CommonState.setPid(i);
     Protocol p = (Protocol) Configuration.getInstance(names_specs[j]);
     if (p == null)
       System.err.println(" ############### Failed to instantiate: " + names_specs[j]);
     protocol[i] = p;
   }
 }
예제 #3
0
 ProtocolData(String prefix) {
   pid = CommonState.getPid();
   lid = Configuration.getPid(prefix + "." + PAR_LINKABLE);
   tid = Configuration.getPid(prefix + "." + PAR_TRANSPORT);
   period = Configuration.getInt(prefix + "." + PAR_PERIOD);
   prob = Configuration.getDouble(prefix + "." + PAR_PROB);
 }
예제 #4
0
  /**
   * Standard constructor that reads the configuration parameters. Invoked by the simulation engine.
   *
   * @param name the configuration prefix for this class
   */
  public GraphPrinter(String name) {

    super(name);
    baseName = Configuration.getString(name + "." + PAR_BASENAME, null);
    format = Configuration.getString(name + "." + PAR_FORMAT, "neighborlist");
    if (baseName != null) fng = new FileNameGenerator(baseName, ".graph");
    else fng = null;
  }
예제 #5
0
 /**
  * Standard constructor that reads the configuration parameters. Invoked by the simulation engine.
  *
  * @param prefix the configuration prefix for this class
  */
 public DynamicNetwork(String prefix) {
   add = Configuration.getDouble(prefix + "." + PAR_ADD);
   substitute = Configuration.contains(prefix + "." + PAR_SUBST);
   Object[] tmp = Configuration.getInstanceArray(prefix + "." + PAR_INIT);
   inits = new NodeInitializer[tmp.length];
   for (int i = 0; i < tmp.length; ++i) {
     // System.out.println("Inits " + tmp[i]);
     inits[i] = (NodeInitializer) tmp[i];
   }
   maxsize = Configuration.getInt(prefix + "." + PAR_MAX, Integer.MAX_VALUE);
   minsize = Configuration.getInt(prefix + "." + PAR_MIN, 0);
 }
예제 #6
0
 public HelloWorld(String prefix) {
   this.prefix = prefix;
   // initialisation des identifiants a partir du fichier de configuration
   this.transportPid = Configuration.getPid(prefix + ".transport");
   this.mypid = Configuration.getPid(prefix + ".myself");
   this.ping_timeout = Configuration.getLong(prefix + ".ping_timeout");
   this.ping_frequency = Configuration.getLong(prefix + ".ping_frequency");
   this.transport = null;
   this.state = 0;
   this.last_pong = new long[Network.size()];
   this.nodes_alive = new boolean[Network.size()];
   for (int i = 0; i < Network.size(); i++) {
     nodes_alive[i] = true;
   }
 }
  @Override
  public void init(String prefix) {
    // initialize global arm model
    GlobalArmModel.initialize(prefix);

    // initialize static fields
    K = (double) GlobalArmModel.numberOfArms();
    d = GlobalArmModel.getDValue();

    // initialize counters
    n = new double[GlobalArmModel.numberOfArms()];
    Arrays.fill(n, 0.0);
    sumN = 0.0;

    // model
    s = Arrays.copyOf(n, n.length);
    w = Arrays.copyOf(n, n.length);
    r = Arrays.copyOf(n, n.length);
    q = Arrays.copyOf(n, n.length);
    f = Arrays.copyOf(n, n.length);
    g = Arrays.copyOf(n, n.length);

    // parameter
    c = Configuration.getDouble(prefix + ".p2greedy.C");
  }
  public JungGraphObserver(String name) {
    this.name = name;
    this.hyphadataPid = Configuration.getPid(PAR_HYPHADATA_PROTO);
    this.hyphalinkPid = Configuration.getPid(PAR_HYPHALINK_PROTO);
    this.mycocastPid = Configuration.getPid(PAR_MYCOCAST_PROTO);
    this.period = Configuration.getInt(name + "." + PAR_PERIOD);

    this.walkDelay = Configuration.getInt(name + "." + PAR_WALK_DELAY);
    mainThread = Thread.currentThread();
    this.changeListeners = new HashSet<ChangeListener>();

    visualizer = null;

    // HyphaData.addHyphaDataListener(this);
    // HyphaLink.addHyphaLinkListener(this);
  }
예제 #9
0
  /** Initialization based on configuration parameters. */
  public OrangeSched(String n) {

    String[] prots = Configuration.getString(n + "." + PAR_PROTOCOL).split("\\s");
    pid = new int[prots.length];
    nce = new NextCycleEvent[prots.length];
    for (int i = 0; i < prots.length; ++i) {
      pid[i] = Configuration.lookupPid(prots[i]);
      if (!(Network.prototype.getProtocol(pid[i]) instanceof CDProtocol)) {
        throw new IllegalParameterException(
            n + "." + PAR_PROTOCOL, "Only CDProtocols are accepted here");
      }

      nce[i] =
          (NextCycleEvent) Configuration.getInstance(n + "." + PAR_NEXTC, new NextCycleEvent(null));
    }

    randstart = Configuration.contains(n + "." + PAR_RNDSTART);
  }
예제 #10
0
 /** Loads protocol schedulers for all protocols. */
 static {
   String[] names = Configuration.getNames(Node.PAR_PROT);
   sch = new Scheduler[names.length];
   for (int i = 0; i < names.length; ++i) {
     if (Network.prototype.getProtocol(i) instanceof CDProtocol)
       // with no default values for step to avoid
       // "overscheduling" due to lack of step option.
       sch[i] = new Scheduler(names[i], false);
   }
 }
  public OrangeNodeInit(String prefix) {
    pid = Configuration.getPid(prefix + "." + PAR_PROT);
    category = Configuration.getInt(prefix + "." + PAR_CATEGORY);
    maxVideoSize = Configuration.getInt(prefix + "." + PAR_MINVIDEOSIZE);
    rangeVideoSize = Configuration.getInt(prefix + "." + PAR_RANGEVIDEOSIZE);

    maxUpSpeed = Configuration.getInt(prefix + "." + PAR_UPSPEED);
    minDlSpeed = Configuration.getInt(prefix + "." + PAR_MINDLSPEED);
    maxDlSpeed = Configuration.getInt(prefix + "." + PAR_MAXDLSPEED);
  }
예제 #12
0
 public TrafficGene(String prefix) {
   pid = Configuration.getPid(prefix + "." + PAR_PROT);
   numReqPerClient = Configuration.getInt(prefix + "." + PAR_NUMREQPERCLIENT);
   startupFilePath = Configuration.getString(prefix + "." + PAR_STARTUPFILEPATH);
   reqArrivalInterval = Configuration.getLong(prefix + "." + PAR_REQARRIVALINTERVAL);
   localTransTime = Configuration.getLong(prefix + "." + PAR_LOCALTRANSTIME);
   Library.policy = Configuration.getString(prefix + "." + PAR_POLICY);
 }
예제 #13
0
  public RenaterInitializer(String prefix) {
    pid = Configuration.getPid(prefix + "." + PAR_PROT);
    phid = FastConfig.getLinkable(pid);
    cpid = Configuration.getPid(prefix + "." + PAR_CHORD_PROT);

    nrDC = Configuration.getInt("NR_DC", 1);
    nrNodePerDC = Configuration.getInt("NR_NODE_PER_DC", 1);

    dc_file = (Configuration.getString(prefix + "." + PAR_DC_FILE, "nofilewiththisname"));
    distance = (Configuration.getDouble(prefix + "." + PAR_DC_DISTANCE, 0.01));
  }
예제 #14
0
  @Override
  public boolean execute() {
    double alpha = Configuration.getDouble("ALPHA", -2.0);
    System.out.println("ALPHA set to " + alpha);

    System.out.println("\nSetting up renater nodes, positioning and gateways ");
    // initialize the gson parser
    List<String> lines = null;

    if (Files.exists(Paths.get(dc_file))) {
      lines = getDcCordsFromFile();
      if (lines != null) nrDC = lines.size();
    }

    KoalaJsonParser.intitialize();
    NodeUtilities.initialize();
    NodeUtilities.setNodePIDs(phid, pid, cpid);
    NodeUtilities.intializeDCCenters(lines);

    //        if(Network.size() < nrDC)
    //        	nrDC = Network.size();

    NodeUtilities.ACTUAL_NR_DC = Network.size();

    //        assigning nodes an id and setting their coordinates according to their data-center
    initializationMode = true;
    for (int i = 0; i < Network.size(); i++) {
      initialize(Network.get(i));
    }
    initializationMode = false;

    //        System.setErr(new PrintStream(new OutputStream() {
    //            public void write(int b) {
    //                //DO NOTHING
    //            }
    //        }));

    return false;
  }
  public PopulateVirtualWorld(String prefix) {
    distribution = Configuration.getInt(prefix + "." + PAR_DISTRIB);
    applicativeLayerId = Configuration.getPid(prefix + "." + APPLICATIVE_LAYER);
    Globals.mapSize = Configuration.getLong(prefix + "." + MAP_SIZE);
    Globals.zoneSize = Configuration.getLong(prefix + "." + ZONE_SIZE);
    Globals.zoneNb = Configuration.getInt(prefix + "." + ZONE_NB);
    Globals.outOfZoneNb = Configuration.getInt(prefix + "." + OUT_OF_ZONE_NB);
    Globals.wSpeed = Configuration.getInt(prefix + "." + WSPEED);
    Globals.tSpeed = Configuration.getInt(prefix + "." + TSPEED);
    Globals.smallZoneSize = Configuration.getInt(prefix + "." + SMALL_ZONE_SIZE);
    Globals.smallZoneNb = Configuration.getInt(prefix + "." + SMALL_ZONE_NB);

    Globals.haltedToHalted = Configuration.getInt(prefix + "." + HTH);
    Globals.haltedToTravelling = Configuration.getInt(prefix + "." + HTT);
    Globals.haltedToWandering = Configuration.getInt(prefix + "." + HTW);

    Globals.travellingToTravelling = Configuration.getInt(prefix + "." + TTT);
    Globals.travellingToHalted = Configuration.getInt(prefix + "." + TTH);
    Globals.travellingToWandering = Configuration.getInt(prefix + "." + TTW);

    Globals.wanderingToWandering = Configuration.getInt(prefix + "." + WTW);
    Globals.wanderingToTravelling = Configuration.getInt(prefix + "." + WTT);
    Globals.wanderingToHalted = Configuration.getInt(prefix + "." + WTH);
    Globals.changeWanderingDirection = Configuration.getInt(prefix + "." + CWD);

    Globals.quiet = Configuration.getBoolean(prefix + "." + QUIET);
  }
예제 #16
0
 public ControlerNw(String prefix) {
   this.prefix = prefix;
   pid = Configuration.getPid(prefix + "." + PAR_PROTOCOL);
 }
예제 #17
0
 public ChordInitializer(String prefix) {
   pid = Configuration.getPid(prefix + "." + PAR_PROT);
 }
예제 #18
0
 public Protocol(String prefix) {
   this.prefix = prefix;
   this.peerClassName = Configuration.getString(prefix + "." + PEER_CLASS_PAR);
   System.err.println("- Running control CanYouHereMeProtocol");
 }
예제 #19
0
 public TrafficGene(String prefix) {
   pid = Configuration.getPid(prefix + "." + PAR_PROT);
   idLength = Configuration.getInt(prefix + "." + PAR_IDLENGTH);
 }
 /**
  * The basic constructor of the class, which reads the parameters from the configuration file.
  *
  * @param prefix the configuration prefix for this class
  */
 public NodeInitializer(String prefix) {
   pid = Configuration.getPid(prefix + "." + PAR_PROT);
   newerDistr = Configuration.getInt(prefix + "." + PAR_NEWER_DISTR);
   seederDistr = Configuration.getInt(prefix + "." + PAR_SEEDER_DISTR);
 }
예제 #21
0
 /** Creates a new observer and initializes the configuration parameter. */
 public DummyObserver(String name) {
   this.name = name;
   pid = Configuration.getPid(name + "." + PAR_PROTID);
 }
  public static void main(String[] args) throws Exception {
    String configName = args[0];
    Configuration.setConfig(new ParsedProperties(configName));
    // System.err.println("#Reading datasets from files");
    File tFile = new File(Configuration.getString("trainingFile"));
    File eFile = new File(Configuration.getString("evaluationFile"));
    String dbReaderName = "gossipLearning.RecSysDataBaseReader";

    seed = Configuration.getInt("SEED");
    numOfClusters = Configuration.getInt("numOfClusters");
    divErr = Configuration.getDouble("divErr");
    numberOfRatings = Configuration.getDouble("numOfRatings");
    numberOfAllUsers = Configuration.getDouble("numOfAllUsers");

    classifierName = Configuration.getString("classifier", null);

    prefix = "model";
    modelName = Configuration.getString(prefix, null);

    boolean isNormalize = Configuration.getBoolean("normalize");
    int polyDegree = Configuration.getInt("polyDegree");

    DataBaseReader dbReader = DataBaseReader.createDataBaseReader(dbReaderName, tFile, eFile);

    // System.err.println("#Preprocessing datasets");
    // pre-processing database
    getNumberOfUsers = new double[dbReader.getTrainingSet().getNumberOfFeatures()];
    getAverageRating = new double[dbReader.getTrainingSet().getNumberOfFeatures()];
    getNumberOfLikeableUsers = new double[dbReader.getTrainingSet().getNumberOfFeatures()];
    for (int i = 0; i < dbReader.getTrainingSet().size(); i++) {
      for (VectorEntry e : dbReader.getTrainingSet().getInstance(i)) {
        getNumberOfUsers[e.index]++;
        getAverageRating[e.index] += e.value;
      }
    }
    for (int i = 0; i < dbReader.getTrainingSet().getNumberOfFeatures(); i++) {
      getAverageRating[i] =
          getNumberOfUsers[i] == 0.0 ? 0.0 : getAverageRating[i] / getNumberOfUsers[i];
    }

    for (int i = 0; i < dbReader.getTrainingSet().size(); i++) {
      for (VectorEntry e : dbReader.getTrainingSet().getInstance(i)) {
        if (e.value > getAverageRating[e.index]) {
          getNumberOfLikeableUsers[e.index]++;
        }
      }
    }

    // System.err.println("#Extracting features");
    // feature extraction
    InstanceHolder trainingSet = new InstanceHolder((int) numberOfRatings, 11);
    for (int userID = 0; userID < dbReader.getTrainingSet().size(); userID++) {
      for (VectorEntry e : dbReader.getTrainingSet().getInstance(userID)) {
        int itemID = e.index;
        double label = e.value;
        double[] features = new double[11];
        computeUserSpecificFeatureVectorPart(
            dbReader.getTrainingSet().getInstance(userID), features);
        computeItemSpecificFinalFeatureVector(itemID, features);
        SparseVector instance = new SparseVector(features);
        trainingSet.add(instance, label);
      }
    }
    InstanceHolder testSet = new InstanceHolder((int) numberOfRatings, 11);
    for (int userID = 0; userID < dbReader.getEvalSet().size(); userID++) {
      for (VectorEntry e : dbReader.getEvalSet().getInstance(userID)) {
        int itemID = e.index;
        double label = e.value;
        double[] features = new double[11];
        computeUserSpecificFeatureVectorPart(
            dbReader.getTrainingSet().getInstance(userID), features);
        computeItemSpecificFinalFeatureVector(itemID, features);
        SparseVector instance = new SparseVector(features);
        testSet.add(instance, label);
      }
    }

    File tout = new File("tr.dat");
    File eout = new File("ev.dat");

    trainingSet.writeToFile(tout);
    testSet.writeToFile(eout);

    DataBaseReader dbr =
        DataBaseReader.createDataBaseReader("gossipLearning.DataBaseReader", tout, eout);

    if (polyDegree > 1) {
      // dbr.polynomize(polyDegree);
      // dbr.writeToFile(new File("bookcrossing_fn_" + polyDegree + ".train"), new
      // File("bookcrossing_fn_" + polyDegree + ".test"));
      // System.exit(0);
    }

    if (isNormalize) {
      dbr.standardize();
    }

    if (classifierName != null) {
      weka(dbr.getTrainingSet(), dbr.getEvalSet());
      // weka(trainingSet, testSet);
    }

    if (modelName != null) {
      golf(dbr.getTrainingSet(), dbr.getEvalSet());
      // golf(trainingSet, testSet);
    }

    tout.deleteOnExit();
    eout.deleteOnExit();
  }
예제 #23
0
 /**
  * Standard constructor that reads the configuration parameters. Invoked by the simulation engine.
  *
  * @param prefix the configuration prefix for this class.
  */
 public InetObserver(String prefix) {
   super(prefix);
   coordPid = Configuration.getPid(prefix + "." + PAR_COORDINATES_PROT);
   graph_filename = Configuration.getString(prefix + "." + PAR_FILENAME_BASE, "graph_dump");
   fng = new FileNameGenerator(graph_filename, ".dat");
 }
예제 #24
0
 /** Reads configuration parameters, using the specified prefix. */
 public FingerObserver(String prefix) {
   pid = Configuration.getPid(prefix + "." + PAR_PROT);
   hid = Configuration.getPid(prefix + "." + PAR_HOLDER, pid);
   this.prefix = prefix;
 }