Examples of DirectedSparseEdge


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

        // 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<String>)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<String> inputsFrom_toMerge = s.transitionMatrix.get(toMerge).keySet();
            for(String input:inputsFrom_toMerge)
              if (!usedInputs.contains(input))
              {
                Set<String> labels = new HashSet<String>();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

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

 
  public static Edge findEdge(Vertex from, Vertex to){
    @SuppressWarnings("unchecked")
    Iterator<DirectedSparseEdge> edgesOut = from.getOutEdges().iterator();
    while(edgesOut.hasNext()){
      DirectedSparseEdge current = edgesOut.next();
      if(current.getDest().equals(to))
        return current;
    }
    return null;
  }
View Full Code Here

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

    Map<VertexID,DeterministicVertex> newVertices = new TreeMap<VertexID,DeterministicVertex>();
    for(DirectedSparseEdge e:(Set<DirectedSparseEdge>)g.getEdges())
    {
      DeterministicVertex newSrc = DeterministicDirectedSparseGraph.copyVertex(newVertices,result,e.getSource()),
        newDst = DeterministicDirectedSparseGraph.copyVertex(newVertices, result, e.getDest());
      DirectedSparseEdge newEdge = new DirectedSparseEdge(newSrc,newDst);
      newEdge.addUserDatum(JUConstants.LABEL, ((HashSet<String>)e.getUserDatum(JUConstants.LABEL)).clone(), UserData.SHARED);
      result.addEdge(newEdge);
    }
    return result;
  }
View Full Code Here

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

    init.addUserDatum("colour", "red", UserData.SHARED);
 
    Iterator<DirectedSparseEdge> edgeIter = g.getEdges().iterator();
    while(edgeIter.hasNext())
    { 
      DirectedSparseEdge e = edgeIter.next();
      Map<String,CmpVertex> outgoing = transitionMatrix.get(e.getSource());
      // 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
      for(String label:(HashSet<String>)e.getUserDatum(JUConstants.LABEL))
        outgoing.put(label, (CmpVertex)e.getDest());     
    }
  }
View Full Code Here

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

    Map<String,CmpVertex> newVertices = new TreeMap<String,CmpVertex>();
    for(DirectedSparseEdge e:(Set<DirectedSparseEdge>)g.getEdges())
    {
      CmpVertex newSrc = copyVertex(newVertices,result,e.getSource()),
        newDst = copyVertex(newVertices, result, e.getDest());
      DirectedSparseEdge newEdge = new DirectedSparseEdge(newSrc,newDst);
      newEdge.addUserDatum(JUConstants.LABEL, ((HashSet)e.getUserDatum(JUConstants.LABEL)).clone(), UserData.SHARED);
      result.addEdge(newEdge);
    }
    return result;
  }
View Full Code Here

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

        // 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<String>)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(Vertex 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<String> inputsFrom_toMerge = s.transitionMatrix.get(toMerge).keySet();
            for(String input:inputsFrom_toMerge)
              if (!usedInputs.contains(input))
              {
                Set<String> labels = new HashSet<String>();labels.add(input);
                Vertex targetVert = 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

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

            Vertex src = oldVertexToNewVertex.get(entry.getKey()), dst = oldVertexToNewVertex.get(sv.getValue());
            if (src == null)
              throw new IllegalArgumentException("Source vertex "+entry.getKey()+" is not in the transition table");
            if (dst == null)
              throw new IllegalArgumentException("Target vertex "+sv.getValue()+" is not in the transition table, referred to from vertex "+entry.getKey());
            DirectedSparseEdge e = new DirectedSparseEdge(src,dst);
            labels = new HashSet<String>();labels.add(sv.getKey());
            targetStateToEdgeLabels.put(sv.getValue(), labels);
            e.addUserDatum(JUConstants.LABEL, labels, UserData.CLONE);
            result.addEdge(e);     
          }
        }
      }
    }
View Full Code Here

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

  public static Set<List<Label>> computeSuffixes(Vertex v, DirectedSparseGraph model){
    Set<List<Label>> returnSet = new HashSet<List<Label>>();
    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<Label>> paths = getPaths(sp);
          returnSet.addAll(paths);
        }
        else if(e.getSource().equals(v)) { //&&(e.getDest().equals(v))){ // KIRR: BUG FIXED
          sp.add(e);
          Set<List<Label>> paths = getPaths(sp);
          returnSet.addAll(paths);
        }
      }
View Full Code Here

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

          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

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

 
  @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
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.