Package edu.uci.ics.jung.graph

Examples of edu.uci.ics.jung.graph.Vertex


 
 
  /** Makes a copy of the graph given to it and merges states in the pair supplied. */
  public static DirectedSparseGraph mergeAndDeterminize(Graph model, OrigStatePair pair){
    Graph original = (Graph)model.copy();
    Vertex q = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, pair.getQ().getUserDatum(JUConstants.LABEL),original);
    Vertex qDash = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, pair.getR().getUserDatum(JUConstants.LABEL),original);
    pair = new OrigStatePair(q,qDash);
    DirectedSparseGraph temp = merge((DirectedSparseGraph)original, pair);
    OrigStatePair mergable = findMergablePair(temp);
    while(mergable!=null){
      temp=merge(temp, mergable);
View Full Code Here


  }
 
  public DirectedSparseGraph learnMachine(DirectedSparseGraph model) {
    model = createAugmentedPTA(model, sPlus, sMinus);
   
    Vertex init = DeterministicDirectedSparseGraph.findInitial(model);
    init.setUserDatum(JUConstants.COLOUR, JUConstants.RED, UserData.SHARED);

    Stack<OrigStatePair> possibleMerges = chooseStatePairs(model, sPlus, sMinus);
    while(!possibleMerges.isEmpty()){
      OrigStatePair pair = possibleMerges.pop();
View Full Code Here

 
  protected boolean compatible(DirectedSparseGraph model, Collection<List<String>> sPlus, Collection<List<String>> sMinus){
    boolean returnValue = true;
    for(List<String> string:sMinus)
    {
      Vertex v = getVertex(model,string);
      if(v != null){
        if(DeterministicDirectedSparseGraph.isAccept(v))
          returnValue = false;
      }
    }
    for(List<String> string:sPlus)
    {
      Vertex v = getVertex(model,string);
      if(v == null)
        returnValue = false;
      else{
        if(!DeterministicDirectedSparseGraph.isAccept(v))
          returnValue = false;
View Full Code Here

  /*
   * needs to be refactored into smaller methods
   */
  protected List<List<String>> generateQuestions(DirectedSparseGraph model, OrigStatePair pair){
    Vertex q = pair.getQ();
    Vertex r = pair.getR();
    if(q==null || r ==null)
      return new ArrayList<List<String>>();
    boolean accepted = DeterministicDirectedSparseGraph.isAccept(q);
    if(accepted == false)
      return new ArrayList<List<String>>();
    List<String> sp = null;
    Set<List<String>> w =null;
    if(!hasAcceptedNeighbours(q)){
      sp = getShortPrefix(model, q);
      w = getShortSuffixes(model, r);
    }
    else{
      sp = getShortPrefix(model, r);// shortest sequence to the red state
      w = getSuffixes(model,q, accepted);
    }
    Iterator<List<String>> wIt;
    ArrayList<List<String>> questions = new ArrayList<List<String>>();
    Set<String>loopLabels = new HashSet<String>();
    boolean loopToR = r.getSuccessors().contains(r);
    boolean redAndBlueNeighbours = r.getNeighbors().contains(q);
    if(loopToR||redAndBlueNeighbours){ //there either exists a loop to r or will do if r and b merge
      if(loopToR){
        Edge e = findEdge(r, r);
        HashSet<String> labels = (HashSet<String>)e.getUserDatum(JUConstants.LABEL);
        loopLabels.addAll(labels);
      }
      if(redAndBlueNeighbours){
        Edge e = findEdge(r,q);
        HashSet<String> labels = (HashSet<String>)e.getUserDatum(JUConstants.LABEL);
        loopLabels.addAll(labels);
      }
    }
    wIt = w.iterator();
    while(wIt.hasNext()){
      List<String> suffix = wIt.next();
      Iterator<String> labelIt = loopLabels.iterator();
      if(!loopLabels.isEmpty()){
        while(labelIt.hasNext()){
          List<String> newQuestion = new ArrayList<String>();
          newQuestion.addAll(sp);
          newQuestion.add(labelIt.next());
          newQuestion.addAll(suffix);
          Vertex v = getVertex(model, newQuestion);
          if(v==null)
            questions.add(newQuestion);
        }
      }
      List<String> newQuestion = new ArrayList<String>();
      newQuestion.addAll(sp);
      newQuestion.addAll(suffix);
      Vertex v = getVertex(model, newQuestion);
      if(v==null)
        questions.add(newQuestion);
    }
    return questions;
  }
View Full Code Here

 
  public static boolean hasAcceptedNeighbours(Vertex v){
    Iterator<DirectedSparseEdge> neighbourIt = v.getOutEdges().iterator();
    while (neighbourIt.hasNext()){
      DirectedSparseEdge e = neighbourIt.next();
      Vertex to = e.getDest();
      if(DeterministicDirectedSparseGraph.isAccept(to))
        return true;
    }
    return false;
  }
View Full Code Here

    Set<List<String>> setOfPaths = new HashSet<List<String>>();
    Iterator<Vertex> vertexIt = graph.getVertices().iterator();
    Set<Vertex> endVertices = new HashSet<Vertex>();
    DijkstraShortestPath p = new DijkstraShortestPath(graph);
    while(vertexIt.hasNext()){
      Vertex v = vertexIt.next();
      if(v.getSuccessors().isEmpty()&& DeterministicDirectedSparseGraph.isAccept(v) == accepted)
        endVertices.add(v);
    }
    for(Vertex v:endVertices)
    {
      List l = p.getPath(r, v);
View Full Code Here

    return new HashSet<List<String>>();
  }
 
  /** Returns a sequence of names labelling a shortest path from the initial node to node q. */
  protected static List<String> getShortPrefix(DirectedSparseGraph model, Vertex q){
    Vertex init = DeterministicDirectedSparseGraph.findInitial(model);
    UnweightedShortestPath p = new UnweightedShortestPath(model);
    Iterator<Edge> pathIt =  ShortestPathUtils.getPath(p, init, q).iterator();
    List<String> list = new ArrayList<String>();
    while(pathIt.hasNext()){
      Edge e = pathIt.next();
View Full Code Here

    return list;
  }

 
  protected static DirectedSparseGraph merge(DirectedSparseGraph model, OrigStatePair pair){
    Vertex q = pair.getQ();
    Vertex qDash = pair.getR();
    Iterator<DirectedSparseEdge> inEdges = q.getInEdges().iterator();
    Set<DirectedSparseEdge> removeEdges = new HashSet<DirectedSparseEdge>();
    while(inEdges.hasNext()){
      DirectedSparseEdge e = inEdges.next();
      DirectedSparseEdge eDash = new DirectedSparseEdge(e.getSource(), qDash);
      eDash.addUserDatum(JUConstants.LABEL, e.getUserDatum(JUConstants.LABEL), UserData.CLONE);
      if(!e.getSource().getSuccessors().contains(qDash))
        model.addEdge(eDash);
      else{
        Edge existing = findEdge(e.getSource(), qDash);
        Set<String> labels = (Set<String>)existing.getUserDatum(JUConstants.LABEL);// KIRR: if you use UserData.SHARED, you do not need to copy the result back using put
        labels.addAll((Set<String>)e.getUserDatum(JUConstants.LABEL));
        existing.setUserDatum(JUConstants.LABEL, labels, UserData.CLONE);
      }
      removeEdges.add(e);
    }
    Iterator<DirectedSparseEdge> outEdges = q.getOutEdges().iterator();
    while(outEdges.hasNext()){
      DirectedSparseEdge e = outEdges.next();
      DirectedSparseEdge eDash = new DirectedSparseEdge(qDash, e.getDest());
      eDash.addUserDatum(JUConstants.LABEL, e.getUserDatum(JUConstants.LABEL), UserData.CLONE);
      if(!qDash.getSuccessors().contains(e.getDest()))
        model.addEdge(eDash);
      else{
        Edge existing = findEdge(qDash, e.getDest());
        Set<String> labels = (Set<String>)existing.getUserDatum(JUConstants.LABEL);
        labels.addAll((Set<String>)e.getUserDatum(JUConstants.LABEL));
View Full Code Here

   */
  protected static OrigStatePair findMergablePair(DirectedSparseGraph model){
    List<Vertex> queue = DeterministicDirectedSparseGraph.getBFSList(model);
    Iterator<Vertex> queueIt = queue.iterator();
    while(queueIt.hasNext()){
      Vertex v = queueIt.next();
      Set<DirectedSparseEdge> edges = v.getOutEdges();
      Iterator<DirectedSparseEdge> edgeIt = edges.iterator();
      Map<String,DirectedSparseEdge> doneLabels = new HashMap<String,DirectedSparseEdge>();
      while(edgeIt.hasNext()){
        DirectedSparseEdge e = edgeIt.next();
        Set<String> labels = (Set<String>)e.getUserDatum(JUConstants.LABEL);
View Full Code Here

    Stack<Vertex> blueStack = new Stack<Vertex>();
    blueStack.addAll(computeBlue(g));
    TreeMap<Integer,Vector<OrigStatePair> > scoreToPair = new TreeMap<Integer,Vector<OrigStatePair> >();// maps scores to pairs which have those scores
    while(!blueStack.isEmpty()){
      TreeMap<Integer,Vector<OrigStatePair> > singleSet = new TreeMap<Integer,Vector<OrigStatePair> >();
      Vertex blueVertex = blueStack.pop();
      Stack<Vertex> redStack = new Stack<Vertex>();
      redStack.addAll(DeterministicDirectedSparseGraph.findVertices(JUConstants.COLOUR, JUConstants.RED, g));
      while(!redStack.isEmpty()){
        Vertex redVertex = redStack.pop();
        OrigStatePair pair = new OrigStatePair(blueVertex, redVertex);
        doneEdges = new HashSet<DirectedSparseEdge>();
        Integer score = new Integer(computeScore(g,pair));
        DirectedSparseGraph temp = mergeAndDeterminize((Graph)g.copy(), pair);
        if(compatible(temp, sPlus, sMinus)){
View Full Code Here

TOP

Related Classes of edu.uci.ics.jung.graph.Vertex

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.