Examples of RuleGraph


Examples of urban.shapes.RuleGraph

/**
* Transformer class that converts a rule to its generator
*/
public class RuleToGeneratorTransformer implements Transformer<Rule, Generator>{
  public Generator transform(Rule rule) {
    final RuleGraph graph = new RuleToRuleGraphTransformer().transform(rule);
         
    return new Generator(graph);
  }
View Full Code Here

Examples of urban.shapes.RuleGraph

    if (r == null)
      return null;
   
    Data data = new Data(r.getLhs(),r.getRhs());
   
    RuleGraph result = createRoot(r, data);
   
    fillDAG(data);
   
    return result;
  }
View Full Code Here

Examples of urban.shapes.RuleGraph

  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]));
            }
            RuleGraph value = data.rgArrays[indexOf];
            current.addChild(new Link(s.getName(),getSiteName(a,m)), value);
          }
        }
        if ("_".equals(m)){
          current.addChild(new Link(s.getName(),"_"), null);
View Full Code Here

Examples of urban.shapes.RuleGraph

    }
  }


  private RuleGraph createRoot(Rule r, Data data) {
    RuleGraph result = null;
    {
      Agent aL = null;
      Agent bondA = null;
      Agent bondB = null;
      Site siteA = null;
      Site siteB = null;
     
      Iterator<Agent> rhsIt = data.rhs.iterator();
      Iterator<Agent> lhsIt = data.lhs.iterator();
      boolean reverse=false;
      while(lhsIt.hasNext() && rhsIt.hasNext()) {
        Agent a = lhsIt.next();
        Agent b = rhsIt.next();

        Iterator<Site> asIt = a.getSites().iterator();
        Iterator<Site> bsIt = b.getSites().iterator();
        while(asIt.hasNext() && bsIt.hasNext()){
          Site s = asIt.next();
          Site bs = bsIt.next();
         
          String m = s.getBindingMark();
          String n = bs.getBindingMark();
          if (m != null && !"?".equals(m) && !"_".equals(m)){
            if (data.first.containsKey(m))
              data.second.put(m, a);
            else
              data.first.put(m, a);
          }
          if ((m == null && n != null) || (n == null && m != null)){
            if (bondA != null){
              if(bondB != null)
                throw new IllegalArgumentException("Rule not supported: More than one bond formation dissallowed.");
              bondB = a;
              siteB = bs;
              if (m != null){
                data.first.remove(m);
                data.second.remove(m);
                reverse = true;
              }
            } else {
              bondA = a;
              siteA = bs;
            }
          }
         
          if (s.getState() != null && !s.getState().equals(bs.getState())){
            if (aL != null)
              throw new IllegalArgumentException("Rule not supported: More than one flip dissallowed.");
            aL = a;
          }
        } 
      }
      if (aL == null && bondA == null)
        throw new IllegalArgumentException("At least one site should differ");
      if (aL != null && bondA != null)
        throw new IllegalArgumentException("Rule not supported: Either flip or bond, not both.");       
       
      if (bondA == null){
        int indexOf = data.lhs.indexOf(aL);
        Agent aR = data.rhs.get(indexOf);
        result = data.rgArrays[indexOf] = new RuleGraph(new SiteNode(aL, aR));
        data.q.add(pairOf(aL, data.rgArrays[indexOf]));
      } else {
        result = new RuleGraph(new BondNode());
        int i=0;
       
        i = data.lhs.indexOf(bondA);
        RuleGraph r1 = data.rgArrays[i] = new RuleGraph(new Node(reverse ? data.rhs.get(i) : bondA));
        result.addChild(new Link("1",siteA.getName()), r1);

        i = data.lhs.indexOf(bondB);
        RuleGraph r2 = data.rgArrays[i] = new RuleGraph(new Node(reverse ? data.rhs.get(i) : bondB));
        result.addChild(new Link("2",siteB.getName()), r2);       

        data.q.add(pairOf(bondA, r1));
        data.q.add(pairOf(bondB, r2));
      }
View Full Code Here

Examples of urban.shapes.RuleGraph

  @Test
  public void testTransform() throws RecognitionException{
    String rule = "B(a!1, c),A(b!1, c!2),C(a!2, b) <-> B(a!1, c!3),A(b!1, c!2),C(a!2, b!3) @ 0, 0\n";
    String expected = "B(a!1, c),C(a!2, b),A(b!1, c!2) <-> B(a!1, c!2),C(a!3, b!2),A(b!1, c!3) @ 0, 0\n";
   
    RuleGraph graph = new RuleToRuleGraphTransformer().transform(parse(rule));
    assertEquals(expected, new RuleGraphToRuleTransformer().transform(graph).toString());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.