Skip to content

Commit

Permalink
#298 insert new agenda items based on weight/probability
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyaDaleh committed Jul 7, 2023
1 parent 59ab87e commit af37313
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class Deduction {
*/
private boolean[] goalItem;
/**
* Specify if new items shall replace same existing items in the chart. If
* null, don't replace. If h, replace by items with higher value (like
* Specify if new items shall replace same existing items in the chart.
* If h, replace by items with higher value (like
* probabilities). If l, replace by items with lower value (like weights). If
* - don't replace and add new backpointers to the list, commonly used for
* items without value.
Expand Down Expand Up @@ -303,7 +303,7 @@ private int checkForGoal(ChartItemInterface goal) {
continue;
}
chart.add(item);
agenda.add(item);
addToAgenda(item);
deductedFrom.add(new ArrayList<List<Integer>>() {
{
add(new ArrayList<>());
Expand Down Expand Up @@ -444,7 +444,7 @@ private void processNewItems(List<ChartItemInterface> newItems,
}
} else {
chart.add(newItem);
agenda.add(newItem);
addToAgenda(newItem);
appliedRule.add(new ArrayList<>());
appliedRule.get(appliedRule.size() - 1).add(rule.getName());
deductedFrom.add(new ArrayList<>());
Expand All @@ -453,6 +453,25 @@ private void processNewItems(List<ChartItemInterface> newItems,
}
}

private void addToAgenda(ChartItemInterface item) {
if (item instanceof ProbabilisticChartItemInterface) {
double p = ((ProbabilisticChartItemInterface) item).getProbability();
for (int i = 0; i < agenda.size(); i++) {
ProbabilisticChartItemInterface agendaItem = (ProbabilisticChartItemInterface) agenda.get(i);
double agendaP = agendaItem.getProbability();
if (replace == 'h' && p > agendaP) {
agenda.add(i, item);
return;
}
if (replace == 'l' && p < agendaP) {
agenda.add(i, item);
return;
}
}
}
agenda.add(item);
}

private void triggerTreeUpdate(int oldId,
List<ChartItemInterface> triggerItems) {
for (int i = 0; i < deductedFrom.size(); i++) {
Expand Down

0 comments on commit af37313

Please sign in to comment.