예제 #1
0
  public static POMDPState getNewState(Domain d) {
    POMDPState s = new POMDPState();

    ObjectClass doorClass = d.getObjectClass(Names.CLASS_DOOR);
    ObjectClass indexerClass = d.getObjectClass(Names.CLASS_INDEXER);

    ObjectInstance indexer = new ObjectInstance(indexerClass, Names.OBJ_INDEXER);
    indexer.setValue(Names.ATTR_INDEX, 0);
    s.addObject(indexer);

    ObjectInstance leftDoor = new ObjectInstance(doorClass, Names.OBJ_LEFT_DOOR);
    ObjectInstance rightDoor = new ObjectInstance(doorClass, Names.OBJ_RIGHT_DOOR);

    leftDoor.setValue(Names.ATTR_POSITION, Names.LEFT);
    rightDoor.setValue(Names.ATTR_POSITION, Names.RIGHT);

    boolean doorChoice = new java.util.Random().nextBoolean();
    leftDoor.setValue(Names.ATTR_TIGERNESS, doorChoice ? 0 : 1);
    rightDoor.setValue(Names.ATTR_TIGERNESS, doorChoice ? 1 : 0);

    s.addObject(leftDoor);

    s.addObject(rightDoor);

    return s;
  }
  public static State getExampleState(Domain domain) {
    State s = new State();
    ObjectInstance agent = new ObjectInstance(domain.getObjectClass(CLASSAGENT), "agent0");
    agent.setValue(ATTX, 0);
    agent.setValue(ATTY, 0);

    ObjectInstance location = new ObjectInstance(domain.getObjectClass(CLASSLOCATION), "location0");
    location.setValue(ATTX, 10);
    location.setValue(ATTY, 10);

    s.addObject(agent);
    s.addObject(location);

    return s;
  }
    @Override
    protected State performActionHelper(State s, String[] params) {

      // get agent and current position
      ObjectInstance agent = s.getFirstObjectOfClass(CLASSAGENT);
      int curX = agent.getDiscValForAttribute(ATTX);
      int curY = agent.getDiscValForAttribute(ATTY);

      // sample directon with random roll
      double r = Math.random();
      double sumProb = 0.;
      int dir = 0;
      for (int i = 0; i < this.directionProbs.length; i++) {
        sumProb += this.directionProbs[i];
        if (r < sumProb) {
          dir = i;
          break; // found direction
        }
      }

      // get resulting position
      int[] newPos = this.moveResult(curX, curY, dir);

      // set the new position
      agent.setValue(ATTX, newPos[0]);
      agent.setValue(ATTY, newPos[1]);

      // return the state we just modified
      return s;
    }
    @Override
    public List<TransitionProbability> getTransitions(State s, String[] params) {

      // get agent and current position
      ObjectInstance agent = s.getFirstObjectOfClass(CLASSAGENT);
      int curX = agent.getDiscValForAttribute(ATTX);
      int curY = agent.getDiscValForAttribute(ATTY);

      List<TransitionProbability> tps = new ArrayList<TransitionProbability>(4);
      TransitionProbability noChangeTransition = null;
      for (int i = 0; i < this.directionProbs.length; i++) {
        int[] newPos = this.moveResult(curX, curY, i);
        if (newPos[0] != curX || newPos[1] != curY) {
          // new possible outcome
          State ns = s.copy();
          ObjectInstance nagent = ns.getFirstObjectOfClass(CLASSAGENT);
          nagent.setValue(ATTX, newPos[0]);
          nagent.setValue(ATTY, newPos[1]);

          // create transition probability object and add to our list of outcomes
          tps.add(new TransitionProbability(ns, this.directionProbs[i]));
        } else {
          // this direction didn't lead anywhere new
          // if there are existing possible directions that wouldn't lead anywhere, aggregate with
          // them
          if (noChangeTransition != null) {
            noChangeTransition.p += this.directionProbs[i];
          } else {
            // otherwise create this new state and transition
            noChangeTransition = new TransitionProbability(s.copy(), this.directionProbs[i]);
            tps.add(noChangeTransition);
          }
        }
      }

      return tps;
    }