Package edu.uci.ics.jung.graph.impl

Examples of edu.uci.ics.jung.graph.impl.DirectedSparseEdge


    if(different(blueRed))
        return -1;

    Iterator<DirectedSparseEdge> edgesOut = blueRed.getQ().getOutEdges().iterator();
    while(edgesOut.hasNext()){
      DirectedSparseEdge e = edgesOut.next();
      if(this.doneEdges.contains(e))
        continue;
     
      doneEdges.add(e);
      Set<Label> labels = (Set<Label>)e.getUserDatum(JUConstants.LABEL);
      Iterator<Label> labelIt = labels.iterator();
      while(labelIt.hasNext()){
        List<Label> string = new LinkedList<Label>();
        string.add(labelIt.next());
        Vertex qi = e.getDest();
        Vertex qj = getVertex(original,blueRed.getR(), string);
        OrigStatePair newPair = new OrigStatePair(qi, qj);
        if(qj!=null){
          int equivalent = computeScore(original, newPair);
          if(equivalent<0){
View Full Code Here


       
        if(existing == null){
          pta.addVertex(newVertex);
          Vertex previous;
          previous = getVertex(pta, string.subList(0, i-1));// for i==1, getVertex will return the initial vertex
          DirectedSparseEdge e = new DirectedSparseEdge(previous, newVertex);
          Set<Label> labels = new TreeSet<Label>();
          labels.add(string.get(i-1));
          e.addUserDatum(JUConstants.LABEL, labels, UserData.CLONE);
          pta.addEdge(e);
        }
        else
          if (different(new OrigStatePair(existing,newVertex)))
          {
View Full Code Here

    if (current == null)
      return null;
   
    for(int i = 0;i<string.size();i++){
      Label label = string.get(i);
      DirectedSparseEdge edge = getEdgeWithLabel(current.getOutEdges(), label);
      if(edge == null)
        return null;
      current = edge.getDest();
    }
    return current;
  }
View Full Code Here

  }

  public static DirectedSparseEdge getEdgeWithLabel(Set<DirectedSparseEdge> edges, Label label){
    Iterator<DirectedSparseEdge> edgeIt = edges.iterator();
    while(edgeIt.hasNext()){
      DirectedSparseEdge e = edgeIt.next();
      Set<Label> labels = (Set<Label>)e.getUserDatum(JUConstants.LABEL);
      if(labels.contains(label))
        return e;
    }
    return null;
  }
View Full Code Here

 
  @SuppressWarnings("unchecked")
  protected boolean addEdgeInternal(DeterministicVertex v, DeterministicVertex random)
  {
    Set<Label> vertexAlphabet = new TreeSet<Label>();
    DirectedSparseEdge existingEdge = null;
    for (Object e : v.getOutEdges()) {
      DirectedSparseEdge edge = (DirectedSparseEdge)e;
      if (edge.getDest() == random)
        existingEdge = edge;
      Set<Label>labels = (Set<Label>)edge.getUserDatum(JUConstants.LABEL);
      assert labels!=null : "vertex "+v.getStringId()+" has outgoing edges without labels";
      vertexAlphabet.addAll(labels);
    }
    Set<Label> possibles = new TreeSet<Label>();
    possibles.addAll(alphabet);
    possibles.removeAll(vertexAlphabet);
    Label label = null;
    if(possibles.isEmpty())
      return false;// failure to add an edge since all possible letters of an alphabet have already been used
    Label possiblesArray [] = new Label[possibles.size()];possibles.toArray(possiblesArray);
    label = possiblesArray[randomInt(possiblesArray.length)];
    if (existingEdge != null)
    {// a parallel edge
      ((Set<Label>)existingEdge.getUserDatum(JUConstants.LABEL)).add(label);
    }
    else
    {// new edge needs to be added.
      try
      {
        Set<Label> labelSet = new TreeSet<Label>();
        labelSet.add(label);
        DirectedSparseEdge e = new DirectedSparseEdge(v,random);
        e.addUserDatum(JUConstants.LABEL, labelSet, UserData.SHARED);
        machine.addEdge(e);
      }
      catch(edu.uci.ics.jung.exceptions.ConstraintViolationException e1){
        Helper.throwUnchecked("poor constraints from"+v+" to "+random,e1);
      }
View Full Code Here

          DirectedSparseVertex myVertex = getVertex(mod.name);
          myVertex.setUserDatum(JUConstants.COLOUR, JUConstants.RED, UserData.SHARED);

          for (String d : mod.behaviour.getDependencies()) {
            DirectedSparseVertex v = getVertex(d);
            DirectedSparseEdge e = new DirectedSparseEdge(myVertex, v);
            e.setUserDatum(JUConstants.LABEL, new HashSet<Label>(), UserData.CLONE);
            graph.addEdge(e);
          }
          System.out.println("\tDone.");
          succount += 1;
        } catch (IOException e) {
          System.out.println("\tFailed to open " + f.getName());
          succount += 1;
        } catch (Exception e) {
          failcount += 1;
          if (e.getMessage() != null) {
            //if (!e.getMessage().contains("behaviour")) {
              //e.printStackTrace();
            //}
          }
          System.out.println("\tFailed to process " + f.getName() + " - " + e.getMessage() + " <" + e.getClass().getName() + ">");
        }

      }
    }
    System.out.println("" + succount + " processed, " + failcount + " failed");
View Full Code Here

        // It is possible that there is already an edge between g.getSource Blue and newRed
        Iterator<DirectedSparseEdge> sourceOutIt = source.getOutEdges().iterator();
        Edge fromSourceToNewRed = null;
        while(sourceOutIt.hasNext() && fromSourceToNewRed == null)
        {
          DirectedSparseEdge out = sourceOutIt.next();if (out.getDest() == newRed) fromSourceToNewRed = out;
        }
        if (fromSourceToNewRed == null)
        {
          fromSourceToNewRed = new DirectedSparseEdge(source,newRed);
          fromSourceToNewRed.setUserDatum(JUConstants.LABEL, existingLabels, UserData.CLONE);// no need to clone this one since I'll delete the edge in a bit
          g.addEdge(fromSourceToNewRed);
        }
        else
          // there is already a transition from source to newRed, hence all we have to do is merge the new labels into it.
          ((Collection<Label>)fromSourceToNewRed.getUserDatum(JUConstants.LABEL)).addAll( existingLabels );
         
      }

      // now the elements of mergedVertices are in terms of the copied graph.
      for(Vertex vert:(Set<Vertex>)g.getVertices())
        if (mergedVertices.containsKey(vert))
        {// there are some vertices to merge with this one.
          usedInputs.clear();usedInputs.addAll(s.transitionMatrix.get(vert).keySet());
          for(CmpVertex toMerge:mergedVertices.get(vert))
          {// for every input, I'll have a unique target state - this is a feature of PTA
           // For this reason, every if multiple branches of PTA get merged, there will be no loops or parallel edges.
          // As a consequence, it is safe to assume that each input/target state combination will lead to a new state.
            Set<Label> inputsFrom_toMerge = s.transitionMatrix.get(toMerge).keySet();
            for(Label input:inputsFrom_toMerge)
              if (!usedInputs.contains(input))
              {
                Set<Label> labels = new HashSet<Label>();
                                                                labels.add(input);
                DeterministicVertex targetVert = (DeterministicVertex)s.transitionMatrix.get(toMerge).get(input);
                DirectedSparseEdge newEdge = new DirectedSparseEdge(vert,targetVert);
                newEdge.addUserDatum(JUConstants.LABEL, labels, UserData.CLONE);
                g.removeEdges(targetVert.getInEdges());g.addEdge(newEdge);
              }
            usedInputs.addAll(inputsFrom_toMerge);
          }
        }
View Full Code Here

  public static Set<List<String>> computeSuffixes(Vertex v, DirectedSparseGraph model){
    Set<List<String>> returnSet = new HashSet<List<String>>();
    DijkstraShortestPath p = new DijkstraShortestPath(model);
    Iterator<DirectedSparseEdge> edgeIt = model.getEdges().iterator();
    while(edgeIt.hasNext()){
      DirectedSparseEdge e = edgeIt.next();
      List<Edge> sp = null;
      sp = p.getPath(v, e.getSource());
      if(sp!=null){
        if(!sp.isEmpty()){
          sp.add(e);
          Set<List<String>> paths = getPaths(sp);
          returnSet.addAll(paths);
        }
        else if(e.getSource().equals(v)) { //&&(e.getDest().equals(v))){ // KIRR: BUG FIXED
          sp.add(e);
          Set<List<String>> paths = getPaths(sp);
          returnSet.addAll(paths);
        }
      }
View Full Code Here

      throw new IllegalArgumentException("missing initial state");

    Iterator<DirectedSparseEdge> edgeIter = g.getEdges().iterator();
    while(edgeIter.hasNext())
    { 
      DirectedSparseEdge edge = edgeIter.next();
      Map<Label,List<CmpVertex>> outgoing = transitionMatrix.get(origToCmp.get(edge.getSource()));
      assert origToCmp.containsKey(edge.getDest());// this cannot fail if we handle normal Jung graphs which will never let me add an edge with vertex not in the graph
      // The line below aims to ensure that inputs are evaluated by computeStateScore in a specific order, which in conjunction with the visited set of computeStateScore permits emulating a bug in computeScore
      createLabelToStateMap((Set<Label>)edge.getUserDatum(JUConstants.LABEL),origToCmp.get(edge.getDest()),outgoing);
    }
   
    PairCompatibility<Vertex> compat = (PairCompatibility<Vertex>)g.getUserDatum(JUConstants.PAIR_COMPATIBILITY);
    if (compat != null)
      PairCompatibility.copyTo(compat, pairCompatibility, origToCmp);
View Full Code Here

    {
      Vertex v = vertexIt.next();
      outLabels.clear();
      Iterator<DirectedSparseEdge>outEdgeIt = v.getOutEdges().iterator();
      while(outEdgeIt.hasNext()){
        DirectedSparseEdge outEdge = outEdgeIt.next();
        outLabels.addAll( (Set<String>)outEdge.getUserDatum(JUConstants.LABEL) );
      }
      transitionsToBeAdded = !alphabet.equals(outLabels);
    }
   
    if (transitionsToBeAdded)
    {
      // third pass - adding transitions
      g.addVertex(rejectVertex);
      vertexIt = (Iterator<Vertex>)g.getVertices().iterator();
      while(vertexIt.hasNext())
      {
        Vertex v = vertexIt.next();
        if (v != rejectVertex)
        {// no transitions should start from the reject vertex
          Set<String> outgoingLabels = new TreeSet<String>();outgoingLabels.addAll(alphabet);
         
          Iterator<DirectedSparseEdge>outEdgeIt = v.getOutEdges().iterator();
          while(outEdgeIt.hasNext()){
            DirectedSparseEdge outEdge = outEdgeIt.next();
            outgoingLabels.removeAll( (Set<String>)outEdge.getUserDatum(JUConstants.LABEL) );
          }
          if (!outgoingLabels.isEmpty())
          {
            // add a transition
            DirectedSparseEdge edge = new DirectedSparseEdge(v,rejectVertex);
            edge.addUserDatum(JUConstants.LABEL, outgoingLabels, UserData.CLONE);
            g.addEdge(edge);
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of edu.uci.ics.jung.graph.impl.DirectedSparseEdge

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.