Program: 12237
Project: 12237
Buggy source:
/** 
 * Examines the preferences for a given slot, and returns an impasse type for the slot. The argument "result_candidates" is set to a list of candidate values for the slot--if the returned impasse type is NONE_IMPASSE_TYPE, this is the set of winners; otherwise it is the set of tied, conflicted, or constraint-failured values. This list of values is a list of preferences for those values, linked via the "next_candidate" field on each preference structure. If there is more than one preference for a given value, only one is returned in the result_candidates, with (first) require preferences being preferred over acceptable preferences, and (second) preferences from higher match goals being preferred over those from lower match goals. <p>BUGBUG There is a problem here: since the require/acceptable priority takes precedence over the match goal level priority, it's possible that we could return a require preference from lower in the goal stack than some acceptable preference. If the goal stack gets popped soon afterwards (i.e., before the next time the slot is re-decided, I think), we would be left with a WME still in WM (not GC'd, because of the acceptable preference higher up) but with a trace pointing to a deallocated require preference. This case is very obsure and unlikely to come up, but it could easily cause a core dump or worse. <p>decide.cpp:840:run_preference_semantics
 * @param s
 * @param result_candidates
 * @param consistency (defaulted to false in CSoar)
 * @param predict  (defaulted to false in CSoar)
 * @return
 */
private ImpasseType run_preference_semantics(Slot s,ByRef<Preference> result_candidates,boolean consistency,boolean predict){
  if (s.getAllPreferences() == null) {
    if (!s.isa_context_slot)     tempMemory.mark_slot_for_possible_removal(s);
    result_candidates.value=null;
    return ImpasseType.NONE;
  }
  if (!s.isa_context_slot) {
    if (decisionManip.select_get_operator() != null) {
      final Preference force_result=decisionManip.select_force(s.getPreferencesByType(PreferenceType.ACCEPTABLE),!predict);
      if (force_result != null) {
        result_candidates.value=force_result;
        if (!predict && rl.rl_enabled()) {
          exploration.exploration_compute_value_of_candidate(force_result,s,0);
          rl.rl_perform_update(force_result.numeric_value,s.id);
        }
        return ImpasseType.NONE;
      }
 else {
        context.getPrinter().warn("String_Node_Str");
      }
    }
  }
  if (s.getPreferencesByType(PreferenceType.REQUIRE) != null) {
    return require_preference_semantics(s,result_candidates);
  }
  for (Preference p=s.getPreferencesByType(PreferenceType.ACCEPTABLE); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.CANDIDATE;
  for (Preference p=s.getPreferencesByType(PreferenceType.PROHIBIT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.NOTHING;
  for (Preference p=s.getPreferencesByType(PreferenceType.REJECT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.NOTHING;
  Preference candidates=null;
  for (Preference p=s.getPreferencesByType(PreferenceType.ACCEPTABLE); p != null; p=p.next) {
    if (p.value.decider_flag == DeciderFlag.CANDIDATE) {
      p.next_candidate=candidates;
      candidates=p;
      p.value.decider_flag=DeciderFlag.NOTHING;
    }
  }
  if (!s.isa_context_slot) {
    result_candidates.value=candidates;
    return ImpasseType.NONE;
  }
  if ((candidates == null) || (candidates.next_candidate == null)) {
    result_candidates.value=candidates;
    if (!consistency && rl.rl_enabled() && candidates != null) {
      exploration.exploration_compute_value_of_candidate(candidates,s,0);
      rl.rl_perform_update(candidates.numeric_value,s.id);
    }
    return ImpasseType.NONE;
  }
  if (s.getPreferencesByType(PreferenceType.BETTER) != null || s.getPreferencesByType(PreferenceType.WORSE) != null) {
    for (Preference p=s.getPreferencesByType(PreferenceType.BETTER); p != null; p=p.next) {
      p.value.decider_flag=DeciderFlag.NOTHING;
      p.referent.decider_flag=DeciderFlag.NOTHING;
    }
    for (Preference p=s.getPreferencesByType(PreferenceType.WORSE); p != null; p=p.next) {
      p.value.decider_flag=DeciderFlag.NOTHING;
      p.referent.decider_flag=DeciderFlag.NOTHING;
    }
    for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
      cand.value.decider_flag=DeciderFlag.CANDIDATE;
    }
    for (Preference p=s.getPreferencesByType(PreferenceType.BETTER); p != null; p=p.next) {
      final SymbolImpl j=p.value;
      final SymbolImpl k=p.referent;
      if (j == k)       continue;
      if (j.decider_flag.isSomething() && k.decider_flag.isSomething()) {
        if (k.decider_flag != DeciderFlag.CONFLICTED)         k.decider_flag=DeciderFlag.FORMER_CANDIDATE;
        if ((j.decider_flag != DeciderFlag.CONFLICTED) || (k.decider_flag != DeciderFlag.CONFLICTED)) {
          for (Preference p2=s.getPreferencesByType(PreferenceType.BETTER); p2 != null; p2=p2.next)           if ((p2.value == k) && (p2.referent == j)) {
            j.decider_flag=DeciderFlag.CONFLICTED;
            k.decider_flag=DeciderFlag.CONFLICTED;
            break;
          }
          for (Preference p2=s.getPreferencesByType(PreferenceType.WORSE); p2 != null; p2=p2.next)           if ((p2.value == j) && (p2.referent == k)) {
            j.decider_flag=DeciderFlag.CONFLICTED;
            k.decider_flag=DeciderFlag.CONFLICTED;
            break;
          }
        }
      }
    }
    for (Preference p=s.getPreferencesByType(PreferenceType.WORSE); p != null; p=p.next) {
      final SymbolImpl j=p.value;
      final SymbolImpl k=p.referent;
      if (j == k)       continue;
      if (j.decider_flag.isSomething() && k.decider_flag.isSomething()) {
        if (j.decider_flag != DeciderFlag.CONFLICTED)         j.decider_flag=DeciderFlag.FORMER_CANDIDATE;
        if ((j.decider_flag != DeciderFlag.CONFLICTED) || (k.decider_flag != DeciderFlag.CONFLICTED)) {
          for (Preference p2=s.getPreferencesByType(PreferenceType.WORSE); p2 != null; p2=p2.next)           if ((p2.value == k) && (p2.referent == j)) {
            j.decider_flag=DeciderFlag.CONFLICTED;
            k.decider_flag=DeciderFlag.CONFLICTED;
            break;
          }
        }
      }
    }
    Preference cand=null, prev_cand=null;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     if (cand.value.decider_flag == DeciderFlag.CONFLICTED)     break;
    if (cand != null) {
      prev_cand=null;
      cand=candidates;
      while (cand != null) {
        if (cand.value.decider_flag != DeciderFlag.CONFLICTED) {
          if (prev_cand != null)           prev_cand.next_candidate=cand.next_candidate;
 else           candidates=cand.next_candidate;
        }
 else {
          prev_cand=cand;
        }
        cand=cand.next_candidate;
      }
      result_candidates.value=candidates;
      return ImpasseType.CONFLICT;
    }
    prev_cand=null;
    cand=candidates;
    while (cand != null) {
      if (cand.value.decider_flag == DeciderFlag.FORMER_CANDIDATE) {
        if (prev_cand != null)         prev_cand.next_candidate=cand.next_candidate;
 else         candidates=cand.next_candidate;
      }
 else {
        prev_cand=cand;
      }
      cand=cand.next_candidate;
    }
  }
  if (s.getPreferencesByType(PreferenceType.BEST) != null) {
    Preference cand, prev_cand;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     cand.value.decider_flag=DeciderFlag.NOTHING;
    for (Preference p=s.getPreferencesByType(PreferenceType.BEST); p != null; p=p.next)     p.value.decider_flag=DeciderFlag.BEST;
    prev_cand=null;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     if (cand.value.decider_flag == DeciderFlag.BEST) {
      if (prev_cand != null)       prev_cand.next_candidate=cand;
 else       candidates=cand;
      prev_cand=cand;
    }
    if (prev_cand != null)     prev_cand.next_candidate=null;
  }
  if (s.getPreferencesByType(PreferenceType.WORST) != null) {
    Preference cand, prev_cand;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     cand.value.decider_flag=DeciderFlag.NOTHING;
    for (Preference p=s.getPreferencesByType(PreferenceType.WORST); p != null; p=p.next)     p.value.decider_flag=DeciderFlag.WORST;
    prev_cand=null;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     if (cand.value.decider_flag != DeciderFlag.WORST) {
      if (prev_cand != null)       prev_cand.next_candidate=cand;
 else       candidates=cand;
      prev_cand=cand;
    }
    if (prev_cand != null)     prev_cand.next_candidate=null;
  }
  if (candidates == null || candidates.next_candidate == null) {
    result_candidates.value=candidates;
    if (!consistency && rl.rl_enabled() && candidates != null) {
      exploration.exploration_compute_value_of_candidate(candidates,s,0);
      rl.rl_perform_update(candidates.numeric_value,s.id);
    }
    return ImpasseType.NONE;
  }
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate)   cand.value.decider_flag=DeciderFlag.NOTHING;
  for (Preference p=s.getPreferencesByType(PreferenceType.UNARY_INDIFFERENT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.UNARY_INDIFFERENT;
  for (Preference p=s.getPreferencesByType(PreferenceType.NUMERIC_INDIFFERENT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.UNARY_INDIFFERENT_CONSTANT;
  for (Preference p=s.getPreferencesByType(PreferenceType.BINARY_INDIFFERENT); p != null; p=p.next) {
    if ((p.referent.asInteger() != null) || (p.referent.asDouble() != null))     p.value.decider_flag=DeciderFlag.UNARY_INDIFFERENT_CONSTANT;
  }
  boolean not_all_indifferent=false;
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
    if (cand.value.decider_flag == DeciderFlag.UNARY_INDIFFERENT)     continue;
 else     if (cand.value.decider_flag == DeciderFlag.UNARY_INDIFFERENT_CONSTANT)     continue;
    for (Preference p=candidates; p != null; p=p.next_candidate) {
      if (p == cand)       continue;
      boolean match_found=false;
      for (Preference p2=s.getPreferencesByType(PreferenceType.BINARY_INDIFFERENT); p2 != null; p2=p2.next) {
        if (((p2.value == cand.value) && (p2.referent == p.value)) || ((p2.value == p.value) && (p2.referent == cand.value))) {
          match_found=true;
          break;
        }
      }
      if (!match_found) {
        not_all_indifferent=true;
        break;
      }
    }
    if (not_all_indifferent)     break;
  }
  if (!not_all_indifferent) {
    if (!consistency) {
      result_candidates.value=exploration.exploration_choose_according_to_policy(s,candidates);
      result_candidates.value.next_candidate=null;
    }
 else     result_candidates.value=candidates;
    return ImpasseType.NONE;
  }
  if (s.isa_context_slot) {
    result_candidates.value=candidates;
    return ImpasseType.TIE;
  }
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate)   cand.value.decider_flag=DeciderFlag.NOTHING;
  for (Preference p=s.getPreferencesByType(PreferenceType.UNARY_PARALLEL); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.UNARY_PARALLEL;
  boolean not_all_parallel=false;
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
    if (cand.value.decider_flag == DeciderFlag.UNARY_PARALLEL)     continue;
    for (Preference p=candidates; p != null; p=p.next_candidate) {
      if (p == cand)       continue;
      boolean match_found=false;
      for (Preference p2=s.getPreferencesByType(PreferenceType.BINARY_PARALLEL); p2 != null; p2=p2.next) {
        if (((p2.value == cand.value) && (p2.referent == p.value)) || ((p2.value == p.value) && (p2.referent == cand.value))) {
          match_found=true;
          break;
        }
      }
      if (!match_found) {
        not_all_parallel=true;
        break;
      }
    }
    if (not_all_parallel)     break;
  }
  result_candidates.value=candidates;
  if (!not_all_parallel) {
    return ImpasseType.NONE;
  }
  return ImpasseType.TIE;
}

Fixed version (ground truth):
/** 
 * Examines the preferences for a given slot, and returns an impasse type for the slot. The argument "result_candidates" is set to a list of candidate values for the slot--if the returned impasse type is NONE_IMPASSE_TYPE, this is the set of winners; otherwise it is the set of tied, conflicted, or constraint-failured values. This list of values is a list of preferences for those values, linked via the "next_candidate" field on each preference structure. If there is more than one preference for a given value, only one is returned in the result_candidates, with (first) require preferences being preferred over acceptable preferences, and (second) preferences from higher match goals being preferred over those from lower match goals. <p>BUGBUG There is a problem here: since the require/acceptable priority takes precedence over the match goal level priority, it's possible that we could return a require preference from lower in the goal stack than some acceptable preference. If the goal stack gets popped soon afterwards (i.e., before the next time the slot is re-decided, I think), we would be left with a WME still in WM (not GC'd, because of the acceptable preference higher up) but with a trace pointing to a deallocated require preference. This case is very obsure and unlikely to come up, but it could easily cause a core dump or worse. <p>decide.cpp:840:run_preference_semantics
 * @param s
 * @param result_candidates
 * @param consistency (defaulted to false in CSoar)
 * @param predict  (defaulted to false in CSoar)
 * @return
 */
private ImpasseType run_preference_semantics(Slot s,ByRef<Preference> result_candidates,boolean consistency,boolean predict){
  if (s.getAllPreferences() == null) {
    if (!s.isa_context_slot)     tempMemory.mark_slot_for_possible_removal(s);
    result_candidates.value=null;
    return ImpasseType.NONE;
  }
  if (!s.isa_context_slot) {
    if (decisionManip.select_get_operator() != null) {
      final Preference force_result=decisionManip.select_force(s.getPreferencesByType(PreferenceType.ACCEPTABLE),!predict);
      if (force_result != null) {
        result_candidates.value=force_result;
        if (!predict && rl.rl_enabled()) {
          exploration.exploration_compute_value_of_candidate(force_result,s,0);
          rl.rl_perform_update(force_result.numeric_value,s.id);
        }
        return ImpasseType.NONE;
      }
 else {
        context.getPrinter().warn("String_Node_Str");
      }
    }
  }
  if (s.getPreferencesByType(PreferenceType.REQUIRE) != null) {
    return require_preference_semantics(s,result_candidates);
  }
  for (Preference p=s.getPreferencesByType(PreferenceType.ACCEPTABLE); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.CANDIDATE;
  for (Preference p=s.getPreferencesByType(PreferenceType.PROHIBIT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.NOTHING;
  for (Preference p=s.getPreferencesByType(PreferenceType.REJECT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.NOTHING;
  Preference candidates=null;
  for (Preference p=s.getPreferencesByType(PreferenceType.ACCEPTABLE); p != null; p=p.next) {
    if (p.value.decider_flag == DeciderFlag.CANDIDATE) {
      p.next_candidate=candidates;
      candidates=p;
      p.value.decider_flag=DeciderFlag.NOTHING;
    }
  }
  if (!s.isa_context_slot) {
    result_candidates.value=candidates;
    return ImpasseType.NONE;
  }
  if ((candidates == null) || (candidates.next_candidate == null)) {
    result_candidates.value=candidates;
    if (!consistency && rl.rl_enabled() && candidates != null) {
      exploration.exploration_compute_value_of_candidate(candidates,s,0);
      rl.rl_perform_update(candidates.numeric_value,s.id);
    }
    return ImpasseType.NONE;
  }
  if (NEW_PREFERENCES_SCHEME) {
    if (s.getPreferencesByType(PreferenceType.BETTER) != null || s.getPreferencesByType(PreferenceType.WORSE) != null) {
      for (Preference p=s.getPreferencesByType(PreferenceType.BETTER); p != null; p=p.next) {
        p.value.decider_flag=DeciderFlag.NOTHING;
        p.referent.decider_flag=DeciderFlag.NOTHING;
      }
      for (Preference p=s.getPreferencesByType(PreferenceType.WORSE); p != null; p=p.next) {
        p.value.decider_flag=DeciderFlag.NOTHING;
        p.referent.decider_flag=DeciderFlag.NOTHING;
      }
      for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
        cand.value.decider_flag=DeciderFlag.CANDIDATE;
      }
      for (Preference p=s.getPreferencesByType(PreferenceType.BETTER); p != null; p=p.next) {
        final SymbolImpl j=p.value;
        final SymbolImpl k=p.referent;
        if (j == k)         continue;
        if (j.decider_flag.isSomething() && k.decider_flag.isSomething()) {
          if (j.decider_flag == DeciderFlag.CANDIDATE || k.decider_flag == DeciderFlag.CANDIDATE)           k.decider_flag=DeciderFlag.CONFLICTED;
        }
      }
      for (Preference p=s.getPreferencesByType(PreferenceType.WORSE); p != null; p=p.next) {
        final SymbolImpl j=p.value;
        final SymbolImpl k=p.referent;
        if (j == k)         continue;
        if (j.decider_flag.isSomething() && k.decider_flag.isSomething()) {
          if (j.decider_flag == DeciderFlag.CANDIDATE || k.decider_flag == DeciderFlag.CANDIDATE)           j.decider_flag=DeciderFlag.CONFLICTED;
        }
      }
      Preference cand=null, prev_cand=null;
      for (cand=candidates; cand != null; cand=cand.next_candidate) {
        if (cand.value.decider_flag == DeciderFlag.CANDIDATE)         break;
      }
      if (cand == null) {
        prev_cand=null;
        cand=candidates;
        while (cand != null) {
          if (cand.value.decider_flag != DeciderFlag.CONFLICTED) {
            if (prev_cand != null)             prev_cand.next_candidate=cand.next_candidate;
 else             candidates=cand.next_candidate;
          }
 else {
            prev_cand=cand;
          }
          cand=cand.next_candidate;
        }
        result_candidates.value=candidates;
        return ImpasseType.CONFLICT;
      }
      prev_cand=null;
      cand=candidates;
      while (cand != null) {
        if (cand.value.decider_flag == DeciderFlag.CONFLICTED) {
          if (prev_cand != null)           prev_cand.next_candidate=cand.next_candidate;
 else           candidates=cand.next_candidate;
        }
 else {
          prev_cand=cand;
        }
        cand=cand.next_candidate;
      }
    }
  }
 else {
    if (s.getPreferencesByType(PreferenceType.BETTER) != null || s.getPreferencesByType(PreferenceType.WORSE) != null) {
      for (Preference p=s.getPreferencesByType(PreferenceType.BETTER); p != null; p=p.next) {
        p.value.decider_flag=DeciderFlag.NOTHING;
        p.referent.decider_flag=DeciderFlag.NOTHING;
      }
      for (Preference p=s.getPreferencesByType(PreferenceType.WORSE); p != null; p=p.next) {
        p.value.decider_flag=DeciderFlag.NOTHING;
        p.referent.decider_flag=DeciderFlag.NOTHING;
      }
      for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
        cand.value.decider_flag=DeciderFlag.CANDIDATE;
      }
      for (Preference p=s.getPreferencesByType(PreferenceType.BETTER); p != null; p=p.next) {
        final SymbolImpl j=p.value;
        final SymbolImpl k=p.referent;
        if (j == k)         continue;
        if (j.decider_flag.isSomething() && k.decider_flag.isSomething()) {
          if (k.decider_flag != DeciderFlag.CONFLICTED)           k.decider_flag=DeciderFlag.FORMER_CANDIDATE;
          if ((j.decider_flag != DeciderFlag.CONFLICTED) || (k.decider_flag != DeciderFlag.CONFLICTED)) {
            for (Preference p2=s.getPreferencesByType(PreferenceType.BETTER); p2 != null; p2=p2.next)             if ((p2.value == k) && (p2.referent == j)) {
              j.decider_flag=DeciderFlag.CONFLICTED;
              k.decider_flag=DeciderFlag.CONFLICTED;
              break;
            }
            for (Preference p2=s.getPreferencesByType(PreferenceType.WORSE); p2 != null; p2=p2.next)             if ((p2.value == j) && (p2.referent == k)) {
              j.decider_flag=DeciderFlag.CONFLICTED;
              k.decider_flag=DeciderFlag.CONFLICTED;
              break;
            }
          }
        }
      }
      for (Preference p=s.getPreferencesByType(PreferenceType.WORSE); p != null; p=p.next) {
        final SymbolImpl j=p.value;
        final SymbolImpl k=p.referent;
        if (j == k)         continue;
        if (j.decider_flag.isSomething() && k.decider_flag.isSomething()) {
          if (j.decider_flag != DeciderFlag.CONFLICTED)           j.decider_flag=DeciderFlag.FORMER_CANDIDATE;
          if ((j.decider_flag != DeciderFlag.CONFLICTED) || (k.decider_flag != DeciderFlag.CONFLICTED)) {
            for (Preference p2=s.getPreferencesByType(PreferenceType.WORSE); p2 != null; p2=p2.next)             if ((p2.value == k) && (p2.referent == j)) {
              j.decider_flag=DeciderFlag.CONFLICTED;
              k.decider_flag=DeciderFlag.CONFLICTED;
              break;
            }
          }
        }
      }
      Preference cand=null, prev_cand=null;
      for (cand=candidates; cand != null; cand=cand.next_candidate)       if (cand.value.decider_flag == DeciderFlag.CONFLICTED)       break;
      if (cand != null) {
        prev_cand=null;
        cand=candidates;
        while (cand != null) {
          if (cand.value.decider_flag != DeciderFlag.CONFLICTED) {
            if (prev_cand != null)             prev_cand.next_candidate=cand.next_candidate;
 else             candidates=cand.next_candidate;
          }
 else {
            prev_cand=cand;
          }
          cand=cand.next_candidate;
        }
        result_candidates.value=candidates;
        return ImpasseType.CONFLICT;
      }
      prev_cand=null;
      cand=candidates;
      while (cand != null) {
        if (cand.value.decider_flag == DeciderFlag.FORMER_CANDIDATE) {
          if (prev_cand != null)           prev_cand.next_candidate=cand.next_candidate;
 else           candidates=cand.next_candidate;
        }
 else {
          prev_cand=cand;
        }
        cand=cand.next_candidate;
      }
    }
  }
  if (s.getPreferencesByType(PreferenceType.BEST) != null) {
    Preference cand, prev_cand;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     cand.value.decider_flag=DeciderFlag.NOTHING;
    for (Preference p=s.getPreferencesByType(PreferenceType.BEST); p != null; p=p.next)     p.value.decider_flag=DeciderFlag.BEST;
    prev_cand=null;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     if (cand.value.decider_flag == DeciderFlag.BEST) {
      if (prev_cand != null)       prev_cand.next_candidate=cand;
 else       candidates=cand;
      prev_cand=cand;
    }
    if (prev_cand != null)     prev_cand.next_candidate=null;
  }
  if (s.getPreferencesByType(PreferenceType.WORST) != null) {
    Preference cand, prev_cand;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     cand.value.decider_flag=DeciderFlag.NOTHING;
    for (Preference p=s.getPreferencesByType(PreferenceType.WORST); p != null; p=p.next)     p.value.decider_flag=DeciderFlag.WORST;
    prev_cand=null;
    for (cand=candidates; cand != null; cand=cand.next_candidate)     if (cand.value.decider_flag != DeciderFlag.WORST) {
      if (prev_cand != null)       prev_cand.next_candidate=cand;
 else       candidates=cand;
      prev_cand=cand;
    }
    if (prev_cand != null)     prev_cand.next_candidate=null;
  }
  if (candidates == null || candidates.next_candidate == null) {
    result_candidates.value=candidates;
    if (!consistency && rl.rl_enabled() && candidates != null) {
      exploration.exploration_compute_value_of_candidate(candidates,s,0);
      rl.rl_perform_update(candidates.numeric_value,s.id);
    }
    return ImpasseType.NONE;
  }
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate)   cand.value.decider_flag=DeciderFlag.NOTHING;
  for (Preference p=s.getPreferencesByType(PreferenceType.UNARY_INDIFFERENT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.UNARY_INDIFFERENT;
  for (Preference p=s.getPreferencesByType(PreferenceType.NUMERIC_INDIFFERENT); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.UNARY_INDIFFERENT_CONSTANT;
  for (Preference p=s.getPreferencesByType(PreferenceType.BINARY_INDIFFERENT); p != null; p=p.next) {
    if ((p.referent.asInteger() != null) || (p.referent.asDouble() != null))     p.value.decider_flag=DeciderFlag.UNARY_INDIFFERENT_CONSTANT;
  }
  boolean not_all_indifferent=false;
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
    if (cand.value.decider_flag == DeciderFlag.UNARY_INDIFFERENT)     continue;
 else     if (cand.value.decider_flag == DeciderFlag.UNARY_INDIFFERENT_CONSTANT)     continue;
    for (Preference p=candidates; p != null; p=p.next_candidate) {
      if (p == cand)       continue;
      boolean match_found=false;
      for (Preference p2=s.getPreferencesByType(PreferenceType.BINARY_INDIFFERENT); p2 != null; p2=p2.next) {
        if (((p2.value == cand.value) && (p2.referent == p.value)) || ((p2.value == p.value) && (p2.referent == cand.value))) {
          match_found=true;
          break;
        }
      }
      if (!match_found) {
        not_all_indifferent=true;
        break;
      }
    }
    if (not_all_indifferent)     break;
  }
  if (!not_all_indifferent) {
    if (!consistency) {
      result_candidates.value=exploration.exploration_choose_according_to_policy(s,candidates);
      result_candidates.value.next_candidate=null;
    }
 else     result_candidates.value=candidates;
    return ImpasseType.NONE;
  }
  if (s.isa_context_slot) {
    result_candidates.value=candidates;
    return ImpasseType.TIE;
  }
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate)   cand.value.decider_flag=DeciderFlag.NOTHING;
  for (Preference p=s.getPreferencesByType(PreferenceType.UNARY_PARALLEL); p != null; p=p.next)   p.value.decider_flag=DeciderFlag.UNARY_PARALLEL;
  boolean not_all_parallel=false;
  for (Preference cand=candidates; cand != null; cand=cand.next_candidate) {
    if (cand.value.decider_flag == DeciderFlag.UNARY_PARALLEL)     continue;
    for (Preference p=candidates; p != null; p=p.next_candidate) {
      if (p == cand)       continue;
      boolean match_found=false;
      for (Preference p2=s.getPreferencesByType(PreferenceType.BINARY_PARALLEL); p2 != null; p2=p2.next) {
        if (((p2.value == cand.value) && (p2.referent == p.value)) || ((p2.value == p.value) && (p2.referent == cand.value))) {
          match_found=true;
          break;
        }
      }
      if (!match_found) {
        not_all_parallel=true;
        break;
      }
    }
    if (not_all_parallel)     break;
  }
  result_candidates.value=candidates;
  if (!not_all_parallel) {
    return ImpasseType.NONE;
  }
  return ImpasseType.TIE;
}