/** * @return the probability that this expBetaPlanSelector will select this plan for this person. */ public static <T extends BasicPlan, I> double getSelectionProbability(ExpBetaPlanSelector<T, I> expBetaPlanSelector, HasPlansAndId<T, ?> person, final T plan) { Map<T, Double> weights = expBetaPlanSelector.calcWeights(person); double thisWeight = weights.get(plan); double sumWeights = 0.0; for (Double weight : weights.values()) { sumWeights += weight; } return (thisWeight / sumWeights); }
/** * @return a random plan from the person, random but according to its weight. */ @Override public T selectPlan(final HasPlansAndId<T, I> person) { // get the weights of all plans Map<T, Double> weights = this.calcWeights(person); double sumWeights = 0.0; for (Double weight : weights.values()) { sumWeights += weight; } // choose a random number over interval [0, sumWeights[ double selnum = sumWeights * MatsimRandom.getRandom().nextDouble(); for (T plan : person.getPlans()) { selnum -= weights.get(plan); if (selnum <= 0.0) { return plan; } } // hmm, no plan returned... either the person has no plans, or the plan(s) have no score. if (person.getPlans().size() > 0) { return person.getPlans().get(0); } // this case should never happen, except a person has no plans at all. return null; }