Package org.ggp.base.util.propnet.architecture

Examples of org.ggp.base.util.propnet.architecture.Component


      Map<GdlSentence, Component> components, Map<GdlSentence, Component> negations, Constant trueComponent,
      Constant falseComponent) throws InterruptedException {
    boolean changedSomething = false;
    for(Entry<GdlSentence, Component> entry : components.entrySet()) {
      if(entry.getKey().getName() == TRUE) {
        Component comp = entry.getValue();
        if(comp.getInputs().size() == 0) {
          comp.addInput(falseComponent);
          falseComponent.addOutput(comp);
          changedSomething = true;
        }
      }
    }
View Full Code Here


    //should instead become an output of the actual component.
    //If there is no actual component generated, then the statement
    //is necessarily FALSE and should be replaced by the false
    //component.
    for(GdlSentence sentence : temporaryComponents.keySet()) {
      Component tempComp = temporaryComponents.get(sentence);
      Component realComp = components.get(sentence);
      if(realComp == null) {
        realComp = falseComponent;
      }
      for(Component output : tempComp.getOutputs()) {
        //Disconnect
        output.removeInput(tempComp);
        //tempComp.removeOutput(output); //do at end
        //Connect
        output.addInput(realComp);
        realComp.addOutput(output);
      }
      tempComp.removeAllOutputs();

      if(temporaryNegations.containsKey(sentence)) {
        //Should be pointing to a "not" that now gets input from realComp
View Full Code Here

        //Remove as input from or
        or.removeInput(falseComponent);
        falseComponent.removeOutput(or);
        //If or has only one input, remove it
        if(or.getInputs().size() == 1) {
          Component in = or.getSingleInput();
          or.removeInput(in);
          in.removeOutput(or);
          for(Component out : or.getOutputs()) {
            //Disconnect from and
            out.removeInput(or);
            //or.removeOutput(out); //do at end
            //Connect directly to the new input
            out.addInput(in);
            in.addOutput(out);
          }
          or.removeAllOutputs();
          if (pn != null) {
              pn.removeComponent(or);
          }
View Full Code Here

        //Remove as input from and
        and.removeInput(trueComponent);
        trueComponent.removeOutput(and);
        //If and has only one input, remove it
        if(and.getInputs().size() == 1) {
          Component in = and.getSingleInput();
          and.removeInput(in);
          in.removeOutput(and);
          for(Component out : and.getOutputs()) {
            //Disconnect from and
            out.removeInput(and);
            //and.removeOutput(out); //do at end
            //Connect directly to the new input
            out.addInput(in);
            in.addOutput(out);
          }
          and.removeAllOutputs();
          if (pn != null) {
              pn.removeComponent(and);
          }
View Full Code Here

      GdlSentence sentence = entry.getKey();

      if(sentence.getName().equals(NEXT)) {
        //connect to true
        GdlSentence trueSentence = GdlPool.getRelation(TRUE, sentence.getBody());
        Component nextComponent = entry.getValue();
        Component trueComponent = components.get(trueSentence);
        //There might be no true component (for example, because the bases
        //told us so). If that's the case, don't have a transition.
        if(trueComponent == null) {
            // Skipping transition to supposedly impossible 'trueSentence'
            continue;
        }
        Transition transition = new Transition();
        transition.addInput(nextComponent);
        nextComponent.addOutput(transition);
        transition.addOutput(trueComponent);
        trueComponent.addInput(transition);
      }
    }
  }
View Full Code Here

      if(entry.getValue() == trueComponent) {
        if(entry.getKey().getName().equals(INIT)) {
          //Find the corresponding true sentence
          GdlSentence trueSentence = GdlPool.getRelation(TRUE, entry.getKey().getBody());
          //System.out.println("True sentence from init: " + trueSentence);
          Component trueSentenceComponent = components.get(trueSentence);
          if(trueSentenceComponent.getInputs().isEmpty()) {
            //Case where there is no transition input
            //Add the transition input, connect to init, continue loop
            Transition transition = new Transition();
            //init goes into transition
            transition.addInput(initProposition);
            initProposition.addOutput(transition);
            //transition goes into component
            trueSentenceComponent.addInput(transition);
            transition.addOutput(trueSentenceComponent);
          } else {
            //The transition already exists
            Component transition = trueSentenceComponent.getSingleInput();

            //We want to add init as a thing that precedes the transition
            //Disconnect existing input
            Component input = transition.getSingleInput();
            //input and init go into or, or goes into transition
            input.removeOutput(transition);
            transition.removeInput(input);
            List<Component> orInputs = new ArrayList<Component>(2);
            orInputs.add(input);
            orInputs.add(initProposition);
            orify(orInputs, transition, falseComponent);
View Full Code Here

      output.addInput(falseProp);
      return;
    }
    //If there's just one, on the other hand, don't use the or gate
    if(or.getInputs().size() == 1) {
      Component in = or.getSingleInput();
      in.removeOutput(or);
      or.removeInput(in);
      in.addOutput(output);
      output.addInput(in);
      return;
    }
    or.addOutput(output);
    output.addInput(or);
View Full Code Here

                componentsToConnect.add(null);
              }
              continue;
            }

            Component conj = components.get(transformed);
            //If conj is null and this is a sentence form we're still handling,
            //hook up to a temporary sentence form
            if(conj == null) {
              conj = temporaryComponents.get(transformed);
            }
            if(conj == null && SentenceModelUtils.inSentenceFormGroup(transformed, recursionForms)) {
              //Set up a temporary component
              Proposition tempProp = new Proposition(transformed);
              temporaryComponents.put(transformed, tempProp);
              conj = tempProp;
            }
            //Let's say this is false; we want to backtrack and change the right variable
            if(conj == null || isThisConstant(conj, falseComponent)) {
              List<GdlVariable> varsInConjunct = getVarsInConjunct(literal);
              asnItr.changeOneInNext(varsInConjunct, assignment);
              //These last steps just speed up the process
              //telling the factory to ignore this rule
              componentsToConnect.add(null);
              continue; //look at all the other restrictions we'll face
            }

            componentsToConnect.add(conj);
          } else if(literal instanceof GdlNot) {
            //Add a "not" if necessary
            //Look up the negation
            GdlSentence internal = (GdlSentence) ((GdlNot) literal).getBody();
            GdlSentence transformed = CommonTransforms.replaceVariables(internal, assignment);

            //Add constant-checking here...
            SentenceForm conjunctForm = model.getSentenceForm(transformed);
            if(constantChecker.isConstantForm(conjunctForm)) {
              if(constantChecker.isTrueConstant(transformed)) {
                List<GdlVariable> varsToChange = getVarsInConjunct(literal);
                asnItr.changeOneInNext(varsToChange, assignment);
                componentsToConnect.add(null);
              }
              continue;
            }

            Component conj = negations.get(transformed);
            if(isThisConstant(conj, falseComponent)) {
              //We need to change one of the variables inside
              List<GdlVariable> varsInConjunct = getVarsInConjunct(internal);
              asnItr.changeOneInNext(varsInConjunct, assignment);
              //ignore this rule
              componentsToConnect.add(null);
              continue;
            }
            if(conj == null) {
              conj = temporaryNegations.get(transformed);
            }
            //Check for the recursive case:
            if(conj == null && SentenceModelUtils.inSentenceFormGroup(transformed, recursionForms)) {
              Component positive = components.get(transformed);
              if(positive == null) {
                positive = temporaryComponents.get(transformed);
              }
              if(positive == null) {
                //Make the temporary proposition
                Proposition tempProp = new Proposition(transformed);
                temporaryComponents.put(transformed, tempProp);
                positive = tempProp;
              }
              //Positive is now set and in temporaryComponents
              //Evidently, wasn't in temporaryNegations
              //So we add the "not" gate and set it in temporaryNegations
              Not not = new Not();
              //Add positive as input
              not.addInput(positive);
              positive.addOutput(not);
              temporaryNegations.put(transformed, not);
              conj = not;
            }
            if(conj == null) {
              Component positive = components.get(transformed);
              //No, because then that will be attached to "negations", which could be bad

              if(positive == null) {
                //So the positive can't possibly be true (unless we have recurstion)
                //and so this would be positive always
                //We want to just skip this conjunct, so we continue to the next

                continue; //to the next conjunct
              }

              //Check if we're sharing a component with another sentence with a negation
              //(i.e. look for "nots" in our outputs and use those instead)
              Not existingNotOutput = getNotOutput(positive);
              if(existingNotOutput != null) {
                componentsToConnect.add(existingNotOutput);
                negations.put(transformed, existingNotOutput);
                continue; //to the next conjunct
              }

              Not not = new Not();
              not.addInput(positive);
              positive.addOutput(not);
              negations.put(transformed, not);
              conj = not;
            }
            componentsToConnect.add(conj);
          } else if(literal instanceof GdlDistinct) {
View Full Code Here

      output.addInput(trueProp);
      return;
    }
    //If there's just one, on the other hand, don't use the and gate
    if(and.getInputs().size() == 1) {
      Component in = and.getSingleInput();
      in.removeOutput(and);
      and.removeInput(in);
      in.addOutput(output);
      output.addInput(in);
      return;
    }
    and.addOutput(output);
    output.addInput(and);
View Full Code Here

      toAdd.add(Pair.of((Component) initProposition, Type.BOTH));

      while (!toAdd.isEmpty()) {
      ConcurrencyUtils.checkForInterruption();
        Pair<Component, Type> curEntry = toAdd.pop();
        Component curComp = curEntry.left;
        Type newInputType = curEntry.right;
        Type oldType = reachability.get(curComp);
        if (oldType == null) {
          oldType = Type.NEITHER;
        }

        //We want to send only the new addition to our children,
        //for consistency in our parent-true and parent-false
        //counts.
        //Make sure we don't double-apply a type.

        Type typeToAdd = Type.NEITHER; // Any new values that we discover we can have this iteration.
        if (curComp instanceof Proposition) {
          typeToAdd = newInputType;
        } else if (curComp instanceof Transition) {
          typeToAdd = newInputType;
        } else if (curComp instanceof Constant) {
          typeToAdd = newInputType;
        } else if (curComp instanceof Not) {
          typeToAdd = newInputType.opposite();
        } else if (curComp instanceof And) {
          if (newInputType.hasTrue) {
            numTrueInputs.add(curComp);
            if (numTrueInputs.count(curComp) == curComp.getInputs().size()) {
              typeToAdd = Type.TRUE;
            }
          }
          if (newInputType.hasFalse) {
            typeToAdd = typeToAdd.with(Type.FALSE);
          }
        } else if (curComp instanceof Or) {
          if (newInputType.hasFalse) {
            numFalseInputs.add(curComp);
            if (numFalseInputs.count(curComp) == curComp.getInputs().size()) {
              typeToAdd = Type.FALSE;
            }
          }
          if (newInputType.hasTrue) {
            typeToAdd = typeToAdd.with(Type.TRUE);
          }
        } else {
          throw new RuntimeException("Unhandled component type " + curComp.getClass());
        }

        if (oldType.includes(typeToAdd)) {
          //We don't know anything new about curComp
          continue;
        }
        reachability.put(curComp, typeToAdd.with(oldType));
        typeToAdd = typeToAdd.minus(oldType);
        if (typeToAdd == Type.NEITHER) {
          throw new RuntimeException("Something's messed up here");
        }

        //Add all our children to the stack
        for (Component output : curComp.getOutputs()) {
          toAdd.add(Pair.of(output, typeToAdd));
        }
      if (legalsToInputs.containsKey(curComp)) {
        Proposition inputProp = legalsToInputs.get(curComp);
        if (inputProp == null) {
          throw new IllegalStateException();
        }
        toAdd.add(Pair.of((Component) inputProp, typeToAdd));
      }
      }

      Constant trueConst = new Constant(true);
      Constant falseConst = new Constant(false);
      pn.addComponent(trueConst);
      pn.addComponent(falseConst);
      //Make them the input of all false/true components
      for(Entry<Component, Type> entry : reachability.entrySet()) {
          Type type = entry.getValue();
          if(type == Type.TRUE || type == Type.FALSE) {
              Component c = entry.getKey();
              if (c instanceof Constant) {
                //Don't bother trying to remove this
                continue;
              }
              //Disconnect from inputs
              for(Component input : c.getInputs()) {
                  input.removeOutput(c);
              }
              c.removeAllInputs();
              if(type == Type.TRUE ^ (c instanceof Not)) {
                  c.addInput(trueConst);
                  trueConst.addOutput(c);
              } else {
                    c.addInput(falseConst);
                    falseConst.addOutput(c);
              }
          }
      }
View Full Code Here

TOP

Related Classes of org.ggp.base.util.propnet.architecture.Component

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.