Ejemplo n.º 1
0
  private void insertBelief(
      LogicalDependency node,
      ObjectTypeConf typeConf,
      JTMSBeliefSet jtmsBeliefSet,
      boolean wasNegated,
      boolean wasConflicting) {
    if (jtmsBeliefSet.isNegated()) {
      jtmsBeliefSet.setNegativeFactHandle((InternalFactHandle) negEP.insert(node.getObject()));

      // As the neg partition is always stated, it'll have no equality key.
      // However the equality key is needed to stop duplicate LogicalCallbacks, so we manually set
      // it
      // **MDP could this be a problem during derialization, where the
      jtmsBeliefSet
          .getNegativeFactHandle()
          .setEqualityKey(jtmsBeliefSet.getFactHandle().getEqualityKey());
      jtmsBeliefSet.setPositiveFactHandle(null);
      if (!(wasNegated || wasConflicting)) {
        defEP
            .getObjectStore()
            .removeHandle(
                jtmsBeliefSet
                    .getFactHandle()); // Make sure the FH is no longer visible in the default
        // ObjectStore
      }
    } else {
      jtmsBeliefSet.setPositiveFactHandle(
          jtmsBeliefSet.getFactHandle()); // Use the BeliefSet FH for positive facts
      jtmsBeliefSet.setNegativeFactHandle(null);

      if (wasNegated || wasConflicting) {
        jtmsBeliefSet
            .getFactHandle()
            .setObject(
                node.getObject()); // Set the Object, as it may have been a negative initialization,
        // before conflict
        defEP
            .getObjectStore()
            .addHandle(
                jtmsBeliefSet.getPositiveFactHandle(),
                jtmsBeliefSet
                    .getPositiveFactHandle()
                    .getObject()); // Make sure the FH is visible again
      }
      defEP.insert(
          jtmsBeliefSet.getPositiveFactHandle(),
          node.getObject(),
          node.getJustifier().getRule(),
          node.getJustifier(),
          typeConf);
    }
  }
Ejemplo n.º 2
0
 private void initMainEntryPoints() {
   negEP = (NamedEntryPoint) defEP.getWorkingMemoryEntryPoint(MODE.NEGATIVE.getId());
 }
Ejemplo n.º 3
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
    }
  }