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

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


  }
 
  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.getID().toString()+" 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


      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

      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

    return new LearnerGraph(machine,conf).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

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

    Set<Vertex> blues = new HashSet<Vertex>();
    for(Vertex v: DeterministicDirectedSparseGraph.findVertices(JUConstants.COLOUR, JUConstants.RED, model))
    {
      Iterator<DirectedSparseEdge>neighbourIt = v.getOutEdges().iterator();
      while(neighbourIt.hasNext()){
        DirectedSparseEdge next = neighbourIt.next();
        Vertex neighbour = next.getDest();
        JUConstants neighbourColour = (JUConstants)neighbour.getUserDatum(JUConstants.COLOUR);
        if(neighbourColour!=null){
          if(neighbourColour == JUConstants.RED)
            continue;
        }
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

    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);
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

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.