In RewardCalculator, the method rewardSolution takes in a preferenceId. When this method is called from QModelFixer, it is called with -1. Is there a need for this variable at all?
rewardCalculator.rewardSolution(bestSequence, -1);
/**
* Rewards the specified sequence.
*
* @param solution
* @param preferenceId
*/
public void rewardSolution(Solution solution, int preferenceId) {
QTable qTable = knowledge.getQTable();
for (int i = 0; i < solution.getSequence().size(); i++) {
int contextId = solution.getSequence().get(i).getAction().getHierarchy();
int errorCode = solution.getSequence().get(i).getError().getCode();
int actionId = solution.getSequence().get(i).getAction().getCode();
double oldWeight = qTable.getWeight(errorCode, contextId, actionId);
qTable.setWeight(errorCode, contextId, actionId, oldWeight + 300);
if (preferenceId > -1) {
if (!qTable.getTagDictionaryForAction(errorCode, contextId, actionId).contains(preferenceId)) {
qTable.setTagValueInTagDictionary(errorCode, contextId, actionId, preferenceId, 500);
} else {
int oldTagValue = qTable.getTagDictionaryForAction(errorCode, contextId, actionId)
.getWeightFor(preferenceId);
qTable.setTagValueInTagDictionary(errorCode, contextId, actionId, preferenceId, oldTagValue + 500);
}
}
qTable.updateReward(solution.getSequence().get(i), contextId);
}
}
It comes from the original code:
if (getBestSeq().getSeq().size() != 0) {
updateSequencesWeights(getBestSeq(), -1);
sx.getModel().save(null);
}
void updateSequencesWeights(Sequence s, int tag) {
int num;
for (int i = 0; i < s.getSeq().size(); i++) {
if (s.getSeq().get(i).getAction().getSubHierarchy() > -1) {
num = Integer.valueOf(String.valueOf(s.getSeq().get(i).getAction().getHierarchy())
+ String.valueOf(s.getSeq().get(i).getAction().getSubHierarchy()));
} else {
num = s.getSeq().get(i).getAction().getHierarchy();
}
getNewXp().getqTable().get(s.getSeq().get(i).getError().getCode()).get(num).put(
s.getSeq().get(i).getAction().getCode(),
getNewXp().getqTable().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()) + 300);
if (tag > -1) {
if (!getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary().containsKey(tag)) {
getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary().put(tag, 500);
} else {
getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary().put(tag,
getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode())
.get(num).get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary()
.get(tag) + 500);
}
}
if(tagMap.containsKey(s.getSeq().get(i).getError().getCode())) {
if(tagMap.get(s.getSeq().get(i).getError().getCode()).containsKey(num)) {
if(tagMap.get(s.getSeq().get(i).getError().getCode()).get(num).containsKey(s.getSeq().get(i).getAction().getCode())) {
for( Integer key : tagMap.get(s.getSeq().get(i).getError().getCode()).get(num).
get(s.getSeq().get(i).getAction().getCode()).keySet()) {
if (!getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary().containsKey(key)) {
getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary().put(key, tagMap.get(s.getSeq().get(i).getError().getCode()).get(num).
get(s.getSeq().get(i).getAction().getCode()).get(key));
} else {
getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode()).get(num)
.get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary().put(key,
getNewXp().getActionsDictionary().get(s.getSeq().get(i).getError().getCode())
.get(num).get(s.getSeq().get(i).getAction().getCode()).getTagsDictionary()
.get(key) +
tagMap.get(s.getSeq().get(i).getError().getCode()).get(num).
get(s.getSeq().get(i).getAction().getCode()).get(key));
}
}
}
}
}
}
}
In RewardCalculator, the method rewardSolution takes in a preferenceId. When this method is called from QModelFixer, it is called with -1. Is there a need for this variable at all?
rewardCalculator.rewardSolution(bestSequence, -1);It comes from the original code: