示例#1
0
  public static Instances getKnowledgeBase() {
    if (knowledgeBase == null) {
      try {
        // load knowledgebase from file
        CreateAppInsertIntoVm.knowledgeBase =
            Action.loadKnowledge(Configuration.getInstance().getKBCreateAppInsertIntoVm());

        // prediction is also performed therefore the classifier and the evaluator must be
        // instantiated
        if (!isOnlyLearning()) {
          System.out.println("Classify data CreateAppInsertInto");
          if (knowledgeBase.numInstances() > 0) {
            classifier = new MultilayerPerceptron();
            classifier.buildClassifier(knowledgeBase);
            evaluation = new Evaluation(knowledgeBase);
            evaluation.crossValidateModel(
                classifier,
                knowledgeBase,
                10,
                knowledgeBase.getRandomNumberGenerator(randomData.nextLong(1, 1000)));
            System.out.println("Classified data CreateAppInsertInto");
          } else {
            System.out.println("No Instancedata for classifier CreateAppInsertIntoVm");
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return knowledgeBase;
  }
示例#2
0
  @Override
  public void init(Resource problemApp) {
    this.setProblemResource(problemApp);
    this.setProblemType(problemApp.getProblemType());
    this.preconditionsOk = false;
    this.curInstance = null;
    this.selectedVm = null;
    this.costs = 0;
    this.app = null;

    this.costs = Configuration.getInstance().getAppInsertIntoVmCosts();

    if (problemApp instanceof App) { // only apps can be inserted
      app = (App) problemApp;
      if (app.getVm() == null) { // only new apps can be inserted
        prediction = 0;
        int curFitFactor = 0;

        for (PhysicalMachine pm : Monitor.getInstance().getPms()) {
          if (pm.isRunning()) {
            for (VirtualMachine vm : pm.getVms()) {
              curFitFactor = calculateFit(app, vm);
              if (curFitFactor > prediction) {
                preconditionsOk = true;
                prediction = curFitFactor;
                this.selectedVm = vm;
              }
            }
          }
        }
      }
    }
  }
示例#3
0
  public void terminate() {
    try {
      Action.saveKnowledge(
          Configuration.getInstance().getKBCreateAppInsertIntoVm(),
          CreateAppInsertIntoVm.getKnowledgeBase());
    } catch (IOException e) {

      e.printStackTrace();
    }
  }