示例#1
0
  public boolean arrival() {
    List<Fleet> fleets = new ArrayList<>();
    boolean arrival = false;

    if (Fleets().size() == 0) {
      return true;
    }

    for (Fleet fleet : Fleets()) {
      if (fleet.TurnsRemaining() == 0) {
        arrival = true;
        fleets.add(fleet);
      }
    }
    fleets.forEach(
        fleet -> {
          Planet dest = GetPlanet(fleet.DestinationPlanet());
          if (fleet.Owner() != dest.Owner()) {
            dest.NumShips(dest.NumShips() - fleet.NumShips());
            if (dest.NumShips() < 0) {
              dest.Owner(fleet.Owner());
              dest.NumShips(Math.abs(dest.NumShips()));
            }

          } else {
            dest.NumShips(dest.NumShips() + fleet.NumShips());
          }
        });
    return arrival;
  }
 /**
  * The basic method for splitting off a clause of a tree. This modifies the tree in place.
  *
  * @param tree The tree to split a clause from.
  * @param toKeep The edge representing the clause to keep.
  */
 static void splitToChildOfEdge(SemanticGraph tree, SemanticGraphEdge toKeep) {
   Queue<IndexedWord> fringe = new LinkedList<>();
   List<IndexedWord> nodesToRemove = new ArrayList<>();
   // Find nodes to remove
   // (from the root)
   for (IndexedWord root : tree.getRoots()) {
     nodesToRemove.add(root);
     for (SemanticGraphEdge out : tree.outgoingEdgeIterable(root)) {
       if (!out.equals(toKeep)) {
         fringe.add(out.getDependent());
       }
     }
   }
   // (recursively)
   while (!fringe.isEmpty()) {
     IndexedWord node = fringe.poll();
     nodesToRemove.add(node);
     for (SemanticGraphEdge out : tree.outgoingEdgeIterable(node)) {
       if (!out.equals(toKeep)) {
         fringe.add(out.getDependent());
       }
     }
   }
   // Remove nodes
   nodesToRemove.forEach(tree::removeVertex);
   // Set new root
   tree.setRoot(toKeep.getDependent());
 }
示例#3
0
  @Override
  public List<Classifier> buildClassifiers(User user, List<Sample> validSamples) {

    Instances trainingSet =
        new TrainingSetBuilder()
            .setAttributes(user.getBssids())
            .setClassAttribute(
                "Location",
                user.getLocations().stream().map(Location::getName).collect(Collectors.toList()))
            .build("TrainingSet", validSamples.size());

    // Create instances
    validSamples.forEach(
        sample -> {
          Map<String, Integer> BSSIDLevelMap = getBSSIDLevelMap(sample);

          Instance instance = new Instance(trainingSet.numAttributes());

          for (Enumeration e = trainingSet.enumerateAttributes(); e.hasMoreElements(); ) {
            Attribute attribute = (Attribute) e.nextElement();
            String bssid = attribute.name();
            int level = (BSSIDLevelMap.containsKey(bssid)) ? BSSIDLevelMap.get(bssid) : 0;
            instance.setValue(attribute, level);
          }

          instance.setValue(trainingSet.classAttribute(), sample.getLocation());

          instance.setDataset(trainingSet);
          trainingSet.add(instance);
        });

    // Build classifiers
    List<Classifier> classifiers = buildClassifiers(trainingSet);
    return classifiers;
  }
示例#4
0
  protected final void init(ProtocolStackConfigurator configurator) throws Exception {
    List<ProtocolConfiguration> configs = configurator.getProtocolStack();
    // replace vars with system props
    configs.forEach(ProtocolConfiguration::substituteVariables);

    prot_stack = new ProtocolStack(this);
    prot_stack.setup(configs); // Setup protocol stack (creates protocol, calls init() on them)
  }
示例#5
0
 public void cleanup() {
   if (!this.flags.contains(Flags.USECACHE)) {
     tempDirs.forEach(
         dir -> {
           deleteDir(dir);
         });
     tempDirs.clear();
   }
 }
示例#6
0
  public List<Classifier> buildClassifiers(Instances trainingSet) {

    List<Classifier> classifiers = new ArrayList<>();
    classifiers.add(new MultilayerPerceptron());
    classifiers.add(new SMO());
    classifiers.add(new J48());
    classifiers.add(new RandomForest());
    classifiers.add(new BayesNet());

    classifiers.forEach(
        classifier -> {
          try {
            classifier.buildClassifier(trainingSet);
          } catch (Exception e) {
            // The classifier has not been generated successfully
            e.printStackTrace();
          }
        });

    return classifiers;
  }
示例#7
0
 protected void resetAllStats() {
   List<Protocol> prots = getProtocolStack().getProtocols();
   prots.forEach(Protocol::resetStatistics);
   resetStats();
 }