Package urban.model

Examples of urban.model.Agent


    }
  }
  private static Collection<Agent> toAgents(Map<Node, List<Site>> lhs, List<Node> ordering) {
    List<Agent> agents = new ArrayList<Agent>();
    for(Node n : ordering){
      agents.add(new Agent(n.getName(), lhs.get(n)));
    }
    return agents;
  }
View Full Code Here


  }

  private void fillDAG(Data data) {
    while(!data.q.isEmpty()){
      Pair<Agent,RuleGraph> p = data.q.poll();
      Agent aL = p.fst;
      RuleGraph current = p.snd;
      for(Site s : aL.getSites()){
        String m = s.getBindingMark();
        if (m != null && !"?".equals(m) && !"_".equals(m)){
          Pair<Agent,Site> p2 = data.getLinked(aL, m);
          if (p2 != null){
            Agent a = p2.fst;
            int indexOf = data.lhs.indexOf(a);
            if (data.rgArrays[indexOf] == null){
              data.rgArrays[indexOf] = new RuleGraph(new Node(a));
              data.q.add(pairOf(a,data.rgArrays[indexOf]));
            }
View Full Code Here

      this.lhs = new LinkedList<Agent>(lhs);
      this.rgArrays = new RuleGraph[this.lhs.size()];
     
      Iterator<Agent> lhsIt = this.lhs.iterator();
      while(lhsIt.hasNext()) {
        Agent a = lhsIt.next();

        Iterator<Site> asIt = a.getSites().iterator();
        while(asIt.hasNext()){
          Site s = asIt.next();
         
          String m = s.getBindingMark();
          if (m != null && !"?".equals(m) && !"_".equals(m)){
View Full Code Here

  @Override
  public Collection<Agent> transform(Collection<Agent> list) {
    if (list == null)
      return null;
    Agent agent = findAgentWithMostSites(list);
   
    Set<String> bindings = new HashSet<String>();
   
    for(Agent a : list){
      if (a != null){
        for (Site s : a.getSites()){
          String x = s.getBindingMark();
          if (x != null && Character.isDigit(x.charAt(0)))
            bindings.add(x);
        }
      }
    }
   
    if (bindings.size() < 1)
      return list;
   
    HashMap<String,String> mapping = new HashMap<String,String>();
   
    int i=1;
    for(Site s : agent.getSites()){
      String x = s.getBindingMark();
      if (x != null && Character.isDigit(x.charAt(0))){
        mapping.put(x, ""+i++);
        bindings.remove(x);
      }
    }
    for(String x : bindings){
      mapping.put(x, ""+i++);
    }
   
    List<Agent> result = new ArrayList<Agent>();
   
    for(Agent a : list){
      List<Site> sites = new ArrayList<Site>();
      for (Site s : a.getSites()){
        String x = s.getBindingMark();
        if (x != null && Character.isDigit(x.charAt(0))){
          sites.add(s.clone().setBindingMark(mapping.get(x)));
        } else {
          sites.add(s);
        }
      }
      result.add(new Agent(a.getName(),sites));
    }
   
    return result;
  }
View Full Code Here

  private Agent findAgentWithMostSites(Collection<Agent> list) {
    if (list == null)
      return null;
    int maxS =0;
    Agent maxA = null;
   
    for(Agent a : list){
      if (a != null && a.getSites() != null && a.getSites().size() > maxS){
        maxA = a;
        maxS = a.getSites().size();
View Full Code Here

   * @param permutations
   * @param checked
   * @param added
   */
  private static void addPinchPermutations(List<List<Agent>> permutations, List<Agent> checked, List<Agent> added) {
    Agent previous = null;
    List<Agent> checked2 = new ArrayList<Agent>();
   
    int i=0;
    for (Agent constraint : added) {
      if (previous == null){
        previous = constraint;
      } else {
        if (constraint.getName().equals(previous.getName())){
          if (canBeMerged(previous, constraint)){
            // (A.x, A.z) plus A.x (A.z .. from continuing loop
            List<Agent> todo = new ArrayList<Agent>();
            todo.add(merge(previous,constraint)); // could still be merged further
            todo.addAll(added.subList(i+1, added.size()));
View Full Code Here

  }
  private static Agent merge(Agent previous, Agent constraint) {
    Set<Site> set = new HashSet<Site>();
    set.addAll(previous.getSites());
    set.addAll(constraint.getSites());
    return new Agent(previous.getName(), set);
  }
View Full Code Here

    }
  };
 
  private void addAgent(Collection<Agent> list) {
    for(Agent a : list){
      final Agent mergeAgent = mergeAgent(a, agents.get(a.getName()));
      agents.put(a.getName(), mergeAgent);
    }
  }
View Full Code Here

    if (a1 == null)
      return a2;
    if (a2 == null)
      return a1;
   
    return new Agent(a1.getName(), mergeSites(a1.getSites(), a2.getSites()));
  }   
View Full Code Here


  private void fillDAG(Data data) {
    while(!data.q.isEmpty()){
      Pair<Agent,RuleGraph> p = data.q.poll();
      Agent aL = p.fst;
      RuleGraph current = p.snd;
      for(Site s : aL.getSites()){
        String m = s.getBindingMark();
        if (m != null && !"?".equals(m) && !"_".equals(m)){
          Agent a = getLinked(aL, m, data.first, data.second);
          if (a != null){
            int indexOf = data.lhs.indexOf(a);
            if (data.rgArrays[indexOf] == null){
              data.rgArrays[indexOf] = new RuleGraph(new Node(a));
              data.q.add(pairOf(a,data.rgArrays[indexOf]));
View Full Code Here

TOP

Related Classes of urban.model.Agent

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.