Skip to content

Custom Duration Evaluators

Fabien Hermenier edited this page Jun 3, 2013 · 3 revisions

Custom Duration Evaluators

There is only a few implementations of DurationEvaluator. If you need to develop your own, just make a new implementation and register it inside the DurationEvaluators associated to the reconfiguration algorithm. There must be exactly one evaluator per action used the reconfiguration algorithm.

The following snippet makes a new evaluator and associates it to the ForgeVM action. This evaluator states the action duration depends on the template of the given VM that is provided through a standard attribute.

public class MyForgeEvaluator implements DurationEvaluator<VM> {

  @Override
  public int evaluate(Model mo, VM e) {
    Attributes attrs = mo.getAttributes();
    String tpl = attrs.isSet(e, "template") ? attrs.getString(e, "template") : "default";
    switch (tpl) {
      case "small":
        return 2;
      case "large":
        return 6;
      default:
        return -1; //To signal an error
    }
  }
}
    
//Associate the evaluator to the ForgeVM action
ChocoReconfigurationAlgorithm cra = new DefaultChocoReconfigurationAlgorithm();
cra.getDurationEvaluators.register(ForgeVM.class, new MyForgeEvaluator());

Clone this wiki locally