Ejemplo n.º 1
0
 private void initMainEntryPoints() {
   negEP = (NamedEntryPoint) defEP.getWorkingMemoryEntryPoint(MODE.NEGATIVE.getId());
 }
Ejemplo n.º 2
0
  public void delete(LogicalDependency node, BeliefSet beliefSet, PropagationContext context) {
    JTMSBeliefSet jtmsBeliefSet = (JTMSBeliefSet) beliefSet;
    boolean wasConflicting = jtmsBeliefSet.isConflicting();
    boolean wasNegated = jtmsBeliefSet.isNegated();

    // If the prime object is removed, we need to update the FactHandle, and tell the callback to
    // update
    boolean primeChanged = false;

    if ((jtmsBeliefSet.getPositiveFactHandle() != null
            && jtmsBeliefSet.getPositiveFactHandle().getObject() == node.getObject())
        || (jtmsBeliefSet.getNegativeFactHandle() != null
            && jtmsBeliefSet.getNegativeFactHandle().getObject() == node.getObject())) {
      primeChanged = true;
    }

    beliefSet.remove(node.getJustifierEntry());
    if (beliefSet.isEmpty()) {
      if (wasNegated) {
        defEP
            .getObjectStore()
            .addHandle(
                beliefSet.getFactHandle(),
                beliefSet
                    .getFactHandle()
                    .getObject()); // was negated, so add back in, so main retract works
        retractOrUpdateBelief(node, context, jtmsBeliefSet.getNegativeFactHandle(), false, true);
      }

      if (!(context.getType() == PropagationContext.DELETION
          && context.getFactHandle()
              == beliefSet
                  .getFactHandle())) { // don't start retract, if the FH is already in the process
        // of being retracted
        // do not if the FH is the root of the context, it means it's already in the process of
        // retraction
        retractOrUpdateBelief(
            node, context, (InternalFactHandle) jtmsBeliefSet.getFactHandle(), false, true);
      }
    } else if (wasConflicting && !jtmsBeliefSet.isConflicting()) {
      insertBelief(
          node,
          defEP
              .getObjectTypeConfigurationRegistry()
              .getObjectTypeConf(defEP.getEntryPoint(), node.getObject()),
          jtmsBeliefSet,
          wasNegated,
          wasConflicting);
    } else if (primeChanged) {
      // we know there must be at least one more of the same type, as they are still in conflict
      String value;
      InternalFactHandle handle;
      Object object = null;
      if (jtmsBeliefSet.isNegated()) {
        value = MODE.NEGATIVE.getId();
        handle = jtmsBeliefSet.getNegativeFactHandle();
        // Find the new node, and update the handle to it, Negatives iterate from the last
        for (LinkedListEntry<LogicalDependency> entry =
                (LinkedListEntry<LogicalDependency>) jtmsBeliefSet.getLast();
            entry != null;
            entry = (LinkedListEntry<LogicalDependency>) entry.getPrevious()) {
          if (entry.getObject().getValue().equals(value)) {
            object = entry.getObject().getObject();
            break;
          }
        }
      } else {
        value = MODE.POSITIVE.getId();
        handle = jtmsBeliefSet.getPositiveFactHandle();
        // Find the new node, and update the handle to it, Positives iterate from the front
        for (LinkedListEntry<LogicalDependency> entry =
                (LinkedListEntry<LogicalDependency>) jtmsBeliefSet.getFirst();
            entry != null;
            entry = (LinkedListEntry<LogicalDependency>) entry.getNext()) {
          if (entry.getObject().getValue().equals(value)) {
            object = entry.getObject().getObject();
            break;
          }
        }
      }

      // Equality might have changed on the object, so remove (which uses the handle id) and add
      // back in
      ((NamedEntryPoint) handle.getEntryPoint()).getObjectStore().updateHandle(handle, object);

      retractOrUpdateBelief(
          node, context, handle, true, false); // fully retract must be false, as this is an update
    }
  }