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

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


      e.removeUserDatum(JUConstants.LABEL);
      Iterator<Label> labelIt = labels.iterator();
      e.addUserDatum(EDGE, labelIt.next(), UserData.SHARED);
      while(labelIt.hasNext())
      {
        DirectedSparseEdge newEdge = new DirectedSparseEdge(e.getSource(),e.getDest());
        newEdge.setUserDatum(EDGE, labelIt.next(), UserData.SHARED);
        newEdges.add(newEdge);
      }
    }
   
    for(Edge e:newEdges)
View Full Code Here


      throw new IllegalArgumentException("missing initial state");

    Iterator<DirectedSparseEdge> edgeIter = g.getEdges().iterator();
    while(edgeIter.hasNext())
    { 
      DirectedSparseEdge edge = edgeIter.next();
      Map<String,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<String>)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

    return new LearnerGraph(machine,config).paths.reduce();
  }
 
  /** Adds an edge between the supplied vertices and returns true/false if this was successful. */
  protected boolean addEdge(DeterministicVertex v, DeterministicVertex w) {
    machine.addEdge(new DirectedSparseEdge(v,w));return true;
  }
View Full Code Here

    List<DeterministicVertex> result = new LinkedList<DeterministicVertex>();
    @SuppressWarnings("unchecked")
    Iterator<DirectedSparseEdge> inIt = ambassador.getInEdges().iterator();
    Set<DeterministicVertex> verticesToChooseFrom = new TreeSet<DeterministicVertex>();
    while(inIt.hasNext()){
      DirectedSparseEdge e = inIt.next();
      DeterministicVertex v = (DeterministicVertex) e.getSource();
      if(!visited.contains(v))
        verticesToChooseFrom.add(v);
    }
    if (!verticesToChooseFrom.isEmpty()) result.addAll(selectVertices(verticesToChooseFrom, x));
   
    @SuppressWarnings("unchecked")
    Iterator<DirectedSparseEdge> outIt = ambassador.getOutEdges().iterator();
    verticesToChooseFrom.clear();
    while(outIt.hasNext()){
      DirectedSparseEdge e = outIt.next();
      DeterministicVertex v = (DeterministicVertex) e.getDest();
      if(!visited.contains(v))
        verticesToChooseFrom.add(v);
    }
   
    if (!verticesToChooseFrom.isEmpty()) result.addAll(selectVertices(verticesToChooseFrom, y));
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

    return new LearnerGraph(machine,config).paths.reduce();
  }
 
  /** Adds an edge between the supplied vertices and returns true/false if this was successful. */
  protected boolean addEdge(DeterministicVertex v, DeterministicVertex w) {
    machine.addEdge(new DirectedSparseEdge(v,w));return true;
  }
View Full Code Here

    // This one needs to choose vertices at random, not just choose first x/y vertices.
    List<DeterministicVertex> result = new LinkedList<DeterministicVertex>();
    Iterator<DirectedSparseEdge> inIt = ambassador.getInEdges().iterator();
    Set<DeterministicVertex> verticesToChooseFrom = new TreeSet<DeterministicVertex>();
    while(inIt.hasNext()){
      DirectedSparseEdge e = inIt.next();
      DeterministicVertex v = (DeterministicVertex) e.getSource();
      if(!visited.contains(v))
        verticesToChooseFrom.add(v);
    }
    if (!verticesToChooseFrom.isEmpty()) result.addAll(selectVertices(verticesToChooseFrom, x));
   
    Iterator<DirectedSparseEdge> outIt = ambassador.getOutEdges().iterator();
    verticesToChooseFrom.clear();
    while(outIt.hasNext()){
      DirectedSparseEdge e = outIt.next();
      DeterministicVertex v = (DeterministicVertex) e.getDest();
      if(!visited.contains(v))
        verticesToChooseFrom.add(v);
    }
   
    if (!verticesToChooseFrom.isEmpty()) result.addAll(selectVertices(verticesToChooseFrom, y));
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

        // 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

      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

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.